News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

GetKeyState and subclassing an edit control

Started by Jimg, November 28, 2005, 03:41:47 AM

Previous topic - Next topic

Jimg

I am subclassing some edits in a dialog, and wanted to get the tab behavior to work correctly.  I searched for some code, and the only thing I could find was the Iczelion tutorial 22.  It it he uses-

EditWndProc PROC hEdit:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
    .if uMsg==WM_KEYDOWN
        mov eax,wParam
        .if al==VK_RETURN
        .elseif al==VK_TAB
            invoke GetKeyState,VK_SHIFT
            test eax,80000000
            .if ZERO?
                invoke GetWindow,hEdit,GW_HWNDNEXT
                .if eax==NULL
                    invoke GetWindow,hEdit,GW_HWNDFIRST
                .endif
            .else
                invoke GetWindow,hEdit,GW_HWNDPREV
                .if eax==NULL
                    invoke GetWindow,hEdit,GW_HWNDLAST
                .endif
            .endif
            invoke SetFocus,eax
            xor eax,eax
            ret
        .else

Notice the test eax,80000000

So I thought to myself, he meant to type 80000000h, the high hexidecimal bit set.  Nope.  That doesn't work.  Looking furthur, I realized , GetKeyState is defined as a short.  The return is supposed to be the high bit set if the key is down.  The high bit of a short is 8000h, and the decimal value of 80000000 accidentally has the correct bit set and works!  It should have been
test eax,8000h

Thinking about it a little more, I just used GetNextDlgTabItem to do the moving, and skipped all the testing-

DoTab:
    invoke GetKeyState,VK_SHIFT
    and eax,8000h     ; will return zero (false) or non-zero (true) which means next/previous valid item to GetNextDlgTabItem
    inv GetNextDlgTabItem,hWin,hEdit,eax
    invoke SetFocus,eax

A little simpler for those that might need to do this.

hotrod

I just ran across this topic and I cannot get the added code to work. Has anyone worked with it? Thanks...
QuoteDoTab:
    invoke GetKeyState,VK_SHIFT
    and eax,8000h     ; will return zero (false) or non-zero (true) which means next/previous valid item to GetNextDlgTabItem
    inv GetNextDlgTabItem,hWin,hEdit,eax
    invoke SetFocus,eax
quote]