Button in der GUI Titelleiste für Hardcopy (screenshot)

  • Hallo Zusammen,

    ich habe mal ein altes Script ausgekrahmt, mit dem man über einen Button in der GUI Titelleiste machen kann! Ähnlich dem Programm Hardcopy!

    Hier sind noch paar schönheitsfehler drin!
    - wenn die button [min/max/close] nicht da sind, springt die hardcopy button außerhalb der gui!
    - der zusätzliche button braucht manchmal etwas, bis er an der richtigen stelle sitzt!
    nun die frage, wie kann man das am einfachsten lösen?

    Spoiler anzeigen
    [autoit]


    #include <GUIConstants.au3>
    #include <ButtonConstants.au3>
    #include <WindowsConstants.au3>
    #include <WinAPI.au3>
    #include <Constants.au3>
    #include <File.au3>
    #include <ScreenCapture.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiButton.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ;#NoTrayIcon

    [/autoit] [autoit][/autoit] [autoit]

    ;DllCall("UxTheme.dll","int","SetThemeAppProperties","dword",0)
    $GUI = GUICreate('',16,16,-1,-1,$WS_POPUP,$WS_EX_TOPMOST+$WS_EX_TOOLWINDOW)
    GUISetBkColor(_WinAPI_GetSysColor($COLOR_ACTIVEBORDER))
    $Button = GUICtrlCreateButton("2",1,2,14,14,$BS_CENTER)
    ;$Button = GUICtrlCreateButton("",1,2,30,14,$BS_CENTER +$BS_ICON)
    ;_GUICtrlButton_SetImage($Button, "shell32.dll", 181, True)
    GUICtrlSetFont($Button,12,400,0,"Wingdings")
    ;DllCall("UxTheme.dll","int","SetThemeAppProperties","dword",3)
    GUISetState(@SW_SHOWNOACTIVATE)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;Opt("TrayMenuMode",1)
    ;TrayTip("ScreenShot-Tool:", "zum Erstellen von Windows ScreenShots.", 5, 1)
    ;TraySetIcon("shell32.dll", 181)
    TraySetState()

    [/autoit] [autoit][/autoit] [autoit]

    $hwnd = -1
    $w = 0
    CheckWin()
    AdlibRegister("CheckWin",10)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
    AdlibUnRegister("CheckWin")
    Exit
    Case $msg = $Button
    ;MsgBox(0, '', "hi")

    [/autoit] [autoit][/autoit] [autoit]

    Capture() ; erstellt screenshot

    [/autoit] [autoit][/autoit] [autoit]

    WinActivate($hwnd)
    Case $hwnd <> $GUI And WinExists($hwnd)
    $pos = WinGetPos($hwnd)
    WinMove($GUI,"",$pos[0]+$pos[2]-$w,$pos[1]+4)
    EndSelect
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func CheckWin()
    Local $hwnd1 = WinGetHandle("")
    If $hwnd1 <> $GUI And $hwnd <> $hwnd1 Then
    Global $hwnd = $hwnd1
    $Style = _WinAPI_GetWindowLong($hwnd,$GWL_STYLE)
    $w = 5
    If BitAND($Style,$WS_MINIMIZEBOX) Then $w += 30
    If BitAND($Style,$WS_SYSMENU) Then $w += 35
    If BitAND($Style,$WS_MAXIMIZEBOX) Then $w += 30
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; function capture screenshot
    Func Capture()
    ; Capture full screen
    If FileExists(@MyDocumentsDir & "\screenshot") Then
    ;MsgBox(4096, "C:\autoexec.bat File", "Exists")
    Else
    ;MsgBox(4096,"C:\autoexec.bat File", "Does NOT exists")
    DirCreate(@MyDocumentsDir & "\screenshot")
    EndIf
    ;FileDelete(@MyDocumentsDir & "\Printscreen*.*"
    _ScreenCapture_Capture(@MyDocumentsDir & "\screenshot\screenshot.jpg")
    ;MsgBox(0, "", "Screenshot erstellt!", 1)

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>Capture_start

    [/autoit]

    danke

    gruß gmmg

  • überarbeitete version!

    -- screenshot vom allen monitoren!
    -- gui fenstern ohne titelleiste wird kein button mehr verpasst

    ob das alles so korrekt ist könnt ihr gern testen und bearbeiten :)

    Spoiler anzeigen
    [autoit]


    #include <GUIConstants.au3>
    #include <ButtonConstants.au3>
    #include <WindowsConstants.au3>
    #include <WinAPI.au3>
    #include <Constants.au3>
    #include <File.au3>
    #include <ScreenCapture.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiButton.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ;#NoTrayIcon

    [/autoit] [autoit][/autoit] [autoit]

    ;DllCall("UxTheme.dll","int","SetThemeAppProperties","dword",0)
    $GUI = GUICreate('',16,16,-1,-1,$WS_POPUP,$WS_EX_TOPMOST+$WS_EX_TOOLWINDOW)
    GUISetBkColor(_WinAPI_GetSysColor($COLOR_ACTIVEBORDER))
    $Button = GUICtrlCreateButton("2",1,2,14,14,$BS_CENTER)
    ;$Button = GUICtrlCreateButton("",1,2,30,14,$BS_CENTER +$BS_ICON)
    ;_GUICtrlButton_SetImage($Button, "shell32.dll", 181, True)
    GUICtrlSetFont($Button,12,400,0,"Wingdings")
    ;DllCall("UxTheme.dll","int","SetThemeAppProperties","dword",3)
    GUISetState(@SW_SHOWNOACTIVATE)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;Opt("TrayMenuMode",1)
    ;TrayTip("ScreenShot-Tool:", "zum Erstellen von Windows ScreenShots.", 5, 1)
    ;TraySetIcon("shell32.dll", 181)
    TraySetState()

    [/autoit] [autoit][/autoit] [autoit]

    $hwnd = -1
    $w = 0
    CheckWin()
    AdlibRegister("CheckWin",10)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
    AdlibUnRegister("CheckWin")
    Exit
    Case $msg = $Button
    ;MsgBox(0, '', "hi")

    [/autoit] [autoit][/autoit] [autoit]

    Capture_Full() ; erstellt screenshot
    WinActivate($hwnd)

    [/autoit] [autoit][/autoit] [autoit]

    Case $hwnd <> $GUI And WinExists($hwnd)
    $pos = WinGetPos($hwnd)
    WinMove($GUI,"",$pos[0]+$pos[2]-$w,$pos[1]+4)
    EndSelect
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func CheckWin()
    Local $hwnd1 = WinGetHandle("")
    If $hwnd1 <> $GUI And $hwnd <> $hwnd1 Then
    Global $hwnd = $hwnd1
    $Style = _WinAPI_GetWindowLong($hwnd,$GWL_STYLE)
    ;ConsoleWrite($Style & @CRLF)
    $w = 5
    If BitAND($Style,$WS_MINIMIZEBOX) Then $w += 30
    If BitAND($Style,$WS_SYSMENU) Then $w += 35
    If BitAND($Style,$WS_MAXIMIZEBOX) Then $w += 30
    IF Not BitAND($Style,$WS_MINIMIZEBOX) Then $w += 30

    [/autoit] [autoit][/autoit] [autoit]

    $windowtext = _WinAPI_GetWindowText($hWnd)
    ;ConsoleWrite($windowtext & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    IF WinActive ("") And $windowtext = "Program Manager" Or $windowtext = "" Then
    GUISetState(@SW_HIDE)
    Else
    GUISetState(@SW_SHOWNOACTIVATE)
    EndIf
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; function capture screenshot
    Func Capture_Full()

    [/autoit] [autoit][/autoit] [autoit]

    Global $tag_DISPLAY_DEVICE = "dword cb;char DeviceName[32];char DeviceString[128];dword StateFlags;char DeviceID[128];char DeviceKey[128]"
    ;Global Const $DISPLAY_DEVICE_MIRRORING_DRIVER = 0x00000008
    ;Global Const $DISPLAY_DEVICE_PRIMARY_DEVICE = 0x00000004

    [/autoit] [autoit][/autoit] [autoit]

    Global $tag_POINTL = "long x;long y"
    Global $tag_DEVMOD = "char dmDeviceName[32];ushort dmSpecVersion;ushort dmDriverVersion;short dmSize;" & _
    "ushort dmDriverExtra;dword dmFields;" & $tag_POINTL & ";dword dmDisplayOrientation;dword dmDisplayFixedOutput;" & _
    "short dmColor;short dmDuplex;short dmYResolution;short dmTTOption;short dmCollate;" & _
    "byte dmFormName[32];ushort LogPixels;dword dmBitsPerPel;int dmPelsWidth;dword dmPelsHeight;" & _
    "dword dmDisplayFlags;dword dmDisplayFrequency"
    ;Global Const $ENUM_CURRENT_SETTINGS = -1
    Global $ENUM_CURRENT_SETTINGS = -1

    [/autoit] [autoit][/autoit] [autoit]

    Global $Left, $Top, $Right, $Bottom
    Global $i = 0

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $struct = DllStructCreate($tag_DISPLAY_DEVICE)
    DllStructSetData($struct, "cb", DllStructGetSize($struct))

    [/autoit] [autoit][/autoit] [autoit]

    $aRetrun = DllCall("user32.dll", "int", "EnumDisplayDevices", "ptr", 0, "dword", $i, "ptr", DllStructGetPtr($struct), "dword", 0)
    If Not $aRetrun[0] Then ExitLoop

    [/autoit] [autoit][/autoit] [autoit]

    If Not BitAND(DllStructGetData($struct, "StateFlags"), $DISPLAY_DEVICE_MIRRORING_DRIVER) Then ; Avoid Virtual Displays
    ;~ ConsoleWrite(DllStructGetData($struct, "DeviceName") & @TAB & "Primary: " & (BitAND(DllStructGetData($struct, "StateFlags"), $DISPLAY_DEVICE_PRIMARY_DEVICE) > 0) & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    $dev = DllStructCreate($tag_DEVMOD)
    DllStructSetData($dev, "dmSize", DllStructGetSize($dev))
    $aRetrun = DllCall("user32.dll", "int", "EnumDisplaySettings", "str", DllStructGetData($struct, "DeviceName"), "dword", $ENUM_CURRENT_SETTINGS, "ptr", DllStructGetPtr($dev))

    [/autoit] [autoit][/autoit] [autoit]

    If Not IsNumber($Left) Or $Left > DllStructGetData($dev, "x") Then $Left = DllStructGetData($dev, "x")
    If Not IsNumber($Top) Or $Top > DllStructGetData($dev, "y") Then $Top = DllStructGetData($dev, "y")
    If Not IsNumber($Right) Or $Right < DllStructGetData($dev, "x") + DllStructGetData($dev, "dmPelsWidth") Then $Right = DllStructGetData($dev, "x") + DllStructGetData($dev, "dmPelsWidth")
    If Not IsNumber($Bottom) Or $Bottom < DllStructGetData($dev, "y") + DllStructGetData($dev, "dmPelsHeight") Then $Bottom = DllStructGetData($dev, "y") + DllStructGetData($dev, "dmPelsHeight")
    EndIf
    $i += 1
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    If $CmdLine[0] = 1 Then
    _ScreenCapture_Capture($CmdLine[1], $Left, $Top, $Right, $Bottom)
    Else
    _ScreenCapture_Capture(@MyDocumentsDir & "\Printscreen.jpg", $Left, $Top, $Right, $Bottom)
    EndIf
    EndFunc ;==>CaptureFull

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    vielleicht kann mal einer drüber schauen ...

    gruß gmmg

    2 Mal editiert, zuletzt von gmmg (8. Dezember 2011 um 16:38)

  • danke für die info kizum!
    die größe des buttons ist an meine derzeitige auflösung angepasst, das müsste man dann noch anhand der auflösung bzw. titelleiste anpassen!

    gruß gmmg