很無(wú)奈,寫了很長(zhǎng)時(shí)間,最后保存時(shí)網(wǎng)頁(yè)失去響應(yīng),真是要命呢。本來(lái)想就此放棄了,但是想還是粗略的重寫一次吧,希望日后可以對(duì)朋友有一定的幫助。
Microsoft.Spy工具是一個(gè)基礎(chǔ)工具,我們簡(jiǎn)要介紹一下使用方法:
spy在vs有自帶的,也可以在網(wǎng)下直接下載。
打開spy工具,主界面如下:
今天我們使用vnc作為一個(gè)示例
目標(biāo)是在server內(nèi)寫入192.168.2.200,并點(diǎn)擊Options第二個(gè)按鈕
第一步,如何獲取vnc窗體,使用spy進(jìn)行窗體查找
拖動(dòng)查找工具圖標(biāo)到需要的界面上。
這樣我們就可以找到需要的窗體。
FindWindow 可以查找第一個(gè)主窗體,使和類名或標(biāo)題。
FindWindowEx可以查找窗體下的控件。
SendMessage向窗體發(fā)送消息。
使和窗口搜索查找控件。
1 [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)] 2 //參數(shù)1:指的是類名。參數(shù)2,指的是窗口的標(biāo)題名。兩者至少要知道1個(gè) 3 public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 4 5 6 [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] 7 public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle); 8 9 [DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]10 public static extern IntPtr SendMessage(IntPtr hwnd, uint wMsg, int wParam, string lParam);11 12 [DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]13 public static extern IntPtr SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);
1 IntPtr win =FindWindow(null, "VNC Viewer : Connection Details"); 2 if (win != IntPtr.Zero) 3 { 4 IntPtr winComboBox = FindWindowEx(win, new IntPtr(), "ComboBox", null); 5 if (winComboBox != IntPtr.Zero) 6 { 7 IntPtr winEdit = FindWindowEx(winComboBox, new IntPtr(), "Edit", null); 8 9 IntPtr resultEdit = SendMessage(winEdit, 0xC, 0, "192.168.2.100");10 11 12 //獲取第一個(gè)按鈕13 IntPtr button1 = FindWindowEx(win, new IntPtr(), "Button", "&Options...");14 15 if(button1 != IntPtr.Zero)16 SendMessage(button1, 0xF5, 0, 0); //點(diǎn)擊事件17 18 if (winEdit != IntPtr.Zero)19 {20 MessageBox.Show("找到編輯框");21 }22 //MessageBox.Show("找到下拉框");23 }24 else25 {26 //MessageBox.Show("沒(méi)有找到下拉框");27 }28 29 30 MessageBox.Show("已經(jīng)找到窗體");31 }32 else33 {34 MessageBox.Show("沒(méi)有找到窗體");35 }36 }
執(zhí)行結(jié)果如下:
如果多個(gè)按鈕,又沒(méi)有標(biāo)題,則只能一個(gè)一個(gè)的獲取,如下
如果哪位朋友還有其它方法,還請(qǐng)多多指教。
1 IntPtr button1 = FindWindowEx(win, new IntPtr(), "Button", null);2 IntPtr button2 = FindWindowEx(win, button1, "Button", null);
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注