Results 1 to 6 of 6

Thread: mouse over

  1. #1
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    mouse over

    I will keep it simple.

    I have a dialog window with a button and I want to know when the mouse pointer is on top of the button.

    Do I %WM_Command to find the button control
    or
    %WM_MOUSEMOVE and then find the button control.

    I know XP has NMBCHOTITEM http://msdn2.microsoft.com/en-us/library/bb775959.aspx but I am not sure how to implement that.

    Anyone care to point me in the right direction.
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  2. #2

    Re: mouse over

    Abraxas, I've been waiting for someone to give an answer because I don't understand just what you are trying to do. I am dying of curiosity.... What exactly are you trying to do?

    Thanks
    Sandy

  3. #3
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: mouse over

    Sandy you will have to wait and see. ;D

    I am getting there but its not quite working.

    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10

    Re: mouse over

    Abraxas,

    sorry for the delay I take to reply on this.
    I looked at NMBCHOTITEM (that I didn't know) and it is valid only from Win2K up. So not sure if it is a valid road.

    I have this idea. Use %WM_MOUSEMOVE return message. It returns in LParam the x/y coordinates of the mouse relative to the client area of the window. That use ChildWindowFromPoint function (see declaration below) to get the handle of the child window (any control is in reality a window) where the mouse is located. If it correspond to the button you need than bingo.

    Of course you need to know the windows handle of your button and this can be achieve using CONTROL HANDLE statement passing the window handle and the control ID. Also consider that all CONTROL ADD ... functions from thinBasic stable version 1.5.0.0 automatically return the window handle of the control just added.

    DECLARE FUNCTION ChildWindowFromPoint LIB "USER32.DLL" _
                       ALIAS "ChildWindowFromPoint" _
                       (BYVAL hwndParent AS DWORD, BYVAL x AS LONG, BYVAL y AS LONG) AS DWORD
    
    I didn't test my idea so far, so, please, let me know if it works or not.
    Ciao
    Eros
    Last edited by ErosOlmi; 24-03-2011 at 12:41.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10

    Re: mouse over

    Forget my previous idea, I was not able to make it working.
    Anyhow, here a 99% of the times working example. There are some cases that will not work, for example when you window is not the current one but below some other. In this case some side effects can take place.

     uses "UI"
    
     TYPE RECT
      nLeft AS LONG
      nTop AS LONG
      nRight AS LONG
      nBottom AS LONG
     END TYPE
    
     TYPE POINTAPI
      x AS LONG
      y AS LONG
     END TYPE
    
     DECLARE FUNCTION PtInRect    LIB "USER32.DLL" ALIAS "PtInRect"    (lpRect AS RECT, BYVAL ptx AS LONG, BYVAL pty AS LONG) AS LONG
     DECLARE FUNCTION SetCapture   LIB "USER32.DLL" ALIAS "SetCapture"   (BYVAL hWnd AS DWORD) AS LONG
     DECLARE FUNCTION ReleaseCapture LIB "USER32.DLL" ALIAS "ReleaseCapture" () AS LONG
     DECLARE FUNCTION GetCursorPos  LIB "USER32.DLL" ALIAS "GetCursorPos"  (lpPoint AS POINTAPI) AS LONG
     DECLARE FUNCTION GetWindowRect LIB "USER32.DLL" ALIAS "GetWindowRect" (BYVAL hWnd AS DWORD, lpRect AS RECT) AS LONG
      
     %btn_OK    = 101
     %txt_Result  = 102
    
     MAIN
    
     FUNCTION MAIN() as long
      DIM Msg    AS LONG
      DIM wParam  AS LONG
      DIM lParam  AS LONG
      DIM hDlg   AS DWORD
    
      dim hBtn_OK  as dword
      dim pt    as POINTAPI
      dim rc    as RECT
    
      DIALOG NEW 0, "MouseOver test", -1, -1, _
        100, 100, %WS_SYSMENU or %ds_center OR %WS_CAPTION TO hDlg
    
      CONTROL ADD textbox , hDlg, %txt_Result , ""  , 10, 10, 80, 14, %WS_TABSTOP
      CONTROL ADD BUTTON , hDlg, %btn_OK   , "OK" , 25, 80, 50, 14, %WS_TABSTOP
    
      control handle hDlg, %btn_OK to hBtn_OK 
    
    
      DIALOG SHOW MODELESS hDlg
      
      '---Start the main message loop
      WHILE IsWindow(hDlg)         
      
       '---Get the message and fill wParam and lParam
       Msg = GetMessage(hDlg, wParam, lParam) 
          
       SELECT CASE Msg
    
        case %WM_MOUSEMOVE
         
         SetCapture hDlg
         
          GetCursorPos pt
          GetWindowRect hBtn_OK, rc
    
          IF ptInRect(rc,pt.x,pt.y) THEN
           control set text hDlg, %txt_Result, "Bingo"
          ELSE
           control set text hDlg, %txt_Result, ""
          END IF 
         
         ReleaseCapture
         
        CASE %WM_COMMAND
    
         '---Test which control has been clicked
         SELECT CASE wParam
    
          CASE %btn_OK
           exit while
           
         END SELECT
    
        CASE %WM_SYSCOMMAND
    
         SELECT CASE wParam
           
          CASE %SC_CLOSE
           EXIT WHILE
    
            
         END SELECT
    
        CASE ELSE
        
       END SELECT
       
      WEND
    
      DIALOG END hDlg
    
    
     END FUNCTION
    
    Attached Files Attached Files
    Last edited by ErosOlmi; 24-03-2011 at 12:42.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732

    Re: mouse over

    Hi Eros,

    here it works even if window is partially covered.
    Really nice sample, thanks !


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •