全局变量 HWND gFocus; //放至当前窗口句柄
在对话框类中重载PreTranslateMessage
加入以下语句得到当前HWND
HWND Runwnd = ::GetForegroundWindow();
if(IsWindow(Runwnd))
{
if(Runwnd != this->m_hWnd)
{
if(gFocus != Runwnd)
{
if(IsWindow(gFocus))
{
AttachThreadInput(
GetWindowThreadProcessId(m_hWnd,NULL),
GetWindowThreadProcessId(gFocus,NULL),
FALSE);
}
gFocus = Runwnd;
AttachThreadInput(
GetWindowThreadProcessId(m_hWnd,NULL),
GetWindowThreadProcessId(gFocus,NULL),
TRUE);
}
}
}
然后在你的响应函数里你这样发就成了
::SetForegroundWindow(gFocus);
::keybd_event(0x56,::MapVirtualKey(0x56,0),0,0); //这个键是c来着,呵呵
在对话框类中重载PreTranslateMessage
加入以下语句得到当前HWND
HWND Runwnd = ::GetForegroundWindow();
if(IsWindow(Runwnd))
{
if(Runwnd != this->m_hWnd)
{
if(gFocus != Runwnd)
{
if(IsWindow(gFocus))
{
AttachThreadInput(
GetWindowThreadProcessId(m_hWnd,NULL),
GetWindowThreadProcessId(gFocus,NULL),
FALSE);
}
gFocus = Runwnd;
AttachThreadInput(
GetWindowThreadProcessId(m_hWnd,NULL),
GetWindowThreadProcessId(gFocus,NULL),
TRUE);
}
}
}
然后在你的响应函数里你这样发就成了
::SetForegroundWindow(gFocus);
::keybd_event(0x56,::MapVirtualKey(0x56,0),0,0); //这个键是c来着,呵呵