有段时间没写C++的windows代码了,要用到极简的自动按键程序,就随便写了个用用,代码开源。C++结合QT和boost。
一、枚举线程:
HWND hCurWnd = GetTopWindow(0);
while (hCurWnd != NULL)
{
DWORD cur_pid;
DWORD dwTheardId = GetWindowThreadProcessId(hCurWnd, &cur_pid);
if (IsWindowVisible(hCurWnd) != 0)
{
TCHAR szClassName[256];
GetWindowText(hCurWnd, szClassName, 256);
if (QString::fromStdWString(szClassName).length() > 1)
cbx_programs_->addItem(QString::fromStdWString(szClassName), QVariant((long)cur_pid));
}
hCurWnd = GetNextWindow(hCurWnd, GW_HWNDNEXT);
}
二、发送消息
::PostMessage(_hcur_wnd, WM_KEYDOWN, _cur_virtual_key, 0x01510001);
::PostMessage(_hcur_wnd, WM_KEYUP, _cur_virtual_key, 0xC1510001);
4805

被折叠的 条评论
为什么被折叠?



