im pretty new to asm and got a strange problem.

i want that the key check stops during my msgbox is open.

so i set the value of a in .data

a db 0

and around the msgbox i wrote

inc a
Invoke MessageBox...
dec a

( mov a,1 - mov a,0 etc... gives the same result ).

And around WM_TIMER i wrote:

.IF a == 0




Now i press F1 (in the wm_timer key check) and the MsgBox gets opened. When i press F1 no new MsgBox gets opened. Thats actually like i want it.
BUT when i press again F1 one or more time during the MsgBox is opened the same MsgBox gets opened immediately after i close the first one!?

I really dont understand that. Can somebody help me :).
Posted on 2003-04-27 13:50:51 by Cenox

I am not completely sure of what you are after but be aware that while a MessageBox is running, the code in your own calling EXE is not running as a MessageBox is a small dialog that is run by the operating system that you cannot get at while it is running.

Try and explain a little more of what you are trying to do and I may be able to help you with it.


Posted on 2003-04-27 21:30:12 by hutch--
Cenox, you will need to explain a bit further (what is your WM_TIMER handler doing? - perhaps you should post source code).

While it's true calling a MessageBox blocks that thread until OK is clicked, that doesn't stop the system from posting messages to your message queue...
Posted on 2003-04-28 02:19:09 by f0dder

by the way i think i should have posted it into the main board :( .

another longer explanation for my prolly lil problem:

// Ive set a Timer:


T_ID equ 1
T_INT equ 80




Invoke SetTimer, hWnd, T_ID, T_INT, NULL


// I have set the Timer to check if a specific key has been pressed.
// So another important part:


Invoke GetAsyncKeyState, VK_F1
cmp eax, 0
je @F
Invoke Trn, oh, ADDR nh, 3, NULL
Invoke GetAsyncKeyState, VK_F2
cmp eax, 0
je @F
Invoke FindWindow, offset clsName, NULL
push eax
pop windhand
cmp al, FALSE
jnz @F
Invoke GetWindowThreadProcessId, windhand, addr pid
Invoke OpenProcess, PROCESS_ALL_ACCESS, NULL, pid
push eax
pop phandle
Invoke ReadProcessMemory, phandle, rs, addr buffer, 1, NULL
Invoke TrnEng, os, ADDR buffer, 1, NULL
Invoke GetAsyncKeyState, VK_F3
cmp eax, 0
je @F
Invoke Trn, oh, ADDR oh, 3, NULL


// So Far: A Timer is Set. If a specific Key (F1,F2,F3) got pressed another procedure gets started (Trn).
// @ F2 also some other Stuff.
// Ok a Part of Trn is:

Invoke FindWindow, offset clsName, NULL

push eax
pop windhand
cmp al, FALSE
jnz @F

Invoke MessageBox, hWndtr, offset err_run, offset cap_err, MB_OK+MB_TASKMODAL+MB_ICONWARNING


// If the Window cant be found an error Msg gets opened.

Ok. The Problem now is that when i press several times F1 i get the same amount of MsgBoxes :).
So i want to stop the key check that the program only reacts again when the MsgBox has been closed.

One Method i described in my Post above is to set a "variabel" a.
a db 0
Then put around the MsgBox
inc a and dec a.

so befor the error window gets opened. it incs a and a gets 1. if the MsgBox is closed it gets 0 again.

AND IN the WM_TIMER i set .IF a == 0 [ the stuff above ] .ENDIF. I thougt that when the MsgBox is opened a gets 1 and thats why the part where it checks for key presses gets ignored and so no other MsgBox will popup until i close the MsgBox.

ACTUALLY no other MsgBox pops up when i press again F1 or F2,F3 when one is open. BUT after i close that one and i pressed one or more times one of the keys (f1..) the same MsgBox gets opened immediately after i close the one.
Also when the MsgBox is opened and i press some key (a,b,c,4,...) i hear a sound. But when i press f1,f2,f3 i dont hear that ;)...

I also tried it with a Killtimer before the MsgBox and the StartTimer after the MsgBox but then i get the same strange result as stated above ...

puuhh.. always the little problems are the big ones :D.
Posted on 2003-04-28 11:06:16 by Cenox
Try checking the "are we in a message" in your WM_TIMER handler. That is, before your GetAsyncKeyState,

cmp [areWeInMsgBox], 0
jne @@weAreInAMessageBoxAbortRestOfCode

the setting of "areWeInMsgBox" should be done around the messagebox call though.
Posted on 2003-04-28 11:12:17 by f0dder

Problem solved.

( Credits to f0dder who helped me and wrote the code )

A better way to handle these hotkeys is to see if the state of the hotkey is 'down' or 'up'.
If it is 'up' the hotkey was pressed.

For e.g. F1 we need to put the following code into WM_TIMER when a timer is set:

Invoke GetAsyncKeyState, VK_F1 ; F1 Pressed?
test eax, 80000000h ; if most significant bit set, key is down
setz al

; al == 0, meaning key was released. If old state is down, trigger action.
; al == 1, key is up. Go directly to "store"

cmp al, 1
je @@store
Invoke Trn, oh, ADDR nh, 3, NULL ;Start my Procedure
mov [isF1down], al

Dont forget to set "isF1down db 0" in your .DATA Section.

Then it is also workin to skip that Part when the MsgBox is open like i wrote it in my posts above!

Maybe it helps also somebody else sometime :).
Posted on 2003-04-28 13:59:46 by Cenox