標籤:style blog http color io os 使用 ar 2014
很無奈,寫了很長時間,最後儲存時網頁失去響應,真是要命呢。本來想就此放棄了,但是想還是粗略的重寫一次吧,希望日後可以對朋友有一定的協助。
Microsoft.Spy工具是一個基礎工具,我們簡要介紹一下使用方法:
spy在vs有內建的,也可以在網下直接下載。
開啟spy工具,主介面如下:
今天我們使用vnc作為一個樣本
目標是在server內寫入192.168.2.200,並點擊Options第二個按鈕
第一步,如何擷取vnc表單,使用spy進行表單尋找
拖動尋找工具表徵圖到需要的介面上。
這樣我們就可以找到需要的表單。
FindWindow 可以尋找第一個主表單,使和類名或標題。
FindWindowEx可以尋找表單下的控制項。
SendMessage向表單發送訊息。
使和視窗搜尋尋找控制項。
1 [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)] 2 //參數1:指的是類名。參數2,指的是視窗的標題名。兩者至少要知道1個 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 //擷取第一個按鈕13 IntPtr button1 = FindWindowEx(win, new IntPtr(), "Button", "&Options...");14 15 if(button1 != IntPtr.Zero)16 SendMessage(button1, 0xF5, 0, 0); //點擊事件17 18 if (winEdit != IntPtr.Zero)19 {20 MessageBox.Show("找到編輯框");21 }22 //MessageBox.Show("找到下拉框");23 }24 else25 {26 //MessageBox.Show("沒有找到下拉框");27 }28 29 30 MessageBox.Show("已經找到表單");31 }32 else33 {34 MessageBox.Show("沒有找到表單");35 }36 }
執行結果如下:
如果多個按鈕,又沒有標題,則只能一個一個的擷取,如下
如果哪位朋友還有其它方法,還請多多指教。
1 IntPtr button1 = FindWindowEx(win, new IntPtr(), "Button", null);2 IntPtr button2 = FindWindowEx(win, button1, "Button", null);
c#使用spy進行類比操作