winmain calls creact to create the table and save the handle and this seems to work OK.
; creact: !CreateAccelTable [achdl] eax retn
creact:
invoke CreateAcceleratorTable,ADDR acceltbl,1
or eax, eax
jnz @F
call erbeep ;debugging
@@:
mov [achdl], eax
retn
The routine, located outside any procedure in "Global Utilities" is reached and the function does not fail.
This is the data used (in .DATA):
acceltbl LABEL BYTE
accel_k LABEL BYTE
DB FALT or FVIRTKEY
DW 4Bh ;keycode for k
DW 21 ;CMD no. for alt-k
;acceltbl ends
achdl DD ? ;ACcelerator table HanDLe
The winmain message loop is:
msglp:
invoke GetMessage, ADDR msg,NULL,0,0 ;msg local winmain
or eax, eax
jz msglp_ex
js msglp_err
invoke TranslateAccelerator, hwnd,achdl,ADDR msg
or eax, eax
jz @F
call erbeep ;debugging
jmp msglp_dspch
@@:
invoke TranslateMessage, ADDR msg
msglp_dspch:
invoke DispatchMessage, ADDR msg
jmp msglp
The invoke TranslateAccelerator, hwnd,achdl,ADDR msg always returns 0, and a WM_COMMAND message is never received.
Can anyone suggest what I am doing wrong?
The complete code is at:
http://www.intergate.com/~rale/lfw.asm
One problem is that the members of your ACCEL structure are not aligned as Windows expects. In the MASM32 windows.inc the structure is declared as:
ACCEL STRUCT WORD
fVirt BYTE ?
key WORD ?
cmd WORD ?
ACCEL ENDS
The WORD alignment value specifies that the members should by aligned on 2-byte boundaries, so the offsets of the members from the start of the structure should be:
0 fVirt
2 key
4 cmd
But as you have defined it the offsets are:
0 fVirt
1 key
3 cmd
You can correct the problem by adding a 1-byte pad between the fVirt and key members, or by using the structure, something like this:
accel_tbl ACCEL <FALT or FVIRTKEY, 4bh, 21>
But note that this is may not be the only problem.
Thank you. It works now!
I've learned something about structures and alignment.
MichaelW
Global Moderator
Wrote:
Re: keyboard accellerator doesn't work.
« Reply #1 on: Today at 09:35:37 AM »
Reply with quote
One problem is that the members of your ACCEL structure are not aligned as Windows expects. In the MASM32 windows.inc the structure is declared as:
Code:
ACCEL STRUCT WORD
fVirt BYTE ?
key WORD ?
cmd WORD ?
ACCEL ENDS
The WORD alignment value specifies that the members should by aligned on 2-byte boundaries, so the offsets of the members from the start of the structure should be:
0 fVirt
2 key
4 cmd
But as you have defined it the offsets are:
0 fVirt
1 key
3 cmd
You can correct the problem by adding a 1-byte pad between the fVirt and key members, or by using the structure, something like this:
accel_tbl ACCEL <FALT or FVIRTKEY, 4bh, 21>
But note that this is may not be the only problem.