查找指定窗口ios
#include <iostream> #include <windows.h> using namespace std; int main() { TCHAR szTitle[MAX_PATH] = { 0 }; HWND hWnd = ::FindWindow(L"#32770", L"x32Inject"); if (hWnd != NULL) { // 修改窗口標題 ::SetWindowText(hWnd, L"Hello World!"); } else { ::MessageBox(0, L"窗口沒找到", L"提示", 0); } return 0; }
窗口控制windows
#include <windows.h> int main() { TCHAR szTitle[MAX_PATH] = { 0 }; HWND hWnd = ::FindWindow(L"#32770", L"x32Inject"); if (hWnd != NULL) { // 切換窗口 SwitchToThisWindow(hWnd, false); Sleep(5000); // 關閉窗口 ::SendMessage(hWnd, WM_CLOSE, 0, 0); } else { ::MessageBox(0, L"窗口沒找到", L"提示", 0); } return 0; }
查找子窗口spa
#include <windows.h> int main() { TCHAR szTitle[MAX_PATH] = { 0 }; HWND hWnd = ::FindWindow(L"#32770", L"x32Inject"); if (hWnd != NULL) { // 查找子窗口 HWND hEdit = ::FindWindowEx(hWnd, NULL, L"Edit", L""); // 設置標題 ::SetWindowText(hEdit, L"test"); // 修改內容(本案例,內容和標題是同樣的) ::SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)L"Hello World!"); } else { ::MessageBox(0, L"窗口沒找到", L"提示", 0); } return 0; }
#include <windows.h> int main() { TCHAR szTitle[MAX_PATH] = { 0 }; HWND hWnd = ::FindWindow(L"#32770", L"x32Inject"); if (hWnd != NULL) { // 查找子窗口 HWND hEdit = ::GetDlgItem(hWnd, 0x3EA); // 獲取內容 ::SendMessage(hWnd, WM_GETTEXT, MAX_PATH, (LPARAM)szTitle); // 修改內容 ::SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)L"Hello World!"); } else { ::MessageBox(0, L"窗口沒找到", L"提示", 0); } return 0; }
枚舉子窗口code
#include <windows.h> #include <stdio.h> BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) { TCHAR szTitle[MAX_PATH] = { 0 }; ::GetWindowText(hwnd, szTitle, MAX_PATH); ;; MessageBox(0, szTitle, L"子窗口", MB_OK); return TRUE; } int main() { TCHAR szTitle[MAX_PATH] = { 0 }; HWND hWnd = ::FindWindow(L"#32770", L"x32Inject"); if (hWnd != NULL) { ::EnumChildWindows(hWnd, EnumChildProc, NULL); } else { ::MessageBox(0, L"窗口沒找到", L"提示", 0); } getchar(); return 0; }
枚舉全部打開的窗口blog
#include <windows.h> #include <stdio.h> BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { TCHAR szTitle[MAX_PATH] = { 0 }; ::GetWindowText(hwnd, szTitle, MAX_PATH); wprintf(L"%s\n", szTitle); if (wcscmp(szTitle, L"x32Inject") == 0) { ::MessageBox(0, szTitle, L"窗口", 0); } return TRUE; } int main() { ::EnumWindows(EnumWindowsProc, NULL); getchar(); return 0; }
模擬鼠標點擊get
#include <windows.h> #include <stdio.h> // 隱藏控制檯運行 #pragma comment(linker,"/subsystem:\"windows\" /entry:\"mainCRTStartup\"") int main() { TCHAR szTitle[MAX_PATH] = { 0 }; RECT r; HWND hWnd = ::FindWindow(L"#32770", L"x32Inject"); if (hWnd != NULL) { HWND hButton = ::FindWindowEx(hWnd, NULL, L"Button", L"選擇程序"); // 獲取選擇程序窗口座標 ::GetWindowRect(hButton, &r); // 設置鼠標位置 ::SetCursorPos(r.left + 10, r.top + 10); Sleep(3000); // 鼠標左鍵單擊 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); // 按下左鍵 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); // 鬆開左鍵 } else { ::MessageBox(0, L"沒有找到窗口!", L"提示", MB_OK); } getchar(); return 0; }
模擬鍵盤點擊(搜索:鍵盤鍵與虛擬鍵碼對照表)it
#include <windows.h> #include <stdio.h> // 隱藏控制檯運行 #pragma comment(linker,"/subsystem:\"windows\" /entry:\"mainCRTStartup\"") int main() { TCHAR szTitle[MAX_PATH] = { 0 }; RECT r; HWND hWnd = ::FindWindow(L"#32770", L"SemaphoreEx"); if (hWnd != NULL) { HWND hEdit = ::GetDlgItem(hWnd, 0x3E8); // 獲取選擇程序窗口座標 ::GetWindowRect(hEdit, &r); // 設置鼠標位置 ::SetCursorPos(r.left + 1, r.top + 1); Sleep(1000); // 鼠標左鍵單擊 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); // 按下左鍵 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); // 鬆開左鍵 // 模擬鍵盤 keybd_event(97, 0, 0, 0); keybd_event(97, 0, KEYEVENTF_KEYUP, 0); Sleep(1000); keybd_event(66, 0, 0, 0); keybd_event(66, 0, KEYEVENTF_KEYUP, 0); Sleep(1000); keybd_event(16, 0, 0, 0); keybd_event(67, 0, 0, 0); keybd_event(67, 0, KEYEVENTF_KEYUP, 0); keybd_event(16, 0, KEYEVENTF_KEYUP, 0); } else { ::MessageBox(0, L"沒有找到窗口!", L"提示", MB_OK); } getchar(); return 0; }