WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Dialog Editor version 6.X
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Determine Control That Mouse is Hovering Over


Question:

Is there a way of finding out over which of several controls in a WIL dialog the mouse pointer is currently hovering over.

Answer:

#DefineSubRoutine Zmmain(zmHndl, zmEvnt, zmCtrlNum, zmRsvd1, zmRsvd2)
   Select    zmEvnt
      ;:00InitDialog
      Case 0
         ; Controls Used: ITEMBOX,PUSHBUTTON
         btnCancel =  003
         btnOk     =  002
         lbxList   =  001

         DialogProcOptions(zmHndl, 1, @TRUE)     ; 1 ms Timer.
         DialogProcOptions(zmHndl, 2, @TRUE)     ; Button Clicked.
         Return -1

      ;:0Timer
      Case 1
         BoxOpen("","")
         Moe = udfMouseOver(zmHndl, zmNumControls)
         If Moe Then BoxText(StrCat('Mouse is over ', Moe))
         Return -1

      ;:0Button Clicked
      Case 2
         Select    zmCtrlNum
            Case btnOk
               Return 1

            Case  btnCancel
               Return 0

         EndSelect ;   zmCtrlNum
         Return -1

   EndSelect ;   zmEvnt
   Return -1

#EndSubRoutine ;zmMain



#DefineFunction udfctrlfrompt(hCtrl)
   RECT = BinaryAlloc(16)

   ; Fill buffer with control coordinates and get offfsets of initial point.
   DllCall(StrCat(DirWindows(1), "User32.DLL"), long:"GetWindowRect", long:hCtrl, lpbinary:RECT)
   XX = BinaryPeek4(RECT, 0)
   YY = BinaryPeek4(RECT, 4)

   ; Is the mouse over the control?
   Coords = MouseInfo(3)                  ; Mouse screen coordinates in pixels
   mX  = ItemExtract(1, Coords, ' ')
   mY  = ItemExtract(2, Coords, ' ')
   If !DllCall(StrCat(DirWindows(1), "User32.DLL"), long:"PtInRect", lpbinary:RECT, long:mX, long:mY) Then Rtn = @FALSE
      Else Rtn = StrCat(mX-XX, @TAB, mY-YY)    ; Convert mouse coords to client coords.

   BinaryFree(RECT)
   Return Rtn

#EndFunction   ;udfCtrlFromPt

#DefineFunction udfMouseOver(hDlg, CtrlCnt)
   User32 = StrCat(DirWindows(1), 'User32.dll')
   For Cnt = 1 To CtrlCnt
      hCtrl = DllCall(User32, long:"GetDlgItem", long:hDlg, long:Cnt+99)
      If udfctrlfrompt(hCtrl)!=0 Then Return Cnt
   Next
   Return 0
#EndFunction   ;udfMouseOver


List = FileItemize(StrCat(DirScript(), '*.*'))

zmFormat=`WWWDLGED,6.1`

zmCaption=`Scroll Bars`
zmX=002
zmY=033
zmWidth=106
zmHeight=120
zmNumControls=003
zmProcedure=`zmMain`
zmFont=`DEFAULT`
zmTextColor=`DEFAULT`
zmBackground=`DEFAULT,DEFAULT`
zmConfig=0

zm001=`007,007,086,078,ITEMBOX,List,DEFAULT,DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`  ;lbxList
zm002=`007,097,036,012,PUSHBUTTON,DEFAULT,"OK",1,2,32,DEFAULT,DEFAULT,DEFAULT`          ;btnOk
zm003=`057,097,036,012,PUSHBUTTON,DEFAULT,"Cancel",0,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ; btnCancel

ButtonPushed=Dialog("zm")

Exit

Article ID:   W16917
File Created: 2007:07:03:14:27:04
Last Updated: 2007:07:03:14:27:04