Jump to content

Gui Styles Help


Jags
 Share

Recommended Posts

Trying to make a Gui thats transparent, sizable, draggable, thin or no border and no text or other controls that would interfere with transparency.  In the end I want a simple, adjustable, movable shape used to highlight certain screen areas.

 

So far I have:

$myBox = GUICreate("", 200, 300, 100, 500, BitOR($WS_SIZEBOX,$WS_SYSMENU,$WS_POPUP), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))

It is missing a simple drag ability and would like to remove the border.

 

Thanks in advance,
Link to comment
Share on other sites

  • Moderators

Jags,

Perhaps this old code of mine will fit the bill:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <ScreenCapture.au3>

Global $hCapture_GUI
; Set distance from edge of Capture_GUI where resizing is possible
Global Const $iMargin = 4
; Set max and min Capture_GUI sizes
Global Const $iGUIMinX = 50, $iGUIMinY = 50, $iGUIMaxX = @DesktopWidth - 100, $iGUIMaxY = @DesktopHeight - 100

_Main()

Func _Main()

    Local $sJPG_Path = @ScriptDir & "\test.jpg"
    ConsoleWrite($sJPG_Path & @CRLF)

    ; Create GUI
    Local $hMain_GUI = GUICreate("Select Rectangle", 240, 50)

    Local $cRect_Button = GUICtrlCreateButton("Mark Area", 10, 10, 80, 30)
    Local $cCancel_Button = GUICtrlCreateButton("Cancel", 150, 10, 80, 30)

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $cCancel_Button
                FileDelete($sJPG_Path)
                Exit
            Case $cRect_Button
                GUISetState(@SW_HIDE, $hMain_GUI)
                Local $aCoords = Mark_Rect()
                ; Capture selected area
                _ScreenCapture_Capture($sJPG_Path, $aCoords[0], $aCoords[1], $aCoords[0] + $aCoords[2], $aCoords[1] + $aCoords[3], False)
                GUISetState(@SW_SHOW, $hMain_GUI)
                ; Display image
                GUICreate("Selected Rectangle", $aCoords[2], $aCoords[3], 100, 100)
                GUICtrlCreatePic($sJPG_Path, 0, 0, $aCoords[2], $aCoords[3])
                GUISetState()
        EndSwitch
    WEnd

EndFunc   ;==>_Main

; -------------

Func Mark_Rect()

    ; Create capture GUI
    $hCapture_GUI = GUICreate("Y", 100, 100, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUISetBkColor(0xABCDEF)

    ; Create label for dragging
    Local $cLabel = GUICtrlCreateLabel("", $iMargin * 2, $iMargin * 2, 100 - ($iMargin * 4), 100 - ($iMargin * 4), -1, $GUI_WS_EX_PARENTDRAG)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

    ; Create context menu
    Local $cContextMenu = GUICtrlCreateContextMenu($cLabel)
    $cContext_Capture = GUICtrlCreateMenuItem("Capture", $cContextMenu)
    $cContext_Cancel = GUICtrlCreateMenuItem("Cancel", $cContextMenu)

    ; Hide GUI
    _WinAPI_SetLayeredWindowAttributes($hCapture_GUI, 0xABCDEF, 250)

    GUISetState()

    ; Set transparency level
    WinSetTrans($hCapture_GUI, "", 100)

    ; Register message handlers
    GUIRegisterMsg($WM_MOUSEMOVE, "_SetCursor") ; For cursor type change
    GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") ; For resize/drag
    GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; For GUI size limits

    While 1

        Switch GUIGetMsg()
            Case $cContext_Capture
                ; Get GUI position and delete
                $aPos = WinGetPos($hCapture_GUI)
                GUIDelete($hCapture_GUI)
                ; Unregister message handlers
                GUIRegisterMsg($WM_MOUSEMOVE, "")
                GUIRegisterMsg($WM_LBUTTONDOWN, "")
                GUIRegisterMsg($WM_GETMINMAXINFO, "")
                ; Peturn position
                Return $aPos
            Case $cContext_Cancel
                Exit
        EndSwitch
    WEnd

EndFunc   ;==>Mark_Rect

; Set cursor to correct resizing form if mouse is over a border
Func _SetCursor()
    Local $iCursorID
    Switch _Check_Border()
        Case 0
            $iCursorID = 2
        Case 1, 2
            $iCursorID = 13
        Case 3, 6
            $iCursorID = 11
        Case 5, 7
            $iCursorID = 10
        Case 4, 8
            $iCursorID = 12
    EndSwitch
    GUISetCursor($iCursorID, 1)
EndFunc   ;==>_SetCursor

; Check cursor type and resize/drag window as required
Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    Local $iCursorType = _Check_Border()
    If $iCursorType > 0 Then ; Cursor is set to resizing style so send appropriate resize message
        $iResizeType = 0xF000 + $iCursorType
        _SendMessage($hCapture_GUI, $WM_SYSCOMMAND, $iResizeType, 0)
    EndIf
EndFunc   ;==>_WM_LBUTTONDOWN

; Determines if mouse cursor over a border
Func _Check_Border()
    Local $aCurInfo = GUIGetCursorInfo($hCapture_GUI)
    Local $aWinPos = WinGetPos($hCapture_GUI)
    Local $iSide = 0
    Local $iTopBot = 0
    If $aCurInfo[0] < $iMargin Then $iSide = 1
    If $aCurInfo[0] > $aWinPos[2] - $iMargin Then $iSide = 2
    If $aCurInfo[1] < $iMargin Then $iTopBot = 3
    If $aCurInfo[1] > $aWinPos[3] - $iMargin Then $iTopBot = 6
    Return $iSide + $iTopBot
EndFunc   ;==>_Check_Border

; Set min and max GUI sizes
Func _WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam)
    $tMinMaxInfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($tMinMaxInfo, 7, $iGUIMinX)
    DllStructSetData($tMinMaxInfo, 8, $iGUIMinY)
    DllStructSetData($tMinMaxInfo, 9, $iGUIMaxX)
    DllStructSetData($tMinMaxInfo, 10, $iGUIMaxY)
    Return 0
EndFunc   ;==>_WM_GETMINMAXINFO
Drag using the left button; get within 4 pixels of the edge to resize; use the right button to capture/cancel. :)

M23

Edited by Melba23
Typo

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Jags,

There is a bug in 3.3.10.0 which prevents the resizing cursor from appearing in the script I posted above unless you press the mouse button - unfortunately it is not an easy fix. So here is a version of the script which uses a differnt technique but has the same functionality and does show the resize cursors with the latest version: :)

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <ScreenCapture.au3>

Global $hCapture_GUI
; Set max and min Capture_GUI sizes
Global Const $iGUIMinX = 50, $iGUIMinY = 50, $iGUIMaxX = @DesktopWidth - 100, $iGUIMaxY = @DesktopHeight - 100

_Main()

Func _Main()

    Local $sJPG_Path = @ScriptDir & "\test.jpg"
    ConsoleWrite($sJPG_Path & @CRLF)

    ; Create GUI
    Local $hMain_GUI = GUICreate("Select Rectangle", 240, 50)

    Local $cRect_Button = GUICtrlCreateButton("Mark Area", 10, 10, 80, 30)
    Local $cCancel_Button = GUICtrlCreateButton("Cancel", 150, 10, 80, 30)

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $cCancel_Button
                FileDelete($sJPG_Path)
                Exit
            Case $cRect_Button
                GUISetState(@SW_HIDE, $hMain_GUI)
                Local $aCoords = Mark_Rect()
                ; Capture selected area
                _ScreenCapture_Capture($sJPG_Path, $aCoords[0], $aCoords[1], $aCoords[0] + $aCoords[2], $aCoords[1] + $aCoords[3], False)
                GUISetState(@SW_SHOW, $hMain_GUI)
                ; Display image
                GUICreate("Selected Rectangle", $aCoords[2], $aCoords[3], 100, 100)
                GUICtrlCreatePic($sJPG_Path, 0, 0, $aCoords[2], $aCoords[3])
                GUISetState()
        EndSwitch
    WEnd

EndFunc   ;==>_Main

; -------------

Func Mark_Rect()

    Local $iWidth = 100, $iHeight = 100

    ; Create capture GUI
    $hCapture_GUI = GUICreate("Y", $iWidth, $iHeight, -1, -1, BitOr($WS_POPUP, $WS_THICKFRAME), BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUISetBkColor(0xABCDEF)

    ; Create label for drag and menu
    Local $cLabel = GUICtrlCreateLabel("", 0, 0, $iWidth, $iHeight, -1, $GUI_WS_EX_PARENTDRAG)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

    ; Create context menu
    Local $cContextMenu = GUICtrlCreateContextMenu($cLabel)
    $cContext_Capture = GUICtrlCreateMenuItem("Capture", $cContextMenu)
    $cContext_Cancel = GUICtrlCreateMenuItem("Cancel", $cContextMenu)

    ; Hide GUI
    _WinAPI_SetLayeredWindowAttributes($hCapture_GUI, 0xABCDEF, 250)

    GUISetState()

    ; Set transparency level
    WinSetTrans($hCapture_GUI, "", 100)

    ; Register message handler
    GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; For GUI size limits

    While 1

        Switch GUIGetMsg()
            Case $cContext_Capture
                ; Get GUI position and delete
                $aPos = WinGetPos($hCapture_GUI)
                GUIDelete($hCapture_GUI)
                ; Unregister message handlers
                GUIRegisterMsg($WM_MOUSEMOVE, "")
                GUIRegisterMsg($WM_LBUTTONDOWN, "")
                GUIRegisterMsg($WM_GETMINMAXINFO, "")
                ; Peturn position
                Return $aPos
            Case $cContext_Cancel
                Exit
        EndSwitch
    WEnd

EndFunc   ;==>Mark_Rect

; Set min and max GUI sizes
Func _WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam)
    $tMinMaxInfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($tMinMaxInfo, 7, $iGUIMinX)
    DllStructSetData($tMinMaxInfo, 8, $iGUIMinY)
    DllStructSetData($tMinMaxInfo, 9, $iGUIMaxX)
    DllStructSetData($tMinMaxInfo, 10, $iGUIMaxY)
    Return 0
EndFunc   ;==>_WM_GETMINMAXINFO
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...