From 14db1514fec89db599766d4996b4bb1fead0eff0 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 25 八月 2022 17:49:54 +0800 Subject: [PATCH] '完善' --- ConsoleApplication/Win32Util.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 97 insertions(+), 0 deletions(-) diff --git a/ConsoleApplication/Win32Util.cpp b/ConsoleApplication/Win32Util.cpp index 13c0a12..a4d9ead 100644 --- a/ConsoleApplication/Win32Util.cpp +++ b/ConsoleApplication/Win32Util.cpp @@ -101,6 +101,19 @@ SetFocus(hwnd); } +void Win32Util::copy(string text) +{ + HWND hWnd = NULL; + OpenClipboard(hWnd);//打开剪切板 + EmptyClipboard();//清空剪切板 + HANDLE hHandle = GlobalAlloc(GMEM_FIXED, 1000);//分配内存 + char* pData = (char*)GlobalLock(hHandle);//锁定内存,返回申请内存的首地址 + strcpy(pData, text.c_str()); + SetClipboardData(CF_TEXT, hHandle);//设置剪切板数据 + GlobalUnlock(hHandle);//解除锁定 + CloseClipboard();//关闭剪切板 +} + //键盘输入数字 void Win32Util::keyboardNum(string num, int delay) { thread runner(kbNumRunner, num, delay); @@ -111,6 +124,15 @@ void Win32Util::keyboard(int code, int delay) { thread runner(kbKeyRunner, code, delay); runner.join(); +} + +void Win32Util::keyboardPaste() +{ + keybd_event(VK_CONTROL, 0, 0, 0); // 按下CTRL键 + keybd_event('V', 0, 0, 0); // 按下a键 + Sleep(50); + keybd_event('V', 0, KEYEVENTF_KEYUP, 0);// 松开a键 + keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);// 松开CTRL键 } DEVMODE Win32Util::getL2ScreenInfo() @@ -149,5 +171,80 @@ ShowWindow(hwnd, SW_SHOWNORMAL); } +void Win32Util::selectTexFileWin10(HWND hwnd, string path) +{ + //选择路径 + HWND pathWin = FindWindowExA(hwnd, NULL, "WorkerW", NULL); + pathWin = FindWindowExA(pathWin, NULL, "ReBarWindow32", NULL); + pathWin = FindWindowExA(pathWin, NULL, "Address Band Root", NULL); + pathWin = FindWindowExA(pathWin, NULL, "msctls_progress32", NULL); + pathWin = FindWindowExA(pathWin, NULL, "Breadcrumb Parent", NULL); + pathWin = FindWindowExA(pathWin, NULL, "ToolbarWindow32", NULL); + RECT p; + GetWindowRect(pathWin, &p); + Win32Util::focus(hwnd); + Win32Util::click(p.right - 5, p.top + 5, 10); + Sleep(1000); + + //复制路径 + Win32Util::copy(path); + //粘贴路径 + keyboardPaste(); + + //按enter按键 + keybd_event(VK_RETURN, 0, 0, 0); + keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0); + + + + + //选着导入Txt + HWND typeWin = FindWindowExA(hwnd, NULL, "ComboBox", NULL); + GetWindowRect(typeWin, &p); + Win32Util::focus(typeWin); + Win32Util::click(p.right - 5, p.top + 5, 10); + Win32Util::click(p.right - 5, p.bottom + 30, 100); + Sleep(500); + + + + //选中文件 + HWND contentWin = FindWindowExA(hwnd, NULL, "DUIViewWndClassName", NULL); + contentWin = FindWindowExA(contentWin, NULL, "DirectUIHWND", NULL); + HWND contentWin_ = FindWindowExA(contentWin, NULL, "CtrlNotifySink", NULL); + + for (int i = 0;i < 5;i++) + { + if (FindWindowExA(contentWin_, NULL, "SHELLDLL_DefView", NULL) > 0) + break; + contentWin_ = FindWindowExA(contentWin, contentWin_, "CtrlNotifySink", NULL); + } + GetWindowRect(contentWin_, &p); + + + Win32Util::click(p.left + 20, p.top + 10, 10); + Win32Util::click(p.left + 20, p.top + 10, 10); + Win32Util::click(p.left + 20, p.top + 10, 10); + + //Sleep(100); + + //点击打开 + //HWND openWin = FindWindowExA(hwnd, NULL, NULL, "打开(&O)"); + //GetWindowRect(openWin, &p); + //return; + //Win32Util::click((p.left + p.right) / 2, (p.top + p.bottom) / 2, 100); +} + +void Win32Util::rollMouseWheel(bool back, HWND win,int x, int y) +{ + //back-是否往后滚 + SendMessage(win, WM_MOUSEWHEEL, back?0xFF880000:0x00780000, MAKEWORD(x, y)); +} + +void Win32Util::getWindowRect(HWND hwnd, RECT *rect) +{ + GetWindowRect(hwnd, rect); +} + -- Gitblit v1.8.0