TabIndex, Hotkeys and Accelerators


Step1 will be about creating a working TABINDEX. We gonna setup a few edtiboxes and a button so we can loop between them
with just hitting the TAB button on the keyboard. Its actually very easy.

Insert following code in your dispatch loop: (found in the Win Main proc, assuming you are using DialogAsMain.tpl)

            invoke GetMessage, ADDR msg,NULL,0,0
    .BREAK .IF (!eax)
            invoke IsDialogMessage, hWnd, ADDR msg
    .IF (!eax)
            invoke TranslateMessage,addr msg
            invoke DispatchMessage,addr msg

Thats it! TABINDEX is setup and working. Get the sample project here.


Accelerators and Hotkeys:

Step2: Start a new Project with DialogAsMain.tpl for your template.
Open your dialog editor and make it look like the following:

Accel1.jpg (19792 Byte)

This first easy sample will show you how to add the hotkey CTRL+O to the Button "Hello"
This is easy since RADASM comes with a useful addin that does most of the work for us.
But first we extend our loop in WinMain, with following code:

.while TRUE
        invoke GetMessage,addr msg,NULL,0,0
.BREAK .if !eax
        invoke TranslateAccelerator,hWnd,hAccel,addr msg
.if !eax
        invoke TranslateMessage,addr msg
        invoke DispatchMessage,addr msg

in your .inc file you have to add those:

IDC_BTN1         equ 1001
IDR_ACCEL      equ 2000

hAccel dd ?

In the WM_INITDIALOG place following:

invoke LoadAccelerators,hInstance,IDR_ACCEL
mov hAccel,eax

After this our first Hotkeys for the menu should already work. Go assemble & link your project and hit Run! When you now press ALT + F your IDM_FILE_MENU should appear, when you press ALT + H your IDM_HELP_MENU should appear.   Easy ?

But it gets more easier: In your RADASM click Project the click Accelerator. Fill in the Acceleartor dialog till its something like this:

Accel2.jpg (34892 Byte)

IMPORTANT: The ID of your button must be the same then the ID of your key "o".

After this your Hotkey CTRL+o should result in clicking the Hello button. Place following code to the hello button as a test.

invoke MessageBox,hWin,offset AppName,offset DlgName,MB_ICONINFORMATION

If you want F1 as your hotkey choose F1 as your Key and DONT check any of the 3 checkboxes.

The complete project can be found here.

Ketil O. has created a very good sample (uses a struct to fill the accelerator info) . You can find his sample in the Masm32 code section.