The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: rogerio on May 11, 2009, 02:38:31 PM

Title: Can the ID/handle of a non-clickable control be returned with the mouse?
Post by: rogerio on May 11, 2009, 02:38:31 PM
Is it possible to return the ID or handle of a non-clickable control such as a static or bitmap when the mouse is over it? I have tried WM_MOUSEHOVER and RealChildWindowFromPoint, but they only work on clickable controls like edits or buttons. Thanks...



I have removed the "SOLVED" part of the title as this forum is not a help desk but also a reference for other programmers.
Title: Re: Can the ID or handle of a non-clickable control be returned with the mouse?
Post by: rogerio on May 11, 2009, 04:28:02 PM
Found the solution: Add the SS_NOTIFY style and use WM_COMMAND  to trap the message. This works with all of the WM_MOUSExxx messages also.
Title: Re: SOLVED: Can the ID/handle of a non-clickable control be returned with the mouse?
Post by: MichaelW on May 11, 2009, 05:31:48 PM
This is a simple example that uses the WM_MOUSEMOVE message directly, based on a MASM32 in-memory dialog.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
; Build this as a console app so print will work.
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc

    CID_STATIC equ 100
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      hInstance   dd 0
      hwndStatic  dd 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

DlgProc proc hwndDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

    LOCAL pt:POINT, hwnd:DWORD

    SWITCH uMsg

      CASE WM_INITDIALOG

        invoke GetDlgItem, hwndDlg, CID_STATIC
        mov hwndStatic, eax

        print "hwndDlg = "
        print uhex$(hwndDlg),13,10
        print "hwndStatic = "
        print uhex$(hwndStatic),13,10

      CASE WM_MOUSEMOVE

        ;-------------------------------------------------
        ; Get the client coordinates of the mouse cursor.
        ;-------------------------------------------------

        movzx eax, WORD PTR lParam
        mov pt.x, eax
        movzx eax, WORD PTR lParam+2
        mov pt.y, eax

        ;--------------------------------------------------------------
        ; Get the handle of the window that contains the mouse cursor.
        ;--------------------------------------------------------------

        invoke ChildWindowFromPoint, hwndDlg, pt.x, pt.y
        mov hwnd, eax

        ;---------------------------------------
        ; And display it in the static control.
        ;---------------------------------------

        invoke SetWindowText, hwndStatic, uhex$(hwnd)

      CASE WM_CLOSE

        invoke EndDialog, hwndDlg, 0

    ENDSW

    xor eax, eax
    ret

DlgProc endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    invoke GetModuleHandle, NULL
    mov hInstance, eax

    Dialog "Test", \                      ; caption
           "MS Sans Serif",10, \          ; font,pointsize
            WS_OVERLAPPED or \            ; styles for
            WS_SYSMENU or DS_CENTER, \    ; dialog window
            1, \                          ; number of controls
            0,0,60,40, \                  ; x y co-ordinates
            1024                          ; memory buffer size

    DlgStatic "Static",SS_CENTER or WS_BORDER,8,10,40,10,CID_STATIC

    CallModalDialog hInstance,0,DlgProc,NULL

    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

Title: Re: SOLVED: Can the ID/handle of a non-clickable control be returned with the mouse?
Post by: rogerio on May 11, 2009, 09:35:04 PM
Thanks MichaelW for the help. If anyone figures out all of this junk, they need to be put in a museum.
Title: Re: SOLVED: Can the ID/handle of a non-clickable control be returned with the mouse?
Post by: rogerio on May 11, 2009, 10:50:45 PM
MichaelW, I took a look at your code and found that it will only return static controls. I did do some further looking and found that using the POINT method does not return clickable controls. What am I missing?
Title: Re: SOLVED: Can the ID/handle of a non-clickable control be returned with the mouse?
Post by: MichaelW on May 12, 2009, 05:04:08 AM
I'm guessing that controls that can have the focus capture the mouse, or something similar. I could not find any quick fix for this problem. The capture example from the attachment  here (http://www.masm32.com/board/index.php?topic=9637.0) can capture a button, or any other window (even in another application's window), and to do that it must first get the handle.

Title: Re: Can the ID/handle of a non-clickable control be returned with the mouse?
Post by: rogerio on May 12, 2009, 10:41:45 AM
Thanks MichaelW, it will take some time to get through this. I did notice the one on capture and will start with it, but I will look at the rest also; M$ doesn't make things easy. Thanks...