Jump to content

Right-Click and Hover array values?


Burgs
 Share

Recommended Posts

I think NutStomper is on the right track.  Here's a version that uses GUIOnEventMode.  It detects hover, left click, and right click (and no WM_xx needed).  It doesn't catch every click, though, so I think something is a little "off" yet.  Anyway, here it is:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIScrollBars_Size.au3"

AutoItSetOption("GUIOnEventMode", 1)
AutoItSetOption("MustDeclareVars", 1)
Global Const $GUI_WIDTH = 768, $GUI_HEIGHT = 576, $HOVER_TIME = 1000
Global Const $BEACON_X = 0, $BEACON_Y = 1
Global $BEACON[1], $BEACON_TRAITS[1][1]
Global $MapBack, $TheMap, $MOUSE_ID

Initialize()
Main()

Func Initialize()

    ; Load reference file
    Local $_Reference = FileRead(@ScriptDir & "\BEACONS_55-47.txt")
    If @error Then
        MsgBox(16, "Error", "Cannot read BEACONS_55-47.txt" & @LF & "Aborting")
        Exit
    EndIf
    $_Reference = StringSplit(StringStripCR(StringStripWS($_Reference, 2)), @LF)
    If @error Then
        MsgBox(16, "Error", "Invalid BEACONS_55-47.txt" & @LF & "Aborting")
        Exit
    EndIf
    Dim $BEACON[$_Reference[0]]
    Dim $BEACON_TRAITS[$_Reference[0]][18]

    ; Build Loader GUI
    Local $hLoader = GUICreate("Loading Map...", 300, 100, Default, Default, $WS_BORDER)
    Local $hProgress = GUICtrlCreateProgress(20, 20, 260, 20)
    GUISetState(@SW_SHOW, $hLoader)

    ; Start building main GUI
    $MapBack = GUICreate("Map Selector", $GUI_WIDTH, $GUI_HEIGHT)
    GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_Exit")
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "GUI_Primary_Down")
    GUISetOnEvent($GUI_EVENT_PRIMARYUP, "GUI_Primary_Up")
    GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "GUI_Secondary_Down")
    GUISetOnEvent($GUI_EVENT_SECONDARYUP, "GUI_Secondary_Up")
    GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "GUI_Mouse_Move")
    GUISetBkColor(0xFFFFFF)
    Local $aRet = _GUIScrollbars_Size(2048, 2048, $GUI_WIDTH, $GUI_HEIGHT)
    GUIRegisterMsg($WM_HSCROLL, "_Scrollbars_WM_HSCROLL")
    GUIRegisterMsg($WM_VSCROLL, "_Scrollbars_WM_VSCROLL")
    _GUIScrollBars_Init($MapBack)
    _GUIScrollBars_SetScrollInfoPage($MapBack, $SB_HORZ, $aRet[0])
    _GUIScrollBars_SetScrollInfoMax($MapBack, $SB_HORZ, $aRet[1])
    _GUIScrollBars_SetScrollInfoPage($MapBack, $SB_VERT, $aRet[2])
    _GUIScrollBars_SetScrollInfoMax($MapBack, $SB_VERT, $aRet[3])
    GUISwitch($MapBack)
    $TheMap = GUICtrlCreatePic(@ScriptDir & "\HEXES-2048.jpg", 9, 0, 2048, 2048)
    GUICtrlSetState($TheMap, $GUI_DISABLE)

    ; Load main GUI elements
    Local $i, $x, $y, $temp
    For $i = 1 To $_Reference[0]
        $temp = StringSplit($_Reference[$i], ',', 2)
        $x = Number($temp[0])
        $y = Number($temp[1])
        $BEACON_TRAITS[$i - 1][$BEACON_X] = $x
        $BEACON_TRAITS[$i - 1][$BEACON_Y] = $y
        $BEACON[$i - 1] = GUICtrlCreatePic(@ScriptDir & "\Cross.gif", $x, $y, 11, 11)
        GUISwitch($hLoader)
        GUICtrlSetData($hProgress, 100 * $i / $_Reference[0])
        GUISwitch($MapBack)
    Next
    GUISetState(@SW_SHOW, $MapBack)
    GUISetState(@SW_HIDE, $hLoader)
EndFunc

Func Main()
;~  Local $CurrentID, $ShowingToolTip = False
;~  $timer = TimerInit()
    While 1
;~      ; Check hover events
;~      Local $CurrentID = GUIGetCursorInfo($MapBack)
;~      $CurrentID = $CurrentID[4]

;~      ; Still hovering - check hover time
;~      If $CurrentID == $MOUSE_ID Then
;~          If TimerDiff($timer) > $HOVER_TIME Then

;~              ; Do Hover Stuff, like...
;~              If Not $ShowingToolTip Then
;~                  ToolTip("ControlID of hover item:" & @LF & $CurrentID)
;~                  $ShowingToolTip = True
;~              EndIf
;~          EndIf

;~      ; Hovering over something else - reset timer
;~      Else
;~          If $ShowingToolTip Then
;~              $CurrentID = $MOUSE_ID
;~              ToolTip("")
;~              $ShowingToolTip = False
;~          EndIf
;~          $timer = TimerInit()
;~      EndIf
        ; Sleep because GUIOnEventMode is NOT a blocking function like GUIGetMsg
        Sleep(10)
    WEnd
EndFunc

Func GUI_Exit()
    Exit
EndFunc

Func GUI_Primary_Down()
    $MOUSE_ID = GUIGetCursorInfo($MapBack)
    $MOUSE_ID = $MOUSE_ID[4]
EndFunc

Func GUI_Primary_Up()
    Local $CurrentID = GUIGetCursorInfo($MapBack)
    $CurrentID = $CurrentID[4]
    If $CurrentID == $MOUSE_ID Then

        ; Left Click Stuff
        ConsoleWrite("Left click on ControlID " & $CurrentID & @LF)

    EndIf
EndFunc

Func GUI_Secondary_Down()
    $MOUSE_ID = GUIGetCursorInfo($MapBack)
    $MOUSE_ID = $MOUSE_ID[4]
EndFunc

Func GUI_Secondary_Up()
    Local $CurrentID = GUIGetCursorInfo($MapBack)
    $CurrentID = $CurrentID[4]
    If $CurrentID == $MOUSE_ID Then

        ; Right Click Stuff
        ConsoleWrite("Right click on ControlID " & $CurrentID & @LF)

    EndIf
EndFunc

Func GUI_Mouse_Move()
    $MOUSE_ID = GUIGetCursorInfo($MapBack)
    $MOUSE_ID = $MOUSE_ID[4]
EndFunc

; ////////////////////////////////////////////////

Func _Scrollbars_WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)

    #forceref $Msg, $wParam, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $iIndex = -1, $yChar, $yPos
    Local $Min, $Max, $Page, $Pos, $TrackPos

    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $iIndex = $x
            $yChar = $aSB_WindowInfo[$iIndex][3]
            ExitLoop
        EndIf
    Next
    If $iIndex = -1 Then Return 0

    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
    $Min = DllStructGetData($tSCROLLINFO, "nMin")
    $Max = DllStructGetData($tSCROLLINFO, "nMax")
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    $yPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $yPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")

    Switch $nScrollCode
        Case $SB_TOP
            DllStructSetData($tSCROLLINFO, "nPos", $Min)
        Case $SB_BOTTOM
            DllStructSetData($tSCROLLINFO, "nPos", $Max)
        Case $SB_LINEUP
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
        Case $SB_LINEDOWN
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
        Case $SB_PAGEUP
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
        Case $SB_PAGEDOWN
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
        Case $SB_THUMBTRACK
            DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
    EndSwitch

    DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)

    $Pos = DllStructGetData($tSCROLLINFO, "nPos")
    If ($Pos <> $yPos) Then
        _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
        $yPos = $Pos
    EndIf

    Return $GUI_RUNDEFMSG

EndFunc   ;==>_Scrollbars_WM_VSCROLL

Func _Scrollbars_WM_HSCROLL($hWnd, $Msg, $wParam, $lParam)

    #forceref $Msg, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $iIndex = -1, $xChar, $xPos
    Local $Page, $Pos, $TrackPos

    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $iIndex = $x
            $xChar = $aSB_WindowInfo[$iIndex][2]
            ExitLoop
        EndIf
    Next
    If $iIndex = -1 Then Return 0

    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ)
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    $xPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $xPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
    Switch $nScrollCode
        Case $SB_LINELEFT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
        Case $SB_LINERIGHT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
        Case $SB_PAGELEFT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
        Case $SB_PAGERIGHT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
        Case $SB_THUMBTRACK
            DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
    EndSwitch

    DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
    _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)

    $Pos = DllStructGetData($tSCROLLINFO, "nPos")
    If ($Pos <> $xPos) Then _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0)

    Return $GUI_RUNDEFMSG

EndFunc   ;==>_Scrollbars_WM_HSCROLL

EDIT - I used both $GUI_EVENT_PRIMARYDOWN and $GUI_EVENT_PRIMARYUP so that the event doesn't fire if the user clicks on something but moves the mouse off it before releasing.  Same for $GUI_EVENT_SECONDARYDOWN/UP.  I did try commenting out the If/EndIf in the GUI_Primary_Up() and GUI_Secondary_Up() functions to see if that improved performance, and it did not.
 
EDIT 2 - The help file will tell you to use @GUI_CtrlId in the event functions, but that's useless here.  It only tells you what event called the function (ie. $GUI_EVENT_PRIMARYDOWN) and not what ControlID was associated with it.  That's why I used GUIGetCursorInfo() to look it up.

EDIT 3 - It's the Hover stuff that's lagging the left/right click detection. I commented it out, and everything works flawlessly. No idea yet how to make them play nice.

Edited by Artisan
Link to comment
Share on other sites

Yikes that's a kinda significant re-write from what I had before...

Thanks Artisan for your time and help with this...I need to play with this a bit and see what I can see...never used the GUIOnEventMode before so I have to get more familiar with it.  Thanks again!

Regards.

Link to comment
Share on other sites

You're quite welcome.  It was a good challenge for me.  :)

Yeah, get to know GUIOnEventMode before you try to mess with this.  GUIOnEventMode always makes for a fairly significant rewrite when you switch to it.  I haven't used it a ton, but I try to avoid it when I can.  I really hope that someone can help figure out why the Hover part is killing the other events, though.  You'd think that it would be fairly simple to know when a user Left clicks, Right clicks, or Hovers on a given control...

Link to comment
Share on other sites

Yea that's what I would have thought...I find that very frustrating that something so basic requires such a large 'end run' work-around.  I have always avoided it as well, which is why this is the first time I will use it. 

You used "GUISetOnEvent" instead of "GUICtrlSetOnEvent" so as to register all clicks (right/left) in the window regardless if on a control or not, and then determine if a control was clicked with the GUIGetCursorInfo info, correct? 

That kinda brings me full circle back to my original problem whereby the Control ID for the clicked control will be returned rather than the array index # of that control, however as I stated earlier I guess I can get around that by getting the control handle and comparing it to an array of saved handles...  

Thanks again.

Link to comment
Share on other sites

You used "GUISetOnEvent" instead of "GUICtrlSetOnEvent" so as to register all clicks (right/left) in the window regardless if on a control or not, and then determine if a control was clicked with the GUIGetCursorInfo info, correct?

That's right.  GUICtrlSetOnEvent will not catch right-clicks, so I had to register all window clicks.

 

That kinda brings me full circle back to my original problem whereby the Control ID for the clicked control will be returned rather than the array index # of that control, however as I stated earlier I guess I can get around that by getting the control handle and comparing it to an array of saved handles...

There's a couple ways to deal with that.

  • What you said, loop through the array looking for a match each time the event occurs.  It's easy to code and understand, but may degrade performance.
  • Create an array whose index is the ControlID and has a stored value of the $BEACON index number. (Example below.)  It takes a little more effort on your part, and it causes your script to consume a little more memory, but getting the index will be faster.  (Noticeably faster?  Hard to say.)
  • Cheat.  You're in control of making all your controls, and you're not destroying any controls (are you?) and they're all assigned a sequential number.  It just happens to be that your $BEACON index = ControlID - 5.  (This may change if you change the code, but otherwise is static.)  Again, this isn't the best technical solution, but it should work.

Example of #2:

...
Global $BEACON[1], $BEACON_TRAITS[1][1], $BEACON_ID_TO_ARRAY[1]
...

        $BEACON_TRAITS[$i - 1][$BEACON_X] = $x
        $BEACON_TRAITS[$i - 1][$BEACON_Y] = $y
        $BEACON[$i - 1] = GUICtrlCreatePic(@ScriptDir & "\Cross.gif", $x, $y, 11, 11)
        If $BEACON[$i - 1] >= UBound($BEACON_ID_TO_ARRAY) Then ReDim $BEACON_ID_TO_ARRAY[$BEACON[$i - 1] + 1]
        $BEACON_ID_TO_ARRAY[$BEACON[$i - 1]] = $i - 1
...
Func GUI_Primary_Up()
    Local $CurrentID = GUIGetCursorInfo($MapBack)
    $CurrentID = $CurrentID[4]
;~  If $CurrentID == $MOUSE_ID Then

        ; Left Click Stuff
        ConsoleWrite("Left click on ControlID " & $CurrentID & @LF)
        ConsoleWrite("$BEACON array index " & $BEACON_ID_TO_ARRAY[$CurrentID] & @LF)

;~  EndIf
EndFunc
Edited by Artisan
Link to comment
Share on other sites

Greetings again,

  Thanks for the info about determining the correct array index #...nice that there's a couple of different options on how to do that.

  I finally found some time to try this new alternative method...and I'm having a problem.  The mouse clicks are not being registered at all.  I believe the reason is that I am using it in an interface with multiple GUI (child) windows...seems to work fine in the example you gave however that was only 1 window.  How would I modify the code to account for which window the 'click' was generated in like the GUIGetMsg command can be set to do?  Since you are setting the 'CurrentID' variable to record the mouse cursor information of only 1 window (MapBack)...how would I go about picking up a click(s) in different GUI windows?  I have a sinking feeling that it is not possible to do it for multiple windows...Thanks again in advance. 

Link to comment
Share on other sites

You can still use the event functions to catch everything, and you look at @GUI_WINHANDLE to know which window made the call (compare it to $hLoader or $MapBack or whatever), then you respond based on that.  It's probably simplest to just use "Switch @GUI_WINHANDLE" with Case statements for each window, then throw your Action-to-take code (or related function) under that.
 
Here's an example that I modified from the helpfile on GUICtrlSetOnEvent.  The change is only to put the window handle in its title so you can compare it when you click stuff.

#include <GUIConstantsEx.au3>

Example()

Func Example()
    Opt("GUICoordMode", 2)
    Opt("GUIResizeMode", 1)
    Opt("GUIOnEventMode", 1)

    $hwnd = GUICreate("Parent1")
    WinSetTitle($hwnd, "", "Parent1 $hwnd=" & $hwnd)
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
    GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

    GUICtrlCreateButton("OK", 10, 30, 50)
    GUICtrlSetOnEvent(-1, "OKPressed")

    GUICtrlCreateButton("Cancel", 0, -1)
    GUICtrlSetOnEvent(-1, "CancelPressed")

    GUISetState(@SW_SHOW)

    ; Just idle around
    While 1
        Sleep(10)
    WEnd

EndFunc   ;==>Example


Func OKPressed()
    MsgBox(0, "OK Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
EndFunc   ;==>OKPressed


Func CancelPressed()
    MsgBox(0, "Cancel Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
EndFunc   ;==>CancelPressed


Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            MsgBox(0, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
            Exit

        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
            MsgBox(0, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)

        Case @GUI_CtrlId = $GUI_EVENT_RESTORE
            MsgBox(0, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)

    EndSelect
EndFunc   ;==>SpecialEvents
Link to comment
Share on other sites

Greets,

  I've been playing with this some more...as mentioned I'm using multiple windows in my interface, for example:

Global $MainGUI = GUICreate("Main Window", 994, 712)
 GUISetState(@SW_SHOW) 

...


 $MapBack = GUICreate("The Map Back", 728, 544, 0, 28, $WS_CHILD, $WS_EX_CLIENTEDGE, $MainGUI)

  It seems the "$WS_CHILD" is causing a problem...when I have that parameter set the 'clicks' are all completely unresponsive...I can get around that by changing it to "$WS_POPUP" and then fiddling with the window positioning to create the same look...and the 'clicks' WILL be responsive, however then I don't have the "MapBack" window truely embedded in the "Main" window...the user can 'seperate' the windows by dragging the "Main" window around by its titlebar...I have no idea how to get around that.  The last parameter for 'parent window' doesn't seem to do anything, nothing seems different if I include or not...? 

  In addition I don't think I can setup the 'Event' functions in the way you mentioned before because I have to define them for each window, correct?  The Help File states (for GUISetOnEvent last parameter) "Windows handle as returned by GUICreate (default is the previously used window)."  Thus I think I need to write the GUISetOnEvent commands and associated functions as I create each window in the overall interface, that's no big deal I just thought I'd mention it...that also provides a way to identify which window is sending the 'click' call.  Thanks again, regards. 

 

Link to comment
Share on other sites

  • 2 weeks later...

Sorry for the long delay - I was out of town for a while.  Anyway, here's a proof of concept:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIScrollBars_Size.au3"

AutoItSetOption("GUIOnEventMode", 1)
AutoItSetOption("MustDeclareVars", 1)

Global Const $HOVER_TIME = 1000, $CHILD_1_WIDTH = 200, $CHILD_1_HEIGHT = 200, $CHILD_1_X = 110, $CHILD_1_Y = 30
Global Const $BeaconX = 9, $BeaconY = 9
Global $hGUI_Parent, $hP_Button
Global $hGUI_Child_1, $hC1_Pic[$BeaconX][$BeaconY]
Global $hGUI_Child_2
Global $hGUI_Child_3
Global $HoverTimer, $MouseX, $MouseY, $MouseID, $hGUI_Active

Initialize()
Main()

Func Initialize()

    ; Parent GUI
    $hGUI_Parent = GUICreate("Parent", 600, 600, Default, Default, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_CLIPCHILDREN))
    $hP_Button = GUICtrlCreateButton(" Don't Click Me! ", 10, 10)
    GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_Exit")
    GUISetOnEvent($GUI_EVENT_PRIMARYUP, "GUI_Left")
    GUISetOnEvent($GUI_EVENT_SECONDARYUP, "GUI_Right")
    GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "GUI_Move")
    GUISetState(@SW_SHOW, $hGUI_Parent)

    ; Child 1 GUI
    $hGUI_Child_1 = GUICreate("Child 1", $CHILD_1_WIDTH, $CHILD_1_HEIGHT, $CHILD_1_X, $CHILD_1_Y, BitOR($WS_CHILD, $WS_CLIPSIBLINGS), $WS_EX_CLIENTEDGE, $hGUI_Parent)
    GUISetBkColor(0x7070FF, $hGUI_Child_1)
    Local $x, $y
    For $y = 0 To $BeaconY - 1
        For $x = 0 To $BeaconX - 1
            $hC1_Pic[$x][$y] = GUICtrlCreatePic("Cross.gif", $x * 75 + 20, $y * 75 + 20, 11, 11)
        Next
    Next
    Local $aRet = _GUIScrollbars_Size(2048, 2048, $CHILD_1_WIDTH, $CHILD_1_HEIGHT)
    GUIRegisterMsg($WM_HSCROLL, "_Scrollbars_WM_HSCROLL")
    GUIRegisterMsg($WM_VSCROLL, "_Scrollbars_WM_VSCROLL")
    _GUIScrollBars_Init($hGUI_Child_1)
    _GUIScrollBars_SetScrollInfoPage($hGUI_Child_1, $SB_HORZ, $aRet[0])
    _GUIScrollBars_SetScrollInfoMax($hGUI_Child_1, $SB_HORZ, $aRet[1])
    _GUIScrollBars_SetScrollInfoPage($hGUI_Child_1, $SB_VERT, $aRet[2])
    _GUIScrollBars_SetScrollInfoMax($hGUI_Child_1, $SB_VERT, $aRet[3])

    ; Child 2 GUI
    ; ***

    ; Child 3 GUI
    ; ***

    GUISetState(@SW_SHOW, $hGUI_Child_1)
    ; ***

    $hGUI_Active = False
    $MouseID = 0
    GUI_Move()
EndFunc

Func Main()
    While 1
        If TimerDiff($HoverTimer) > $HOVER_TIME Then
            If $MouseID >= $hC1_Pic[0][0] And $MouseID <= $hC1_Pic[$BeaconX - 1][$BeaconY - 1] Then
                ToolTip("ID: " & $MouseID & @LF & "Index: " & MouseIDtoIndex())
            Else
                ToolTip("Window: " & $hGUI_Active & @LF & $MouseX & ", " & $MouseY & @LF & "ID: " & $MouseID)
            EndIf
        EndIf
        Sleep(100)
    WEnd
EndFunc

Func MouseIDtoIndex()
    Local $x, $y
    $x = Mod($MouseID - $hC1_Pic[0][0], $BeaconX)
    $y = Floor(($MouseID  - $hC1_Pic[0][0])/ $BeaconY)
    Return "[" & $x & "][" & $y & "]"
EndFunc

Func GUI_Exit()
    Exit
EndFunc

Func GUI_Left()
    ConsoleWrite(@LF & "Window: " & $hGUI_Active & @LF & "Left click on ControlID " & $MouseID & @LF)
    ; *** Give index to Child image
EndFunc

Func GUI_Right()
    ConsoleWrite(@LF & "Window: " & $hGUI_Active & @LF & "Right click on ControlID " & $MouseID & @LF)
    ; *** Give index to Child image
EndFunc

Func GUI_Move()
    Local $temp = GUIGetCursorInfo($hGUI_Parent)
    $MouseX = $temp[0]
    $MouseY = $temp[1]
    If $MouseX >= $CHILD_1_X And $MouseX <= $CHILD_1_X + $CHILD_1_WIDTH And $MouseY >= $CHILD_1_Y And $MouseY <= $CHILD_1_Y + $CHILD_1_HEIGHT Then
        $hGUI_Active = "Child 1"
    Else
        $hGUI_Active = "Parent"
    EndIf
    If $temp[4] <> $MouseID Then
        $MouseID = $temp[4]
        $HoverTimer = TimerInit()
        ToolTip("")
    EndIf
EndFunc

; ////////////////////////////////////////////////

Func _Scrollbars_WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)

    #forceref $Msg, $wParam, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $iIndex = -1, $yChar, $yPos
    Local $Min, $Max, $Page, $Pos, $TrackPos

    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $iIndex = $x
            $yChar = $aSB_WindowInfo[$iIndex][3]
            ExitLoop
        EndIf
    Next
    If $iIndex = -1 Then Return 0

    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
    $Min = DllStructGetData($tSCROLLINFO, "nMin")
    $Max = DllStructGetData($tSCROLLINFO, "nMax")
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    $yPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $yPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")

    Switch $nScrollCode
        Case $SB_TOP
            DllStructSetData($tSCROLLINFO, "nPos", $Min)
        Case $SB_BOTTOM
            DllStructSetData($tSCROLLINFO, "nPos", $Max)
        Case $SB_LINEUP
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
        Case $SB_LINEDOWN
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
        Case $SB_PAGEUP
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
        Case $SB_PAGEDOWN
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
        Case $SB_THUMBTRACK
            DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
    EndSwitch

    DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)

    $Pos = DllStructGetData($tSCROLLINFO, "nPos")
    If ($Pos <> $yPos) Then
        _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
        $yPos = $Pos
    EndIf

    Return $GUI_RUNDEFMSG

EndFunc   ;==>_Scrollbars_WM_VSCROLL

Func _Scrollbars_WM_HSCROLL($hWnd, $Msg, $wParam, $lParam)

    #forceref $Msg, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $iIndex = -1, $xChar, $xPos
    Local $Page, $Pos, $TrackPos

    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $iIndex = $x
            $xChar = $aSB_WindowInfo[$iIndex][2]
            ExitLoop
        EndIf
    Next
    If $iIndex = -1 Then Return 0

    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ)
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    $xPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $xPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
    Switch $nScrollCode
        Case $SB_LINELEFT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
        Case $SB_LINERIGHT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
        Case $SB_PAGELEFT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
        Case $SB_PAGERIGHT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
        Case $SB_THUMBTRACK
            DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
    EndSwitch

    DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
    _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)

    $Pos = DllStructGetData($tSCROLLINFO, "nPos")
    If ($Pos <> $xPos) Then _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0)

    Return $GUI_RUNDEFMSG

EndFunc   ;==>_Scrollbars_WM_HSCROLL

It uses scrollbars and your Cross.gif image. Note that the coords it gives on hover are always the parent's coords. You can get the child's coords, but it ignores the scrollbars. I'm sure there's a way around that, but I didn't look into it. I don't even know if that's important or not. Finally, when you hover over a beacon, it will give you both the ControlID and the x/y index of the control.

I used the "Cheat" method to get the x/y index of the beacons, mostly out of laziness, but you can easily adapt it to the other methods.  Also, the only way to "know" what window you're over is to look at the coords of the parent window and compare it to where you actually put the child windows.  Which reminds me - I meant to add in two more child windows for fun.  Oops.  Oh well.

Enjoy.   :)

Edited by Artisan
Link to comment
Share on other sites

Thanks again for all your input...I will work this into my code re-write in the next few days when I have the time...much appreciated.  I do have a question however...can you explain this line (from an earlier post) a lil bit?  

$_Reference = StringSplit(StringStripCR(StringStripWS($_Reference, 2)), @LF)

  It appears you are splitting the earlier read line of text for the '$_Reference' variable however stripping out the whitespace and line returns...why do you have the  "@LF" in there?  Just a bit confusing with the nesting...not sure how you are accomplishing the entire fileread sequence, but it works so neatly and with minimal code I want to understand it better...thanks again...!

Edited by Burgs
Link to comment
Share on other sites

  • 2 weeks later...

Hey Burgs, I could have sworn I answered your question last week, but it seems my post didn't actually get posted.  Weird.  Anyway, I've split that line into 3 lines for easier reading:

$_Reference = StringStripWS($_Reference, 2)
$_Reference = StringStripCR($_Reference)
$_Reference = StringSplit($_Reference, @LF)

Line 1 = Strip any trailing whitespace.  Your .txt file has a @CRLF (Carriage Return & Line Feed) at the end of it, which would mess with what I want to do (it would add an extra [empty] item to the array in Line 3).  There's lots of ways to take it out, and I chose StringStripWS.

Line 2 = Strip all @CR characters.  In Windows, all "Enter" keys are @CRLF, and in Unix/Linux they're just @LF.  This function removes all @CR characters from a string.  Again, this is to prepare it for what I want to do later.  Line 1 & Line 2 can happen in any order.

Line 3 = Split the string into an array. The @LF marks where to split the string.  This results in $_Reference holding an array where each line is a separate item in the array.  Later, I use StringSplit on each item in $_Reference (splitting at every comma) to get the individual values to load into the program (look for $temp).

Edited by Artisan
Link to comment
Share on other sites

Thanks again for your help and that explanation...that makes sense.  I'll be done soon with the re-write I had to do regarding this...so far so good, haven't run into any problems as yet.  

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...