#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-05-17 21:40:49 发布
本文展示了如何使用C++编程向Windows组件向导窗口中的ListBox发送键盘事件,具体包括发送空格键和方向键(40对应向下键)。通过FindWindow和FindWindowEx函数定位目标窗口及控件,然后利用PostMessage发送WM_KEYDOWN消息模拟按键行为。
开发板推荐:天空星STM32F407VET6开发板
超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印
开发板推荐:天空星STM32F407VET6开发板
超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

1392

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



