Gui mit Desktop hintergrund

  • Ich wollte mir eine kleine uhr machen, bei der das Gui sichtbar ist, da das Label (mit der zeit) zu sehen sein muss. Jetzt wollte ich nicht ein ödes Gui haben, was mich ganze Zeit stört.

    Also kam mir folgende Idee:

    1. Gui ganz mit GDI+-Öberfläche
    2. Gui mit $ws_popup-style
    3. Bei verschieben vom Gui, wird es hidden
    4. darauf von Gui-position ein Screnncapture machen
    5. Screnncapture ins GDI+ laden
    5. Gui wieder zeigen
    6. mit GDI+ Label erzeugen, welches Zeit enthält.


    So jetzt habe ich folgende Probleme:
    (2.) Wie kann ich ein Gui trotz $ws_popup mit der Maus bewegen lassen
    (4.) Wie bekomme ich die 'left/right-rectangles' des Gui heraus?
    (6.) Welche Funktionen brauch ich, um das GDI+ richtig hierfür anzuwenden? ==> ist gerade neues gebiet für mich.


    Hoffe ihr könnt mir helfen :)
    MFG Sebastian

  • zu (2)
    einfach ein leeres Label über die komplette GUI erzeugen

    [autoit]

    GUICtrlCreateLabel('', 0, 0, 640, 480, -1, $GUI_WS_EX_PARENTDRAG)

    [/autoit]

    zu(4)
    meinst du WinGetPos ?(

  • (6.)

    Habs mal geschrieben:

    Spoiler anzeigen
    [autoit]

    ;Author: Greek
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Include <GDIPlus.au3>

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

    HotKeySet ("{ESC}","_CleanEnd")

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

    Global $GUIBreite=400
    Global $GUIHoehe=150

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

    $hGui=GUICreate("Uhr", $GUIBreite, $GUIHoehe, Default, Default, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW,$WS_EX_TOPMOST))
    GUISetBkColor(0x000000)
    GUICtrlCreateLabel("", 0, 0, $GUIBreite, $GUIHoehe, -1, $GUI_WS_EX_PARENTDRAG)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    _WinAPI_SetLayeredWindowAttributes($hGui, 0x000000, 255,0x02)
    _GuiRoundCorners($hGui,0,0,50,50)
    GUISetState()

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

    GUIRegisterMsg(0x0003,"MY_WM_MOVE")
    _GDIPlus_Startup()

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

    $hGraphic=_GDIPlus_GraphicsCreateFromHWND($hGui)
    $hBrush = _GDIPlus_BrushCreateSolid (0xFFDAA520)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont = _GDIPlus_FontCreate ($hFamily, 40, 2)
    $tLayout = _GDIPlus_RectFCreate (85, 40, 300, 100)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, @HOUR&":"&@MIN&":"&@SEC, $hFont, $tLayout, $hFormat, $hBrush)

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

    AdlibEnable("_Update",200)

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

    While 1
    _GDIPlus_GraphicsClear($hGraphic,0xFF000000)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, @HOUR&":"&@MIN&":"&@SEC, $hFont, $tLayout, $hFormat, $hBrush)
    Sleep ( 1000 )
    WEnd

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

    Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
    ; progandy
    If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03
    If Not $isColorRef Then
    $i_transcolor = Hex(String($i_transcolor), 6)
    $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
    Select
    Case @error
    Return SetError(@error, 0, 0)
    Case $Ret[0] = 0
    Return SetError(4, _WinAPI_GetLastError(), 0)
    Case Else
    Return 1
    EndSelect
    EndFunc ;==>_WinAPI_SetLayeredWindowAttributes

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

    Func MY_WM_MOVE()
    WinSetTrans("Uhr","",150)
    EndFunc

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

    Func _Update()
    $pos=WinGetPos("Uhr")
    $pos2=WinGetPos("Uhr")
    If $pos[0] = $pos2[0] And $pos[1] = $pos2[1] Then
    WinSetTrans("Uhr","",254)
    EndIf
    EndFunc

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

    Func _CleanEnd()
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()
    Exit
    EndFunc

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

    Func _GuiRoundCorners($hWnd, $x1, $y1, $x3, $y3)
    Local $pos, $ret, $ret2
    $pos = WinGetPos($hWnd)
    $ret = DllCall('gdi32.dll', 'long', 'CreateRoundRectRgn', 'long', $x1, 'long', $y1, 'long', $pos[2], 'long', $pos[3], 'long', $x3, 'long', $y3)
    If $ret[0] Then
    $ret2 = DllCall('user32.dll', 'long', 'SetWindowRgn', 'hwnd', $hWnd, 'long', $ret[0], 'int', 1)
    If $ret2[0] Then
    Return 1
    Else
    Return 0
    EndIf
    Else
    Return 0
    EndIf
    EndFunc

    [/autoit]

    Da siehst du ja wie es ungefair geht :)

  • Vielen Dank.

    und wie kann ich den Hintergrund der Gui durch den Desktop, der NUR hinter der Gui ist ersetzen?

    Ich dachte es mir so:

    Wenn man die Gui verschiebt und loslässt, das dann die Gui vresteckt wird. Dannach soll von der Gui die Koordinaten der Ecken ermittelt werden und von diesen Koordinaten ein Screencapture gemacht werden. Dieses Bild kann man dann mit leichtigkeit glaub ich als Hintergrund des GDI/GUI nehmen.

    Bloß wie geht das? Also die Eckkoordinaten der Gui herausfinden?

    MFG Sebastian

  • zu (2) ( man muss kein Label über das gui legen ( könnte stören ))

    hier ein code dafür:

    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include<misc.au3>

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

    $form1=guicreate("Titel",default,default,default,default,$WS_POPUP)
    global $gui
    guisetstate()
    while 1
    $msg=guigetmsg()
    switch $msg
    case $GUI_EVENT_PRIMARYDOWN
    $crusor=GUIGetCursorInfo()
    switch $crusor[4]
    case $gui
    while _IsPressed(01)

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

    $pos=MouseGetPos()
    WinMove($form1,'',$pos[0]-$crusor[0],$pos[1]-$crusor[1],default,default)
    WEnd
    endswitch
    endswitch
    WEnd

    [/autoit]


    Hoffe ich konnte helfen MFG Scripter192

  • Hm, versteh nicht ganz was du meinst, also entweder so: ( Was noch sinnvoll wäre )

    Spoiler anzeigen
    [autoit]

    ;Author: Greek
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Include <GDIPlus.au3>

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

    HotKeySet ("{ESC}","_CleanEnd")

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

    Global $GUIBreite=400
    Global $GUIHoehe=150

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

    $hGui=GUICreate("Uhr", $GUIBreite, $GUIHoehe, Default, Default, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW,$WS_EX_TOPMOST))
    GUISetBkColor(0x000000)
    GUICtrlCreateLabel("", 0, 0, $GUIBreite, $GUIHoehe, -1, $GUI_WS_EX_PARENTDRAG)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    _WinAPI_SetLayeredWindowAttributes($hGui, 0x000000, 255,0x02)
    _GuiRoundCorners($hGui,0,0,400,150)
    GUISetState()

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

    GUIRegisterMsg(0x0003,"MY_WM_MOVE")
    _GDIPlus_Startup()

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

    $hGraphic=_GDIPlus_GraphicsCreateFromHWND($hGui)
    $hBrush = _GDIPlus_BrushCreateSolid (0xFF00FF00)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont = _GDIPlus_FontCreate ($hFamily, 40, 2)
    $tLayout = _GDIPlus_RectFCreate (85, 40, 300, 100)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, @HOUR&":"&@MIN&":"&@SEC, $hFont, $tLayout, $hFormat, $hBrush)

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

    AdlibEnable("_Update",1000)

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

    While 1
    $pos=WinGetPos("Uhr")
    $pos2=WinGetPos("Uhr")
    If $pos[0] = $pos2[0] And $pos[1] = $pos2[1] Then
    _WinAPI_SetLayeredWindowAttributes($hGui, 0x000000, 255,0x02)
    EndIf
    Sleep ( 200 )
    WEnd

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

    Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
    ; progandy
    If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03
    If Not $isColorRef Then
    $i_transcolor = Hex(String($i_transcolor), 6)
    $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
    Select
    Case @error
    Return SetError(@error, 0, 0)
    Case $Ret[0] = 0
    Return SetError(4, _WinAPI_GetLastError(), 0)
    Case Else
    Return 1
    EndSelect
    EndFunc ;==>_WinAPI_SetLayeredWindowAttributes

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

    Func MY_WM_MOVE()
    _WinAPI_SetLayeredWindowAttributes($hGui, 0x000000, 0,0x01)
    EndFunc

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

    Func _Update()
    _GDIPlus_GraphicsClear($hGraphic,0xFF000000)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, @HOUR&":"&@MIN&":"&@SEC, $hFont, $tLayout, $hFormat, $hBrush)
    EndFunc

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

    Func _CleanEnd()
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()
    Exit
    EndFunc

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

    Func _GuiRoundCorners($hWnd, $x1, $y1, $x3, $y3)
    Local $pos, $ret, $ret2
    $pos = WinGetPos($hWnd)
    $ret = DllCall('gdi32.dll', 'long', 'CreateRoundRectRgn', 'long', $x1, 'long', $y1, 'long', $pos[2], 'long', $pos[3], 'long', $x3, 'long', $y3)
    If $ret[0] Then
    $ret2 = DllCall('user32.dll', 'long', 'SetWindowRgn', 'hwnd', $hWnd, 'long', $ret[0], 'int', 1)
    If $ret2[0] Then
    Return 1
    Else
    Return 0
    EndIf
    Else
    Return 0
    EndIf
    EndFunc

    [/autoit]

    Oder so: ( was nicht nur dumm aussieht, sonder auch noch sehr lang brauch bis das Bild kommt )

    Spoiler anzeigen
    [autoit]

    ;Author: Greek
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Include <GDIPlus.au3>
    #Include <ScreenCapture.au3>
    #Include <WinAPI.au3>

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

    HotKeySet ("{ESC}","_CleanEnd")

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

    Global $pImageAttributes
    Global $GUIBreite=400
    Global $GUIHoehe=150

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

    $hGui=GUICreate("Uhr", $GUIBreite, $GUIHoehe, Default, Default, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW,$WS_EX_TOPMOST))
    GUISetBkColor(0x000000)
    GUICtrlCreateLabel("", 0, 0, $GUIBreite, $GUIHoehe, -1, $GUI_WS_EX_PARENTDRAG)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    _WinAPI_SetLayeredWindowAttributes($hGui, 0x000000, 255,0x02)
    _GuiRoundCorners($hGui,0,0,400,150)
    GUISetState()

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

    GUIRegisterMsg(0x0003,"MY_WM_MOVE")
    _GDIPlus_Startup()

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

    $hGraphic=_GDIPlus_GraphicsCreateFromHWND($hGui)
    $hBrush = _GDIPlus_BrushCreateSolid (0xFF00FF00)
    $hBrush2 = _GDIPlus_BrushCreateSolid (0xFF000000)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont = _GDIPlus_FontCreate ($hFamily, 40, 2)
    $tLayout = _GDIPlus_RectFCreate (85, 40, 300, 100)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, @HOUR&":"&@MIN&":"&@SEC, $hFont, $tLayout, $hFormat, $hBrush)

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

    AdlibEnable("_Update",1000)

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

    While 1
    $msg=GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_PRIMARYDOWN
    $pos3=WinGetPos("Uhr")
    $hGDIBitmap = _ScreenCapture_Capture("",$pos3[0],$pos3[1],$GUIBreite+$pos3[0],$GUIHoehe+$pos3[1])
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hGDIBitmap)
    _WinAPI_DeleteObject($hGDIBitmap)
    $pImageAttributes = _GDIPlus_ImageAttributesCreate()
    _DrawImage($hGraphic, $hBitmap, 0, 0, $pImageAttributes)
    _GDIPlus_ImageAttributesDispose($pImageAttributes)
    EndSwitch

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

    $pos=WinGetPos("Uhr")
    $pos2=WinGetPos("Uhr")
    If $pos[0] = $pos2[0] And $pos[1] = $pos2[1] Then
    _WinAPI_SetLayeredWindowAttributes($hGui, 0x000000, 255,0x02)
    EndIf
    Sleep ( 200 )
    WEnd

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

    Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
    ; progandy
    If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03
    If Not $isColorRef Then
    $i_transcolor = Hex(String($i_transcolor), 6)
    $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
    Select
    Case @error
    Return SetError(@error, 0, 0)
    Case $Ret[0] = 0
    Return SetError(4, _WinAPI_GetLastError(), 0)
    Case Else
    Return 1
    EndSelect
    EndFunc ;==>_WinAPI_SetLayeredWindowAttributes

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

    Func MY_WM_MOVE()
    _WinAPI_SetLayeredWindowAttributes($hGui, 0x000000, 0,0x01)
    EndFunc

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

    Func _Update()
    ;~ _GDIPlus_GraphicsClear($hGraphic,0xFF000000)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, @HOUR&":"&@MIN&":"&@SEC, $hFont, $tLayout, $hFormat, $hBrush)
    EndFunc

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

    Func _CleanEnd()
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()
    Exit
    EndFunc

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

    Func _GuiRoundCorners($hWnd, $x1, $y1, $x3, $y3)
    Local $pos, $ret, $ret2
    $pos = WinGetPos($hWnd)
    $ret = DllCall('gdi32.dll', 'long', 'CreateRoundRectRgn', 'long', $x1, 'long', $y1, 'long', $pos[2], 'long', $pos[3], 'long', $x3, 'long', $y3)
    If $ret[0] Then
    $ret2 = DllCall('user32.dll', 'long', 'SetWindowRgn', 'hwnd', $hWnd, 'long', $ret[0], 'int', 1)
    If $ret2[0] Then
    Return 1
    Else
    Return 0
    EndIf
    Else
    Return 0
    EndIf
    EndFunc

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

    Func _DrawImage($hGraphics, $hImage, $X, $Y, $pImageAttributes)
    ; Prog@ndy
    Local $H = _GDIPlus_ImageGetHeight($hImage)
    Local $W = _GDIPlus_ImageGetWidth($hImage)
    Local $Result = _GDIPlus_GraphicsDrawImageRectRectAttr($hGraphics, $hImage, 0, 0, $W, $H, $X, $Y, $W, $H, 2, $pImageAttributes)
    Return SetError(@error,0,$Result)
    EndFunc

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

    Func _GDIPlus_GraphicsDrawImageRectRectAttr($hGraphics, $hImage, $iSrcX, $iSrcY, $iSrcWidth, $iSrcHeight, $iDstX, $iDstY, $iDstWidth, $iDstHeight, $iUnit = 2, $pImageAttributes=0)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipDrawImageRectRectI", "ptr", $hGraphics, "ptr", $hImage, "int", $iDstX, "int", _
    $iDstY, "int", $iDstWidth, "int", $iDstHeight, "int", $iSrcX, "int", $iSrcY, "int", $iSrcWidth, "int", _
    $iSrcHeight, "int", $iUnit, "ptr", $pImageAttributes, "ptr", 0, "ptr", 0)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
    EndFunc ;==>_GDIPlus_GraphicsDrawImageRectRectAttr

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

    Func _GDIPlus_ImageAttributesCreate()
    ; Prog@ndy
    Local $aResult = DllCall($ghGDIpDLL, "int", "GdipCreateImageAttributes", "ptr*", 0)
    If @error Then Return SetError(1,@error,0)
    Return SetError($aResult[0],0,$aResult[1])
    EndFunc

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

    Func _GDIPlus_ImageAttributesDispose($pImageAttributes)
    ; Prog@ndy
    Local $aResult = DllCall($ghGDIpDLL, "int", "GdipDisposeImageAttributes", "ptr", $pImageAttributes)
    If @error Then Return SetError(1,@error,0)
    Return SetError($aResult[0],0,$aResult[0]=0)
    EndFunc

    [/autoit]

    Und bei dem 2 weis ich auch nicht wie man die Zeit übermalen soll ohne dabei das Bild wieder zulöschen.

  • Ich meinte 2. :)

    Ja das mit dem übremalen ist noch doof. glaube dir aber, das du das noch herausfindest :)

    Kann man den Mauszeiger irgendwie verschwinden lassen?

    Weil der Mauszeiger noch immer dabei ist.

    MFG Sebastian