PDA

View Full Version : GetWindowKeyState and MsgBox



catventure
28-10-2008, 19:04
Hi,

I had some code OUTSIDE the Dialog Window Main Loop to check for a SPACE keypress and soon after in a different function called a MSGBOX with YES/NO buttons...

Below is cut-down code:



GETWINDOWKEYSTATE( hwnd, -1 )
DO
'---trap space keypress
IF getwindowkeystate(hwnd, %VK_SPACE ) THEN
sleep 200
EXIT DO
END IF
LOOP

GETWINDOWKEYSTATE( hwnd, -1 )





'REM: The messagebox below does not show up!!!
Retcode=MSGBOX( hwnd, "Some Text", %MB_YESNO or %mb_iconquestion, "Some Text" )
SELECT CASE Retcode
CASE %IDYES
etc...etc


Keypress worked fine but the msgbox above never showed up...!
I discovered that somehow the SPACE was being interpreted as a YES for variable Retcode and the CASE %IDYES was being immediately processed without the msgbox appearing for the user to make a choice... It is odd. I solved it (after some time) by adding a MSGBOX to the keypress routine like so:


GETWINDOWKEYSTATE( hwnd, -1 )
DO
'---trap space keypress
IF getwindowkeystate(hwnd, %VK_SPACE ) THEN
sleep 200
EXIT DO
END IF
LOOP

GETWINDOWKEYSTATE( hwnd, -1 )

'REM: Blank messagebox below does not appear at all - but nullifies SPACE keypress!!
MSGBOX hwnd,""






'Messagebox now appears correctly!!
Retcode=MSGBOX( hwnd, "Some Text", %MB_YESNO or %mb_iconquestion, "Some Text" )
SELECT CASE Retcode
CASE %IDYES
etc...etc


I am using version 1.6.0.10

Regards,
catventure

ErosOlmi
28-10-2008, 19:16
Hi catventure.

The above behave is a standard window behave. SPACE is used to confirm default button in modal dialog.

Try to execute whatever program that show a modal messagebox with a default button and press SPACE.
You will see that default button will be pressed like using the ENTER key.

To avoid this behave, one have to subclass the window behave but this is not possible in an interpreter.
You can avoid this behave creating your own MSGBOX window or using a different key press in your script.

At the moment this is the only thing I get get in my mind.

Ciao
Eros

catventure
28-10-2008, 19:22
Hi Eros,

Thanks for explanation. Since it seems working OK with the modification I think I will stick to using SPACE though (unless there is further trouble) It is used in TAB program to scroll pages of text waiting to be output in Adventure RichEdit. I think I used %vk_c before.
Anyhow - maybe useful little trick to know. :)

Regards,
catventure.

ErosOlmi
28-10-2008, 19:24
Ok, perfect.



You can avoid this behave creating your own MSGBOX window ...

Just to let you know, next thinBasic version will give you great power in creating very strong and much easier to do windows using windows callback.
Creating a personalized MSGBOX dialog will be very easy and comfortable.

Ciao
Eros