Thanks for all your help then.
Printable View
Thanks for all your help then.
I found it!
With the help of http://www.cplusplus.com/forum/windows/36860 I changed my search from "shortcut" to "hotkey" I found something about keyboard accelerators (http://social.msdn.microsoft.com/For...2-617d69557057) which led me here: http://msdn.microsoft.com/en-us/libr...ting_acc_table
After figuring out the way it worked, I have this (Spread across several files)
It works prefectly.Code:/*Keyboard Accelerators*/
ShortAccel ACCELERATORS {
VK_ESCAPE, IDA_ESC, VIRTKEY
}
/*---*/
//Load accelerators
HACCEL haccel;
haccel=LoadAccelerators(hinst, _T("ShortAccel"));
if(!haccel) //Make sure it loaded
MessageBox(hwnd, _T("Unable to load accelerator table"), _T("Error"), MB_ICONERROR);
while(GetMessage(&msg, NULL, 0, 0) > 0){
if(!TranslateAccelerator(FindWindow(_T("SettingsWindow"),_T("Settings")),haccel,&msg)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
/*---*/
#define IDA_ESC 4001
/*---*/
LRESULT fnSettingsProc_OnCommand(lpWndEventArgs wea){
switch(LOWORD(wea->wParam)){
case IDA_ESC: //Name given in accelerator table
DestroyWindow(wea->hwnd);
break;
}
return 0;
}
You may be surprised, but code suggested by Mark hardly differs much from the last code you showed. What translate accelerator does is sending WM_COMMAND with corresponding id in case virtual key can be found in the table.
Code:while(GetMessage(&msg, NULL, 0, 0) > 0){
if (msg.message == WM_KEYDOWN &&
LOWORD(msg.wParam) == VK_ESCAPE)
SendMessage(FindWindow(_T("SettingsWindow"),_T("Settings")), WM_COMMAND, IDA_ESC, 0);
if(!IsDialogMessage(glbWin.vScrollContent, &msg)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
I see what you mean. I think I'll stick with the method I found though, as it is easier to expand.
...and you're 100% right. My point was just to make a bond between what you've found yourself and what you've been told of before. :)
And that I do appreciate. I wouldn't have known that is how it worked if it wasn't for your telling me. :)
This can done in the window callback handler. ie: in WindowProc. And for removing that behavior instead of showing a msgbox just drop the value bu setting a NULL.
just an alternative for the above code.Code:LRESULT CALLBACK wndProc (HWND hW, UINT msg, WPARAM wP, LPARAM lP)
{
switch (msg)
{
case WM_KEYDOWN:
{
if (wParam == VK_ESCAPE)
wParam = NULL;
}
}
return 0;
}
No, it's not. The code in the message loop works with focus set anywhere in the app. Unlike your "alternative" which requires to have a focus on the particular window.Quote:
just an alternative for the above code.