利用findwindow先取得視窗hanle 然後在用sendmessage傳送關閉的指令
特定視窗的handle可透過spy++查看
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern int FindWindow(string strclassName, string strWindowName);
[DllImport("user32.dll")]
private static extern int SendMessage(
int hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);
const int WM_KEYDOWN = 0x0100;
const int WM_KEYUP = 0x0101;
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
private void button1_Click(object sender, EventArgs e)
{
//int a= FindWindow("#32770", "LT_TEST_V1.3.exe");
int a = FindWindow("Notepad", "未命名 - 記事本");
listBox1.Items.Add(a);
if (a > 0)
{
SendMessage(a, WM_SYSCOMMAND, SC_CLOSE, 0);
}
}
沒有留言:
張貼留言
您的留言會先經過審核後才會公開至版面上
若本站所分享的資訊對您有幫助或有幫您省到錢的話
麻煩在留完言之後順手幫個忙
瀏覽一些您有興趣的廣告連結當作回饋贊助
您的小小鼓勵是支持本站繼續分享的最大動力
謝謝各位善心人士!! :)