How can I make an accelerator table. Tryed everything but can't make it work properly. I put a series of ACCEL strukts (5 bytes) into a buffer and register with:

LOCAL accel[64]:ACCEL

;ax key
;edi ptr to buffer
mov (ACCEL ptr ).fVirt,FVIRTKEY or FCONTROL
mov (ACCEL ptr ).key,ax
mov eax,MenuID
mov (ACCEL ptr ).cmd,ax

invoke CreateAcceleratorTable,addr accel,nAccel
mov hAccelTools,eax

and in the messageloop:

invoke TranslateAccelerator,hWnd,hAccelTools,addr msg
.if eax==0
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
.endif

What am I doing wrong?

Any working code example would be great.

KetilO
Posted on 2001-12-31 07:01:11 by KetilO
Happy new year everybody.

To create an accelerator table shoud be straight forward, but I can't make it work. What am I missing here? Please help me out, this is delaying my next release of RadASM.

Included a RadASM test project.
Posted on 2002-01-01 07:01:58 by KetilO
Here's a post from deja news that looks like what you're dealing with. I don't know if the solution is the best ( or if it even works ). I have no time today to check it out.
Hope it helps.

----------------------------------

> I am writing an application that uses a dialog box as the main Window.
> It is easy to add a menu, but how do you add accelerators?
> You would normally use TranslateAccelerator when you process the
> Windows message queue (see below), but with a Dialog box you cannot do
> this.
>
> Code I cannot use with dialog boxes:
>
> while (GetMessage (&msg, NULL, 0, 0)) {
> if (!TranslateAccelerator(hwnd, hAccel, &msg) {
> TranslateMessage (&msg);
> DispatchMessage (&msg);
> }
> }
>

You need to implement WH_MSGFILTER hook for dialog window. Like that:

LRESULT CALLBACK MsgHookProc(
int nCode, WPARAM wParam, LPARAM lParam)
{
if(0 <= nCode && MSGF_DIALOGBOX == nCode)
{
PMSG pMsg = (PMSG)lParam;
if(WM_KEYFIRST <= pMsg->message &&
WM_KEYLAST >= pMsg->message)
{
if(TranslateAccelerator(g_hDlgWnd, g_hAccel, pMsg))
return TRUE;
}
}

return CallNextHookEx(g_hMsgHook, nCode, wParam, lParam);
}

Note: If this code will run in different threads you cannot use global
variables for window, accelerator table and hook. Rather you should
use some per-thread storage (Thread Local Storage is perfect for that)
for these values.

Here is a description of that problem:
http://msdn.microsoft.com/library/periodic/period99/faq0499.htm

But if you are using MFC for your dialog, then you can override
PreTrnaslateMessage and load your accellerator table.
Posted on 2002-01-01 11:46:13 by Wayne
Hi all

Phew. Took me 10 hours to find that the ACCEL struct in windos.inc was the reason. Had to create my own.

Thanks Wayne, but not what I was looking for.

Here is the working example.
Posted on 2002-01-01 13:44:33 by KetilO
hii

i dont have time to assemble it right now . but the exe doesnt work on my system
:(



bye

eko
Posted on 2002-01-01 15:17:44 by eko
Hi all

Change the line:

invoke CreateAcceleratorTable,addr accel,2

to:

invoke CreateAcceleratorTable,addr accel,8

This will make all 8 accelerators (Ctrl+A to Ctrl+H) work.

KetilO
Posted on 2002-01-01 16:38:10 by KetilO
if(0 <= nCode && MSGF_DIALOGBOX == nCode)


:)
Read again what you wrote.
It's the same if x = 0 and x <= 0
:)
Posted on 2002-12-02 10:05:04 by The Svin
Originally posted by The Svin


:)
Read again what you wrote.
It's the same if x = 0 and x <= 0
:)


I think it is because he did know that MSGF_DIALOGBOX equ 0
Posted on 2002-12-02 10:45:02 by roticv
You meant "he didn't ?"
Anyway, look at the condition statement again.
If
MSGF_DIALOGBOX > 0 then statement doesn't have
any sence.
'Cause in any case it is impossible to meet condition.
if MSGF_DIALOGBOX <=0 then another part is
redandent.

It is like saying
if x=5 and x > 0.
If x == 5 is enough.
Posted on 2002-12-02 16:41:45 by The Svin
Ok.. I get your point.:grin:
Posted on 2002-12-02 22:25:46 by roticv