Luigi Auriemma

aluigi.org (ARCHIVE-ONLY FORUM!)
It is currently 19 Jul 2012 14:46

All times are UTC [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: how to add accelerators to Dialog boxes
PostPosted: 28 Aug 2007 16:20 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
today I was becoming crazy for this problem, I have a simple dialog box created through the classical DialogBox() but the problem is that you cannot load accelerators (the shortcuts like CTRL-O, CTRL-F and so on) because the loop which handles them is internally managed by Windows.

So my friend James suggested me this method which works and allows us to get anything typed on the keyboard so accelerators are only one of the many things which we can do with this code, for example I have added the possibility of navigating inside a fixed size edit control.

IDC_TIMER is the ID of the resource, you can assign any value to it
100 is the amount of milliseconds of the timer

If you know other ways, write them here:

#include <windows.h>
#include "resource.h"

BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch(Message) {
case WM_INITDIALOG: {
SetTimer(hwnd, IDC_TIMER, 100, (TIMERPROC)NULL);
} break;
case WM_COMMAND: {
} break;
case WM_TIMER: {
if(GetForegroundWindow() != hwnd) break;
if(GetAsyncKeyState(VK_CONTROL)) {
if(GetAsyncKeyState('A')) {
MessageBox(0, "CTRL-A pressed", "test", MB_OK | MB_TASKMODAL);
}
}
} break;
case WM_CLOSE: {
KillTimer(hwnd, IDC_TIMER);
DestroyWindow(hwnd);
} break;
case WM_DESTROY: {
PostQuitMessage(0);
} break;
default: {
return(0);
} break;
}
return(0);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
return(DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc));
}


Top
 Profile  
 
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: