Announcement

Collapse
1 of 2 < >

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
2 of 2 < >

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Tracking Mouse

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tracking Mouse

    All,
    If you ever need to know when the mouse has left your dialog then this could be of use to you. No need for %WM_MOUSEMOVE or %WM_MOUSELEAVE.

    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "WIN32API.INC"
    
    FUNCTION PBMAIN () AS LONG
        LOCAL Count AS LONG
        LOCAL hDlg AS LONG
    
        DIALOG NEW 0,"Mouse TRAP",50,50,148,150,%ws_sysmenu,TO hDlg&
        CONTROL ADD LABEL,hDlg&,302,"%WM_MOUSEMOVE       x=0;y=0",10,110,130,10
        CONTROL ADD TEXTBOX,hDlg&,501,"Sample",10,40,70,12
        CONTROL ADD BUTTON,hDlg&,500,"Button",10,70,70,15
    
        DIALOG SHOW MODELESS hDlg&,CALL DlgCallBack
        DO
            DIALOG DOEVENTS TO Count
        LOOP WHILE Count AND IsWindow(hDlg)
    END FUNCTION
    
    CALLBACK FUNCTION DlgCallBack
      LOCAL gpt AS POINTAPI
      LOCAL xCnt AS LONG
      LOCAL yCnt AS LONG
    
      LOCAL dlgx AS LONG
      LOCAL dlgy AS LONG
    
      LOCAL mx AS LONG
      LOCAL my AS LONG
    
      SetTimer CBHNDL,1000,100,BYVAL %NULL
    
      SELECT CASE AS LONG CBMSG
          CASE %WM_TIMER
              IF CBWPARAM=1000 THEN
    
                  GetCursorPos gPt
                  mx = gPt.x
                  my = gPt.y
                  CONTROL SET TEXT CBHNDL,302,"Mouse Location  x="+FORMAT$(mx)+"; y="+FORMAT$(my)
    
                  DIALOG GET LOC CBHNDL TO dlgx&, dlgy&
                  DIALOG UNITS CBHNDL, dlgx, dlgy TO PIXELS dlgx, dlgy
                  DIALOG GET SIZE CBHNDL TO xCnt&, yCnt&
                  DIALOG UNITS CBHNDL, xCnt, yCnt TO PIXELS xCnt, yCnt
    
                  IF mx > dlgx - 1 AND mx < dlgx + xCnt AND my > dlgy - 1 AND my < dlgy + yCnt THEN
                      PostMessage CBHNDL, %WM_APP, 0, 0
                  ELSE
                      PostMessage CBHNDL, %WM_APP + 1, 0, 0
                  END IF
    
              END IF
    
          CASE %WM_APP
    
                  SetWindowText CBHNDL, "Dialog - on dialog"
    
          CASE %WM_APP + 1
    
                  SetWindowText CBHNDL, "Dialog - off dialog"
    
    
      END SELECT
    END FUNCTION
    And if you want to use this with SDK style apps, you will need to change

    Code:
                  DIALOG GET LOC CBHNDL TO dlgx&, dlgy&
                  DIALOG UNITS CBHNDL, dlgx, dlgy TO PIXELS dlgx, dlgy
    to this:

    Code:
                  GetWindowRect hDlgAddr, rc    'gets the dialog start x and y points
                  dlgx = rc.nLeft
                  dlgy = rc.nTop

    Since the aforementioned DDT code does not work with SDK. Plus add this to the locals
    LOCAL rc AS RECT
    to get the correct location for your dialogs upper left corner.

    and even though the following works with SDK:
    Code:
                  DIALOG GET SIZE CBHNDL TO xCnt&, yCnt&
                  DIALOG UNITS CBHNDL, xCnt, yCnt TO PIXELS xCnt, yCnt
    it can be replaced with this:

    Code:
                  xCnt = rc.nRight - rc.nLeft
                  yCnt = rc.nBottom - rc.nTop

    enjoy
    Last edited by Jim Fritts; 28 Nov 2007, 06:01 PM.
Working...
X