3
VB.netで外部アプリケーションのウィンドウをプログラムで閉じるにはどうしたらいいですか? プロセス全体を閉じずに現在のウィンドウを閉じたいだけです。VB.netでプログラムでウィンドウを閉じるには?
VB.netで外部アプリケーションのウィンドウをプログラムで閉じるにはどうしたらいいですか? プロセス全体を閉じずに現在のウィンドウを閉じたいだけです。VB.netでプログラムでウィンドウを閉じるには?
使用FindWindow
とSendMessage
のAPIここではC#で
、変換するのは簡単でなければなりません:
using Microsoft.Win32;
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName,string lpWindowName);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
private void closeWindow()
{
// retrieve the handler of the window
int iHandle = FindWindow("Notepad", "Untitled - Notepad");
if (iHandle > 0)
{
// close the window using API
SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
}
}
あなたが外部アプリケーションのウィンドウとはどういう意味ですか? – krammer
@krammer私は自分のアプリケーションを通して別のアプリケーションのウィンドウを閉じようとしています。私はフォームの名前を知らない。私はただそれを閉じたい。 – Harsh