The MASM Forum Archive 2004 to 2012

Project Support Forums => MASM32 => Topic started by: hutch-- on June 26, 2005, 02:07:27 AM

Title: Test a toy for me.
Post by: hutch-- on June 26, 2005, 02:07:27 AM
The attached file is a test piece for the selection code I had posted before and now has the added capacity to draw buttons, move them using the mouse and size and micro adjust their position using the arrow keys. The arrow keys are used by themselves to microadjust the position and if the shift key is also used, it changes either the width or the height of the button that has the focus.

I have tested it on win98se and win2k sp4 and it appears to be working correctly.

[attachment deleted by admin]
Title: Re: Test a toy for me.
Post by: MichaelW on June 26, 2005, 03:20:36 AM
I don't currently have an XP installation, but under Windows 2000 it seems to work OK. I can drag the mouse to draw a button, and after release I can move or delete the button. I don't know if this means anything, but it misbehaves when I drop a button on another button. The image of the dropped button remains visible in the button it was dropped on until I force a redraw by attempting to drag the button out of the window, and then back in.


Title: Re: Test a toy for me.
Post by: hutch-- on June 26, 2005, 03:26:59 AM
Michael,

Thanks for running the example, the redraw has not been handled yet but I am interested in if the sizing and moving with the arrow keys and shift are working OK as well.
Title: Re: Test a toy for me.
Post by: Phil on June 26, 2005, 03:41:13 AM
Seems to work fine under XP. I did manual resizing, maximizing, minimizing, and shifted thru the menu items with the arrow keys after an initial click on the file item. I'm not sure if you meant test sizing the window by using the arrow keys ... if you did then I don't know how to do or test that. The buttons all displayed their message box when I clicked on them and they didn't display the message if I moved the pointer off of the button before releasing the mouse button. Looks like you have grouping built into the buttons as well. I didn't notice any overlap or bad behavior when I made the window small.
Title: Re: Test a toy for me.
Post by: hutch-- on June 26, 2005, 04:00:06 AM
Sorry Phil,

I should have made sense of the request. The keyboard moving and sizing is for the button that has the focus, arrow keys move it an Shift + arrow keys size the button.
Title: Re: Test a toy for me.
Post by: MichaelW on June 26, 2005, 04:20:32 AM
Hutch,

Sorry, I don't multitask as well as I used to :lol

Sizing/moving with the arrow keys works OK and the increment per keystroke seems just about right.
Title: Re: Test a toy for me.
Post by: Eóin on June 26, 2005, 12:14:14 PM
Hi hutch--, I'm running XP and resizing buttons doesn't seem to work. Using shift + an arrow key just moves a button.
Title: Re: Test a toy for me.
Post by: hutch-- on June 26, 2005, 02:33:14 PM
Eóin,

Thanks for running the test, tel me this much, do the arrow keys by themselves move the button once it is drawn or only with the Shift key pressed ?

This is the code I am using in the button subclass to handle the keys.


        invoke GetKeyState,VK_SHIFT
        rol eax, 16
        cmp ax, 1111111111111111b
        jne over

        switch wParam           ; change size
          case VK_LEFT
            sub pt2.x, 1
          case VK_RIGHT
            add pt2.x, 1
          case VK_UP
            sub pt2.y, 1
          case VK_DOWN
            add pt2.y, 1
        endsw
        jmp past

      over:
        switch wParam           ; move position
          case VK_LEFT
            sub pt1.x, 1
          case VK_RIGHT
            add pt1.x, 1
          case VK_UP
            sub pt1.y, 1
          case VK_DOWN
            add pt1.y, 1
        endsw

      past:
        invoke MoveWindow,hCtl,pt1.x,pt1.y,pt2.x,pt2.y,TRUE


Is there anything about your XP seteup that is unusual, keyboard etc ....
Title: Re: Test a toy for me.
Post by: RuiLoureiro on June 26, 2005, 03:22:45 PM
Hi,
    I tested in my XP and it works well with and without shift, moving the created button up, down, left and right. It doesnt do anything else.
Title: Re: Test a toy for me.
Post by: Eóin on June 26, 2005, 03:29:38 PM
I don't think I've any special setup, the arrow keys move the highlighted button regardless if shift is pressed or not.
Title: Re: Test a toy for me.
Post by: hutch-- on June 26, 2005, 03:33:06 PM
OK Guys,

Thanks for testing this out, it looks like XP does something different with GetKeyState().
Title: Re: Test a toy for me.
Post by: doomsday on June 26, 2005, 04:17:23 PM
Hi Hutch,

I'm playing with it on XP.

To add to MichealW's post, I think it might be a problem with the focus.  If you drop buttonA on top of buttonB then drag buttonB with the mouse then buttonB doesn't appear to be redrawn.

regards,
-Brent
Title: Re: Test a toy for me.
Post by: AeroASM on June 26, 2005, 09:06:04 PM
1. I also have WinXP, and Shift doesn't affect anything.

2. When Button B is dropped on top on Button A, when you try to drag Button B, it instead drags Button A which is underneath.
Title: Re: Test a toy for me.
Post by: jojo on June 26, 2005, 09:40:15 PM
Hutch, Shift works fine on my XP installation with a Swiss-German keyboard.
Title: Re: Test a toy for me.
Post by: hutch-- on June 27, 2005, 02:12:08 AM
Thanks jojo.

There is no code specific to the button on top of another so it will not handle redraws in that context but what I am testing is whether the shift key effects the movement and sizing of each button and it appears to be inconsistent on XP depending on which version is used. It seems that all version still send the arrow key data with the WM_MOUSEMOVE message but it seems that the return value from GetKeyState() may be treated differently on different versions.

What the code should do wth the Shift key pressed and the arrow keys used is change the size of the button that has the focus so it appears that that option is not being taken with the API I have used or alternatively I may not be using the return value corectly. I will see if there is a way to use GetAsyncKeyState() instead as I have had no problems with it in other contexts.
Title: Re: Test a toy for me.
Post by: hutch-- on June 27, 2005, 07:34:23 AM
Sorry to wear you out but I have another way of processing the return value from GetKeyState() as follows. This one is working OK on both my boxes so it might do the job. I have not changed the redraw issue but I am hoping that the key adjustments now work properly on XP. Arrow keys for fine adjustment, arrow keys & SHIFT for sizing the buttons.


        invoke GetKeyState,VK_SHIFT
        and eax, 10000000000000000000000000000000b
        jz over

        switch wParam           ; change size
          case VK_LEFT
            sub pt2.x, 1
          case VK_RIGHT
            add pt2.x, 1
          case VK_UP
            sub pt2.y, 1
          case VK_DOWN
            add pt2.y, 1
        endsw
        jmp past

      over:
        switch wParam           ; move position
          case VK_LEFT
            sub pt1.x, 1
          case VK_RIGHT
            add pt1.x, 1
          case VK_UP
            sub pt1.y, 1
          case VK_DOWN
            add pt1.y, 1
        endsw

      past:

        invoke MoveWindow,hCtl,pt1.x,pt1.y,pt2.x,pt2.y,TRUE

[attachment deleted by admin]
Title: Re: Test a toy for me.
Post by: AeroASM on June 27, 2005, 10:04:56 AM
it doesn't work on xp.
Title: Re: Test a toy for me.
Post by: Eóin on June 27, 2005, 12:17:35 PM
Doesn't work on XP for me either.

hutch--, check out this msdn (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/usingkeyboardinput.asp) example on using the wParam of WM_KEYDOWN instead of calling GetKeyState.
Title: Re: Test a toy for me.
Post by: zooba on June 27, 2005, 01:30:32 PM
IIRC, GetKeyState returns values of 0, 1, -127 and -128. I can't remember exactly what each bit means but it is restricted to a single byte. MSDN says the 'high-order bit' is set if the key is pressed, which in a SHORT (WORD) value would be 8000h or 8001h. In practise, the WORD would normally be 0FF80h or 0FF81h. Shame the documentation isn't any better.

BTW, GetKeyState sends a message requesting the state of a key whereas GetAsyncKeyState gets the interrupt-level state associated with the hardware.  :U
Title: Re: Test a toy for me.
Post by: hutch-- on June 27, 2005, 01:56:44 PM
Thanks guys, these version differences nearly drive me nuts. I tested GetKeyState() with both of the specified bits set or clear and it ran as either a toggle or a one off kit. From the return value in eax I tried,


        and eax, 10000000000000000000000000000000b  ; one off key hit
        and eax, 00000000000000000000000000000001b  ; toggle key alternate


I am already trapping the arrow keys from the wParam for WM_MOUSE MOVE so that is not the problem, its trapping the shift key reliably as well that is the problem on XP and I dont have a box set up with XP.
Title: Re: Test a toy for me.
Post by: Eóin on June 27, 2005, 04:57:38 PM
Hi --hutch, I just ran a quick check of the return values from "invoke GetKeyState,VK_SHIFT" on XP. They are

No key pressed: eax = 0h or 1h
Shift key pressed: eax = FFFFFF81h ro FFFFFF80h.

Maybe that'll be helpful to you.
Title: Re: Test a toy for me.
Post by: Ghirai on June 28, 2005, 10:42:59 AM
Tested @ work on 2k sp4 and 2k server, works fine.
Title: Re: Test a toy for me.
Post by: hutch-- on June 28, 2005, 11:32:11 AM
I used Eóin's suestion and tested the two values and it appears to be working fine in my win2k box. I wrote up a test piece in binary notation output and the results were unusual. It seems the terminology for high order and low order bit ALA Microsoft apply on to the AL register, not EAX the return value.

I did the test with,


            invoke GetKeyState,VK_SHIFT

            cmp al, 10000000b
            je lbl1

            cmp al, 10000001b
            je lbl2


and the results verified the toggle state of the key.

I have attached the project with source this time as it is almost reliable.

Same as before, draw a button and then move it with the arrow keys for fine adjustment, arrow keys and Shift change the right or bottom side of the button while sizing.

[attachment deleted by admin]
Title: Re: Test a toy for me.
Post by: AeroASM on June 28, 2005, 12:31:21 PM
still doesn't work on xp - you must be getting frustrated!

do you want me to do any testing?
Title: Re: Test a toy for me.
Post by: Mark Jones on June 28, 2005, 02:01:26 PM
It works fine for me on XP SP2... left-click and drag in the main window to create a "button" then (while selected) use the arrow keys to move it.
Title: Re: Test a toy for me.
Post by: AeroASM on June 28, 2005, 02:54:12 PM
but when you hold shift and use the arrow keys it moves instead of resizing...
Title: Re: Test a toy for me.
Post by: Mark Jones on June 28, 2005, 04:38:57 PM
Whoops, missed that part. :green
Title: Re: Test a toy for me.
Post by: hutch-- on June 29, 2005, 01:57:37 AM
I have attached a test piece to try and find what the difference is with XP over win2k and win9x with the return values from GetKeyState().

With the bin toggle button I get with NO Shift key pressed,

00000000000000000000000000000000
or
00000000000000000000000000000001


With the Shift key pressed, I get,


11111111111111111111111110000000
or
11111111111111111111111110000001


The second button titled No Toggle has the toggle bit masked out while the third button does not. Both the second and third button work on AL only from the return value of GetKeyState().

Sorry to wear you out but the results have been very unpredictable on XP where they work perfectly on win9x and win2k.

[attachment deleted by admin]
Title: Re: Test a toy for me.
Post by: zooba on June 29, 2005, 12:55:25 PM
Thanks for including your code in the most recent file Hutch ;-)

You've got this code:

        invoke GetKeyState,VK_SHIFT
        .if eax == 0FFFFFF81h || eax == 0FFFFFF80h
          jmp over
        .endif


Change it to:

        invoke GetKeyState,VK_SHIFT
        test al, 80h
        jnz over


and it works fine on WinXP  :U

My guess is that pre-WinXP GetKeyState negated the return value if the key is down whereas WinXP simply sets the (mildly) appropriate bit. The function is not well documented, maybe this will help  :P
Title: Re: Test a toy for me.
Post by: chep on June 29, 2005, 01:05:30 PM
Hi,

I just tried both the first and the latest version, and both work fine here on WinXP (no service pack) / french keyboard.

zooba's fix also works fine (tested on the latest version SELECT03.ZIP).
Title: Re: Test a toy for me.
Post by: Mark Jones on June 30, 2005, 03:35:59 AM
I get this in Hutch's latest test piece:

Bin Toggle:        00000000000000000000000000000000 / 00000000000000000000000000000001
(only toggles and changes with shift alternated)
Bin Toggle(shift): 11111111111111111111111110000000 / 11111111111111111111111110000001
No Toggle:         00000000
No Toggle(shift):  00000080
Toggle:            00000000 / 00000001
Toggle(shift):     00000080 / 00000081
Title: Re: Test a toy for me.
Post by: dsouza123 on July 02, 2005, 09:01:18 PM
XP Pro SP2

All three versions of select.exe work the same

Arrows micro move the button   
Ctrl+Arrows micro move the button
Shift+Arrows resize the button
Shift+Ctrl+Arrows resize the button
Alt+Arrows nothing (moves or resizes)

Keytest gives the what Mark Jones listed.
Title: Re: Test a toy for me.
Post by: hutch-- on July 03, 2005, 02:56:24 AM
dsouza123,

Thanks for running the tests, it matches the results I get on win2k sp4 but I still don't have an answer of why the micro size adjustment does not work on some installations of XP.
Title: Re: Test a toy for me.
Post by: askm on February 06, 2008, 02:10:12 PM
I was searching
GetKeyState...

Re: Test a toy for me.
Where is this toy progress
now ?
Title: Re: Test a toy for me.
Post by: ToutEnMasm on February 06, 2008, 02:26:42 PM
Hello,
XP SP2

The space bar invalid the drawing of the rectangle and when left clic mouse the selected drawing rectangle move.
Shift key invalid the drawing of the rectangle but there is no move of the selected rectangle.
Perhaps using only WM_KEYUP (down) and WM_CHAR is better