Jump to content

Drawing Graphic Boxes over DLLCall


Recommended Posts

Hi All, 

I am trying to mark out the middle square of this Magnify Routine "window on right" (stolen from M23 - Thanks) - I assume the DllCall is overwriting the boxes. But wherever I try and redraw, they won't stay on the Magnify Window. Can anyone advise, bet way to keep boxes around the middle square.

Please be kind with my code, it is ripped from a MUCH bigger exe.

The "half" transparent window, is for dragging to where you want it, and the buttons are for more precise placement.

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

Global $hMag_GUI, $hMagDC, $hDeskDC, $hPen, $oObj, $aWinPos[2], $iLast_Mouse_X = 0, $iLast_Mouse_Y = 0
Global $pWindowCaptureX, $pWindowCaptureY
Global $pWindowMagWinX, $pWindowMagWinY

#Region - GUI3
    ; *** Grabber/Picker Window
    Global $hGUI3 = GUICreate("Capture", 150, 150, $pWindowCaptureX, $pWindowCaptureY, $WS_EX_TOOLWINDOW)
    Global $Pic1 = GUICtrlCreatePic("", 70, 40, 10, 10, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER))
    Global $hButtonUp = GUICtrlCreateButton("U", 65, 60, 20, 20)
    Global $hButtonDown = GUICtrlCreateButton("D", 65, 100, 20, 20)
    Global $hButtonLeft = GUICtrlCreateButton("L", 40, 80, 20, 20)
    Global $hButtonRight = GUICtrlCreateButton("R", 90, 80, 20, 20)
    Global $hButtonOK = GUICtrlCreateButton("OK", 60, 80, 30, 20)
#EndRegion - GUI3
#Region - GUI4
    Global $hGUI4 = GUICreate("MagWin", 250, 250, 325, 195)
    Global $hButtonMOK = GUICtrlCreateButton("OK", 45, 140, 30, 20)
    Global $hButtonMUp = GUICtrlCreateButton("U", 50, 120, 20, 20)
    Global $hButtonMDown = GUICtrlCreateButton("D", 50, 160, 20, 20)
    Global $hButtonMLeft = GUICtrlCreateButton("L", 25, 140, 20, 20)
    Global $hButtonMRight = GUICtrlCreateButton("R", 75, 140, 20, 20)
    Global $hLabelWindow = GUICtrlCreateLabel("Window", 5, 185, 44, 15)
    Global $hLabelWindowText = GUICtrlCreateLabel("", 60, 185, 176, 15)
    Global $hLabelCheck = GUICtrlCreateLabel("Check", 5, 205, 44, 15)
    Global $hLabelCheckText = GUICtrlCreateLabel("", 60, 205, 176, 15)
    Global $hLabelScreen = GUICtrlCreateLabel("Screen", 5, 225, 44, 15)
    Global $hLabelScreenText = GUICtrlCreateLabel("", 60, 225, 176, 15)
#EndRegion - GUI4

    ;GUISetState(@SW_HIDE, $hGUI1)
    GUISetState(@SW_SHOW, $hGUI3)
    GUISetState(@SW_SHOW, $hGUI4)
    WinSetTrans($hGUI3, "", 100)
    $hMag_GUI = WinGetHandle("MagWin")
    ; Get device context for Mag GUI
    $hMagDC = _WinAPI_GetDC($hMag_GUI)
    If @error Then Exit
    ; Get device context for desktop
    $hDeskDC = _WinAPI_GetDC(0)
    If @error Then
        _WinAPI_ReleaseDC($hMag_GUI, $hMagDC)
        Exit
    EndIf
    ; Create pen
    $hPen = _WinAPI_CreatePen($PS_SOLID, 5, 0x7E7E7E)
    $oObj = _WinAPI_SelectObject($hMagDC, $hPen)
        ; Loop until the user exits.

; *** Static Window
        While 1
            ; Reset position
            Local $aWinPos = WinGetPos("Capture")
            If $aWinPos[0] <> $iLast_Mouse_X Or $aWinPos[1] <> $iLast_Mouse_Y Then
                ; Redraw Mag GUI
                _FOEA_Loupe($aWinPos)
;~                  Local $TWPx = $aWinPos[0]+81  ;+81 Top Left Corner; +85 Middle
;~                  Local $TWPy = $aWinPos[1]+75  ;+75 Top Left Corner; +80 Middle
;~                  ;*** WINDOW COORDS = x+81 & y+75 (top left of picker square)

GUISetState(@SW_HIDE, $hGUI3)
                Local $output1 = PixelCheckSum($aWinPos[0]+81, $aWinPos[1]+75, $aWinPos[0]+91, $aWinPos[1]+85)
                Local $output2 = PixelCheckSum($aWinPos[0]+73, $aWinPos[1]+66, $aWinPos[0]+83, $aWinPos[1]+76)
                If $aWinPos[0] < 1440 Then
                    GUICtrlSetData($hLabelWindowText, $aWinPos[0]+81 & "(" & $aWinPos[0]+81+1440 &")," & $aWinPos[1]+75 & " : " & $output1)
                    GUICtrlSetData($hLabelCheckText, $aWinPos[0]+73 & "(" & $aWinPos[0]+73+1440 & ")," & $aWinPos[1]+66 & " : " & $output2)
                    GUICtrlSetData($hLabelScreenText, "W: " & $aWinPos[0]+73 & "(" & $aWinPos[0]+73+1440 &")," & $aWinPos[1]+66 & "  C: " & $aWinPos[0]+81 & "," & $aWinPos[1]+75)
                Else
                    GUICtrlSetData($hLabelWindowText, $aWinPos[0]+81-1440 & "(" & $aWinPos[0]+81 &")," & $aWinPos[1]+75 & " : " & $output1)
                    GUICtrlSetData($hLabelCheckText, $aWinPos[0]+89-1440 & "(" & $aWinPos[0]+89 &")," & $aWinPos[1]+84 & " : " & $output2)
                    GUICtrlSetData($hLabelScreenText, "W: " & $aWinPos[0]+73-1440 & "(" & $aWinPos[0]+73 & ")," & $aWinPos[1]+66 & "  C: " & $aWinPos[0]+81 & "," & $aWinPos[1]+75)
                ;GUICtrlSetData($hLabel2, $aWinPos[1]+75)
                EndIf
GUISetState(@SW_SHOW, $hGUI3)
                $iLast_Mouse_X = $aWinPos[0]
                $iLast_Mouse_Y = $aWinPos[1]
                $pWindowCaptureX = $aWinPos[0]
                $pWindowCaptureY = $aWinPos[1]
                ; *** Box ; Tried it here - doesn't work
;~              Global $Graphic = GUICtrlCreateGraphic(176, 55, 2, 20)
;~              Global $Graphic = GUICtrlCreateGraphic(194, 55, 2, 20)
;~              Global $Graphic = GUICtrlCreateGraphic(176, 55, 20, 2)
;~              Global $Graphic = GUICtrlCreateGraphic(176, 73, 20, 2)
;~              Global $Graphic = GUICtrlCreateGraphic(0, 0, 1, 1)
            EndIf

            Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                    Local $aWinPos = WinGetPos("MagWin")
                    $pWindowMagWinX = $aWinPos[0]
                    $pWindowMagWinY = $aWinPos[1]
                    ;GUISetState(@SW_HIDE, $hGUI3)
                    GUIDelete($hGUI3)
                    ; Clear up Mag GUI
                    _WinAPI_SelectObject($hMagDC, $oObj)
                    _WinAPI_DeleteObject($hPen)
                    _WinAPI_ReleaseDC(0, $hDeskDC)
                    _WinAPI_ReleaseDC($hMag_GUI, $hMagDC)
                    ;GUISetState(@SW_HIDE, $hMag_G
                    GUIDelete($hGUI4)
                    GUIDelete($hMag_GUI)
                    ExitLoop

                Case $hButtonMOK
                    GUISetState(@SW_HIDE, $hGUI3)
                    Local $aWinPos = WinGetPos("Capture")
                    Local $TWPx = $aWinPos[0]+81  ;+81 Top Left Corner; +85 Middle
                    Local $TWPy = $aWinPos[1]+75  ;+75 Top Left Corner; +80 Middle
                    ;*** WINDOW COORDS = x+81 & y+75 (top left of picker square)

                    If $aWinPos[0] > 1440 Then
                        $aWinPos[0] = $aWinPos[0]-1440
                        $TWPx = $TWPx-1440
                    EndIf

                    Local $output0 = PixelCheckSum($TWPx-8, $TWPy-9, $TWPx-8+10, $TWPy+1)
                    ;_FOEA_WinAPI_DrawRect(LRChecksum($TWPx-8), $TWPy-9, LRChecksum($TWPx-8)+10, $TWPy+1, 0xFFFFFF, 50)
                    MsgBox($MB_SYSTEMMODAL, "Results ", _
                    "Window Coords" & @CRLF & _
                    $TWPx & "(" & $TWPx+1440 & "), " & $TWPy  & @CRLF & _
                    "Checksum0: " & $output0 & @CRLF)
                    GUISetState(@SW_SHOW, $hGUI3)
                    WinActivate($hGUI3, "Capture")

                Case $hButtonMUp
                    _FOEA_ButtonMUp()

                Case $hButtonMDown
                    _FOEA_ButtonMDown()

                Case $hButtonMRight
                    _FOEA_ButtonMRight()

                Case $hButtonMLeft
                    _FOEA_ButtonMLeft()
            EndSwitch
        WEnd


Func _FOEA_Loupe($aWinPos)
    Local $iX, $iY
    DllCall("gdi32.dll", "int", "StretchBlt", _
    "int", $hMagDC,  "int", 10,                   "int", 10,                   "int", 110, "int", 110, _
    "int", $hDeskDC, "int", $aWinPos[0]+68, "int", $aWinPos[1]+61, "int", 20, "int", 20, _
    "long", $SRCCOPY)
    DllCall("gdi32.dll", "int", "StretchBlt", _
    "int", $hMagDC,  "int", 130,                   "int", 10,                   "int", 110, "int", 110, _
    "int", $hDeskDC, "int", $aWinPos[0]+70, "int", $aWinPos[1]+63, "int", 7, "int", 7, _
    "long", $SRCCOPY)
    ; Appears initially - then disappears...
    Global $Graph1 = GUICtrlCreateGraphic(170, 57, 8, 16, $SS_WHITERECT)
    Global $Graph2 = GUICtrlCreateGraphic(170, 73, 31, 8, $SS_WHITERECT)
    Global $Graph3 = GUICtrlCreateGraphic(193, 57, 8, 16, $SS_WHITERECT)
    Global $Graph4 = GUICtrlCreateGraphic(170, 49, 31, 8, $SS_WHITERECT)
    ; This apears to be needed to stop the Magnify window moving
    Global $Graph5 = GUICtrlCreateGraphic(0, 0, 1, 1)
    ;Tried this too - no difference
    GUISetState(@SW_SHOW, $Graph1)
    GUISetState(@SW_SHOW, $Graph2)
    GUISetState(@SW_SHOW, $Graph3)
    GUISetState(@SW_SHOW, $Graph4)
EndFunc   ;==>Loupe

Func _FOEA_ButtonMUp()
    Local $aWinPos = WinGetPos("Capture")
    WinMove($hGUI3, "Capture", $aWinPos[0], $aWinPos[1]-1)
EndFunc

Func _FOEA_ButtonMDown()
    Local $aWinPos = WinGetPos("Capture")
    WinMove($hGUI3, "Capture", $aWinPos[0], $aWinPos[1]+1)
EndFunc

Func _FOEA_ButtonMRight()
    Local $aWinPos = WinGetPos("Capture")
    WinMove($hGUI3, "Capture", $aWinPos[0]+1, $aWinPos[1])
EndFunc

Func _FOEA_ButtonMLeft()
    Local $aWinPos = WinGetPos("Capture")
    WinMove($hGUI3, "Capture", $aWinPos[0]-1, $aWinPos[1])
EndFunc

 

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

×
×
  • Create New...