Originally posted by sean345
When I create my dialog I am using the function DialogBox. How can I use the message loop you gave with the DialogBox function?
- Sean
Good question!......never really thought about that! You got me to pull out the compiler and start messing....
I tried to install a hook to read the MSG before the GetMessage() of your dialog laid its hands on it .....
After some messing I came up with this......seems to woke AOK
Code:
#include <windows.h>
#include "resource.h"
HHOOK g_hHook;//evils of globals I know...
HACCEL g_hAcc;
HWND g_hWnd;
BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,
LPARAM lParam){
switch(uMsg){
case WM_INITDIALOG:
g_hWnd = hwndDlg;//Set Global hwnd
return 1;
case WM_CLOSE:
EndDialog(hwndDlg,0);
return 1;
case WM_COMMAND:
if(LOWORD(wParam)==ID_F1){//catch F1 Key
MessageBox(hwndDlg,"F1 Pressed",NULL,MB_OK);
return 1;
}
else break;
}
return 0;
}
LRESULT CALLBACK GetMsgProc(int code,WPARAM wParam,
LPARAM lParam){
TranslateAccelerator(g_hWnd,g_hAcc,(MSG*)lParam); //Here's the func!
return CallNextHookEx(g_hHook,code,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,int){
g_hAcc = LoadAccelerators(hInst,
MAKEINTRESOURCE(IDR_ACCELERATOR1));
if(!g_hAcc)return 1;
g_hHook = SetWindowsHookEx(WH_GETMESSAGE,GetMsgProc,
hInst,GetCurrentThreadId());
if(!g_hHook)return 1;
DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),
HWND_DESKTOP,DialogProc);
UnhookWindowsHookEx(g_hHook);
return 0;
}
All that does is add a call to the hook procdecure before getting on with the normal business....
There's probably an easier more straight forward way though.....but the above works ok......