Can't Activate Window C++ [modified]
-
Hi Guys I have a business full screen appliection (A.exe) run in Windows 98. I need a hotkey when the appliection is running,Press SPACE key ,Excute a Dialog based program "C.EXE". I try to use "RegisterHotKey" function ,But the hot key does not work. Now I try to use Keyboard hook, I create a Dialog based program "B.exe" and "B.dll",When "B.exe" excuted,It launched hook callback function in "B.dll". Excute Sequence :B.exe A.exe when A.exe is running ,I press SPACE key,the hook function catch the keyboard message, it call C.exe (use the "ShellExcute"),The window of C.exe appear. Qustion: The window of "C.exe" isn't current active window.the window of "A.exe" is active windows yet! I need the window of C.exe is active when it appeared.
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
BOOL fEatKeystroke = FALSE;
PKBDLLHOOKSTRUCT p = NULL;
if (nCode == HC_ACTION)
{
p = (PKBDLLHOOKSTRUCT) lParam;
switch (wParam)
{
case WM_KEYDOWN:
if (p->vkCode == VK_SPACE)
{
return 1;
}
break;
case WM_KEYUP:if (p->vkCode == VK\_SPACE) { ShellExecute(NULL,"open","C:\\\\C.exe",NULL,NULL,SW\_SHOW); HWND h=FindWindow(NULL,"Caption of C"); if(h) { ShowWindow(h,SW\_SHOW); } return 1; } break; default: break; } } return (CallNextHookEx(glhHook,nCode,wParam,lParam));
}
void _stdcall StartKeyMask()
{
glhHook = SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,glhInstance,0);
}void _stdcall StopKeyMask()
{
if (glhHook!=NULL)
UnhookWindowsHookEx(glhHook);
}modified on Sunday, February 22, 2009 10:53 AM
-
Hi Guys I have a business full screen appliection (A.exe) run in Windows 98. I need a hotkey when the appliection is running,Press SPACE key ,Excute a Dialog based program "C.EXE". I try to use "RegisterHotKey" function ,But the hot key does not work. Now I try to use Keyboard hook, I create a Dialog based program "B.exe" and "B.dll",When "B.exe" excuted,It launched hook callback function in "B.dll". Excute Sequence :B.exe A.exe when A.exe is running ,I press SPACE key,the hook function catch the keyboard message, it call C.exe (use the "ShellExcute"),The window of C.exe appear. Qustion: The window of "C.exe" isn't current active window.the window of "A.exe" is active windows yet! I need the window of C.exe is active when it appeared.
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
BOOL fEatKeystroke = FALSE;
PKBDLLHOOKSTRUCT p = NULL;
if (nCode == HC_ACTION)
{
p = (PKBDLLHOOKSTRUCT) lParam;
switch (wParam)
{
case WM_KEYDOWN:
if (p->vkCode == VK_SPACE)
{
return 1;
}
break;
case WM_KEYUP:if (p->vkCode == VK\_SPACE) { ShellExecute(NULL,"open","C:\\\\C.exe",NULL,NULL,SW\_SHOW); HWND h=FindWindow(NULL,"Caption of C"); if(h) { ShowWindow(h,SW\_SHOW); } return 1; } break; default: break; } } return (CallNextHookEx(glhHook,nCode,wParam,lParam));
}
void _stdcall StartKeyMask()
{
glhHook = SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,glhInstance,0);
}void _stdcall StopKeyMask()
{
if (glhHook!=NULL)
UnhookWindowsHookEx(glhHook);
}modified on Sunday, February 22, 2009 10:53 AM
You can try with SetForegroundWindow[^]
Doc
-
You can try with SetForegroundWindow[^]
Doc
-
guamp wrote:
use " SetForegroundWindow" no effect
See http://blogs.msdn.com/oldnewthing/archive/2009/02/20/9435239.aspx[^] for a possible explanation.