Hello,

How could I use an accelerator in a main dialog window ?
the dialog is the main window created with DialogBoxParam()
and the accelerator is inside a resource file.
I have load it with LoadAccelerators()
I have seen examples where TranslateAccelerator is called inside a loop when they use WNDCLASSEX but how to do it with a dialog ?
thank you
Posted on 2003-04-11 21:05:24 by Jnrz
You have to use them in a message loop or they don't work at all. At least that's how I understand it
invoke LoadAccelerators,hInst,200

mov hAccel,eax

.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateAccelerator,hDlg,hAccel,ADDR msg
.IF (!eax)
invoke IsDialogMessage, hDlg, ADDR msg
.IF (!eax)
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
.ENDIF
.ENDIF
.ENDW
mov eax,msg.wParam
Put your accelerators in the RC file like this
#define IDR_MAINACCEL 	200

IDR_MAINACCEL ACCELERATORS DISCARDABLE
BEGIN
VK_F1,IDM_HELP,VIRTKEY,NOINVERT
END
Posted on 2003-04-11 21:07:47 by donkey
:( does not work



WinMain proc Handle:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
LOCAL hAccel: DWORD
LOCAL msg: MSG

mov eax, uMsg
.if eax == WM_INITDIALOG
invoke LoadAccelerators, g_hInstance, 4000
mov hAccel,eax

.while TRUE
invoke GetMessage, addr msg, 0, 0, 0
. break .if (!eax)
invoke TranslateAccelerator, Handle, hAccel, addr msg
.if (!eax)
invoke IsDialogMessage, Handle, addr msg
.if (!eax)
invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg
.endif
.endif
.ednw
mov eax, msg.wParam
.elseif eax == WM_COMMAND
...
.endif
return 0
WinMain endp
Posted on 2003-04-12 01:45:18 by Jnrz
No, I explained it badly. They are the message loop. You cannot use the accelerators in a standard dialog, only in a dialog as window type program i.e.
start:

invoke GetModuleHandle, NULL
mov hInst,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInst, NULL, CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax

WinMain proc hInstance:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
LOCAL msg :MSG
LOCAL wc :WNDCLASSEX

mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WindowProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,DLGWINDOWEXTRA
mov eax,hInst
mov wc.hInstance,eax
mov wc.hbrBackground,COLOR_BTNFACE + 1
mov wc.lpszMenuName,IDR_MENU
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,hInst,ICO_APPICON
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc

invoke CreateDialogParam, hInst, ADDR DlgName, NULL, NULL, NULL
mov hDlg,eax

invoke ShowWindow, hDlg, CmdShow

invoke LoadAccelerators,hInst,200
mov hAccel,eax
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateAccelerator, hDlg, hAccel, ADDR msg
.IF (!eax)
invoke IsDialogMessage, hDlg, ADDR msg
.IF (!eax)
invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg
.ENDIF
.ENDIF
.ENDW
mov eax,msg.wParam

ret
WinMain endp

WindowProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

.IF uMsg == WM_CREATE

.ELSE
; Let the default window proc to handle unprocessed messages
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret

.ENDIF

xor eax,eax
ret
WindowProc endp
Posted on 2003-04-12 01:59:14 by donkey
you may emulate DialogBoxParam function by:

invoke CreateDialogParam
invoke EnableWindow, hWndOwner, FALSE
<manually coded message loop>
invoke EnableWindow, hWndOwner, TRUE

in the message loop you can use your accelerators. Dont forget to call IsDialogMessage.
Possibly you have to do a "invoke PostQuitMessage" when receiving WM_DESTROY message
Posted on 2003-04-12 04:51:48 by japheth