string title = "HWID KMS38 CN 0.62.01 (c) Microsoft Inc. [ Enterprise 19041.2728 | x64 ]";void FindJHWin(){ bool OK; label2.Text = "等待激活软件运行..."; OK = false; while (!OK) { //主窗口标题 为 win10jh.exe IntPtr startwin = FindWindow(null, "win10jh.exe"); if (startwin != IntPtr.Zero) { label2.Text += "已运行
\r\n"; OK = true; } } label2.Text += "准备进入设置界面..."; OK = false; IntPtr maindHwnd = IntPtr.Zero; while (!OK) { //根据 title 得到要操作的窗口句柄 maindHwnd = FindWindow(null, title); if (maindHwnd != IntPtr.Zero) { label2.Text += "已经进入!\r\n"; OK = true; } }}
此时运行效果如下:下面我要做的事是3步我把得到窗体标题的代码弄到另一个地方去了,因为后面用不到了1、将下拉列表项调到“数字激活位置”void FindJHWin(){ bool OK; label2.Text = "等待激活软件运行..."; OK = false; while (!OK) { //主窗口标题 为 win10jh.exe IntPtr startwin = FindWindow(null, "win10jh.exe"); if (startwin != IntPtr.Zero) { label2.Text += "已运行
\r\n"; OK = true; } } label2.Text += "准备进入设置界面..."; OK = false; IntPtr maindHwnd = IntPtr.Zero; while (!OK) { //根据 title 得到要操作的窗口句柄 maindHwnd = FindWindow(null, title); if (maindHwnd != IntPtr.Zero) { label2.Text += "已经进入!\r\n"; OK = true; } } GOJH(maindHwnd); //确保打开了设置窗体后,去查找下拉列表并设置}[DllImport("user32.dll", EntryPoint = "FindWindowEx")]private extern static IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);[DllImport("User32.dll", EntryPoint = "SendMessage")]private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);void GOJH(IntPtr p){ //子窗口 IntPtr childHwnd1 = FindWindowEx(p, IntPtr.Zero, "#32770", null); //下拉列表 IntPtr combo = FindWindowEx(childHwnd1, IntPtr.Zero, "ComboBox", null); //操作下拉列表 ,为了确保执行成功,这里我搞了三次 SendMessage(combo, 0x014D, (IntPtr)0, "数字激活"); SendMessage(combo, 0x014D, (IntPtr)0, "数字激活"); SendMessage(combo, 0x014D, (IntPtr)0, "数字激活");}
上面代码的说明:只能说我还是太年轻了,这个窗体里面应该还是套了一个窗体,然后里面是有一些控件的,搞了半天,我实在是烦了,还是用了spy++[捂脸][捂脸][捂脸]//子窗口IntPtr childHwnd1 = FindWindowEx(p, IntPtr.Zero, "#32770", null);运行结果:不过还是有点不甘心,下次还是研究一下怎么遍历所有子窗体剩下的事,还需要点击,开始按钮,然后等激活结束,再退出,今天算了,找子窗口搞了半天,明天再说吧(图片来源网络,侵删)
0 评论