国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

c#使用spy進行模擬操作

2019-11-17 02:52:51
字體:
來源:轉載
供稿:網友

c#使用spy進行模擬操作

2014-09-19 01:16 by 遲來的春天, ... 閱讀, ... 評論, 收藏, 編輯

很無奈,寫了很長時間,最后保存時網頁失去響應,真是要命呢。本來想就此放棄了,但是想還是粗略的重寫一次吧,希望日后可以對朋友有一定的幫助。

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);


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东明县| 牟定县| 彭水| 莱芜市| 灵武市| 溧水县| 青浦区| 南京市| 赤峰市| 都匀市| 延庆县| 二连浩特市| 洛隆县| 合阳县| 且末县| 绥德县| 广汉市| 天全县| 科技| 嘉峪关市| 青海省| 嘉荫县| 泽普县| 甘孜县| 阳城县| 桂东县| 虎林市| 仲巴县| 喀喇| 哈尔滨市| 福泉市| 巨野县| 瓦房店市| 湛江市| 自治县| 珲春市| 灵武市| 五常市| 武义县| 苍梧县| 册亨县|