#include<windows.h>
#include<tchar.h>
#include<iostream>
using namespace std;
HWND _FindWindow(LPCTSTR lpClassName,
LPCTSTR lpWindowName);
HWND _FindWindowEx(HWND hwndParent,
HWND hwndChildAfter,
LPCTSTR lpszClass,
LPCTSTR lpszWindow);
void main()
{
const int WM_CLICK= 0x00F5;
// ShellExecute(NULL,"open","calc.exe",NULL,NULL,SW_SHOW);
HWND hWnd=_FindWindow("#32770","Windows 组件向导");
HWND ChWnd=_FindWindowEx(hWnd,NULL,"#32770","");
HWND hList=_FindWindowEx(ChWnd,NULL,"ListBox","");
//::PostMessage(hList,WM_CLICK,0,0);
//::PostMessage(hList, WM_KEYDOWN, 0x20, NULL);
::PostMessage(hList, WM_KEYDOWN, 40, NULL);
//上下左右键分别对应的十进制为38、40、37、39
}
HWND _FindWindow(LPCTSTR lpClassName,
LPCTSTR lpWindowName)
{
HWND hWnd=NULL;
while(1)
{
hWnd=::FindWindow(lpClassName,lpWindowName);
if(hWnd)
break;
}
return hWnd;
}
HWND _FindWindowEx(HWND hwndParent,
HWND hwndChildAfter,
LPCTSTR lpszClass,
LPCTSTR lpszWindow)
{
HWND hBtn=NULL;
while(1)
{
hBtn=::FindWindowEx(hwndParent,hwndChildAfter,lpszClass,lpszWindow);
if(hBtn)
break;
}
return hBtn;
}
vc 向外部窗体发送空格键、和方向键
最新推荐文章于 2021-07-30 14:40:06 发布