有时我们可能会在某个程序中用到模拟按钮点击事件。
本文中的例子在MFC程序中调试通过,duilib的没试过,还需探索
不多说,上代码:
1 #include "stdafx.h" 2 #include "windows.h" 3 #include "Psapi.h" 4 #include "atlstr.h" 5 #include <string.h> 6 #include<iostream> 7 using namespace std; 8 9 #pragma comment(lib,"Psapi"); 10 #define ID_EXEC_CURFILE 32807 11 #define ID_RCL_HELP 32804 12 CString str; 13 14 //根据exe名字一部分查找进程id,返回 15 DWORD FindProcess(char *strProcessName) 16 { 17 DWORD aProcesses[1024], cbNeeded, cbMNeeded; 18 HMODULE hMods[1024]; 19 HANDLE hProcess; 20 char szProcessName[MAX_PATH]; 21 if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return 0; 22 for(int i=0; i< (int) (cbNeeded / sizeof(DWORD)); i++) 23 { 24 hProcess = OpenProcess( /*PROCESS_QUERY_INFORMATION | PROCESS_VM_READ*/PROCESS_ALL_ACCESS, FALSE, aProcesses[i]); 25 if (hProcess == NULL) 26 continue; 27 EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbMNeeded); 28 GetModuleFileNameEx( hProcess, hMods[0], szProcessName,sizeof(szProcessName)); 29 30