GUI immer im Vordergrund! $WS_EX_TOPMOST funzt nicht!

  • Hallo!

    Ich habe eine GUI die ich mit Buttons belegt hab..nun habe ich eine andere GUI mit der ich auf den Bildschirm zeichne. Diese soll immer im Vordergrund sein! Soweit funzt das auch, nur wenn ich paarmal aufn Desktop klicke und wieder ins GUI zurück dann ist die Zeichnen-GUI im Hintergrund!

    Wie kann ich das Zeichnen-GUI IMMER im Vordergrund halten? ..oder wieder inn Vordergrund bringen/zeichnen wenn es nicht im Vordergrund ist?
    Gibts da sowas wie ne Z-Depth-Reihenfolge oder sowas?

    P.S.: Hab Windows 7, Aero deaktiviert


    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #include <Misc.au3>
    #include <Array.au3>
    _GDIPlus_Startup()
    ;Transparente GUI erstellen
    $hDummy = GUICreate("") ; Dummy GUI, damit richtiges nicht in Taskleiste auftaucht.
    $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, BitOr($WS_CLIPSIBLINGS, $WS_POPUP), BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST,$WS_EX_TRANSPARENT),$hDummy)
    GUISetBkColor(0xABCDEF, $hGUI)
    _WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 255)
    ;Graphic-Objekt, Pinsel und Backbuffer erstellen und GUI anzeigen
    $hBrush = _GDIPlus_BrushCreateSolid (0xEE000000)
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, @DesktopHeight, $hGraphics)
    $hBackBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
    GUISetState(@SW_SHOW);NOACTIVATE)
    _Zentriere("Fischer, wie tief ist das Wasser?", @DesktopWidth / 2, @DesktopHeight / 5, 36, "Arial", $hBackbuffer)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)

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

    #Region ### START Koda GUI section ### Form=C:\Users\IBM\Desktop\Projekte\Heikos_Klicker\Autoit_Abstimmung\Abstimmung.kxf
    $Form1_1 = GUICreate("Form1", 712, 650, -1, -1)
    $Group1 = GUICtrlCreateGroup("", 6, 0, 697, 58, BitOR($GUI_SS_DEFAULT_GROUP,$WS_CLIPSIBLINGS))
    $bStart = GUICtrlCreateButton("Start", 210, 12, 59, 37)
    $bDEL = GUICtrlCreateButton("DEL", 282, 12, 59, 37)
    $bCorrAntw = GUICtrlCreateButton("ANTW", 354, 12, 59, 37)
    $bDiagr = GUICtrlCreateButton("diagramm", 426, 12, 59, 37)
    $bPreQS = GUICtrlCreateButton("prev", 510, 12, 71, 37)
    $bNextQS = GUICtrlCreateButton("next", 618, 12, 71, 37)
    $Button7 = GUICtrlCreateButton("Button1", 117, 12, 71, 37)
    $inpTime = GUICtrlCreateInput("inpTime", 60, 20, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_RIGHT))
    $lTime = GUICtrlCreateLabel("Zeit:", 18, 19, 36, 21, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 10, 800, 4, "MS Sans Serif")
    $lQS = GUICtrlCreateLabel("1/1", 582, 19, 36, 23, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Label1 = GUICtrlCreateLabel("Vorlesungs-ID für Abstimmung:", 6, 614, 296, 29)
    GUICtrlSetFont(-1, 14, 800, 0, "@Arial Unicode MS")
    $Label2 = GUICtrlCreateLabel("Stimmen", 618, 614, 86, 29)
    GUICtrlSetFont(-1, 14, 800, 0, "@Arial Unicode MS")
    $lVotes = GUICtrlCreateLabel("0", 593, 614, 16, 29, $SS_CENTER)
    GUICtrlSetFont(-1, 14, 800, 0, "@Arial Unicode MS")
    $lID = GUICtrlCreateLabel("222", 306, 614, 40, 29, $SS_CENTER)
    GUICtrlSetFont(-1, 14, 800, 0, "@Arial Unicode MS")
    $gOUT = GUICtrlCreateGraphic(30, 72, 650, 320, BitOR($GUI_SS_DEFAULT_GRAPHIC,$SS_CENTER,$SS_CENTERIMAGE))
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    ;$hWnd = GUICtrlGetHandle($gOUT)
    ;_GDIPlus_Startup ()
    ;~ $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
    ;~ $hBrush = _GDIPlus_BrushCreateSolid (0xcf000000)
    ;~ $hBitmap = _GDIPlus_BitmapCreateFromGraphics(650, 320, $hGraphic)
    ;~ $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    ;~ _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
    ;~ ;Zeichne Fragen und Antworten auf GraphicHWND
    ;~ _Zentriere("Fischer, wie tief ist das Wasser?", 325, 40, 36, "Arial", $hBackbuffer) ;_Zentriere($STRING, $X, $Y, $Grösse, $Schrift, BackBuffer/Graphic)
    ;~ _Zentriere("Frage 1" & @CRLF & "Frage 2" & @crlf & "Frage 3" & @CRLF & "Frage 4", 325, 180, 28, "Arial", $hBackbuffer)
    ;~ _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_ImageDispose($hBackBuffer)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_Shutdown()
    Exit
    Case $bDEL
    $aList = WinList()
    _ArrayDisplay($aList)
    EndSwitch
    WEnd

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

    Func _Zentriere($sString, $iX, $iY, $fSize, $sFont, $hGfxBuffer)
    Local $aResult = DllCall($ghGDIPDLL, "uint", "GdipCreatePath", "int", 0, "int*", 0)
    Local $hPath = $aResult[2]
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    Local $tBounds = _GDIPlus_RectFCreate(0, 0, 0, 0)
    DllCall($ghGDIPDLL, "uint", "GdipAddPathString", "hwnd", $hPath, "wstr", $sString, "int", -1, "hwnd", $hFamily, "int", 0, "float", $fSize, "ptr", DllStructGetPtr($tLayout), "hwnd", $hFormat)
    DllCall($ghGDIPDLL, "uint", "GdipGetPathWorldBounds", "hwnd", $hPath, "ptr", DllStructGetPtr($tBounds), "hwnd", 0, "hwnd", 0)
    Local $fRectX = DllStructGetData($tBounds, "X")
    Local $fRectY = DllStructGetData($tBounds, "Y")
    Local $fRectW = DllStructGetData($tBounds, "Width")
    Local $fRectH = DllStructGetData($tBounds, "Height")
    Local $hMatrix = _GDIPlus_MatrixCreate()
    ;Rechteck um Schrift zeichnen
    $hBrush1 = _GDIPlus_BrushCreateSolid (0xFFEFEFEF)
    _GDIPlus_GraphicsFillRect($hGfxBuffer, (@DesktopWidth / 2) - ($fRectW / 2) - 2, (@DesktopHeight / 5) - ($fRectH / 2) - 2, $fRectW + 6, $fRectH + 4, $hBrush1)
    _GDIPlus_MatrixTranslate($hMatrix, -$fRectX - $fRectW / 2 + $iX, -$fRectY - $fRectH / 2 + $iY)
    DllCall($ghGDIPDLL, "uint", "GdipTransformPath", "hwnd", $hPath, "hwnd", $hMatrix)
    _GDIPlus_MatrixDispose($hMatrix)
    DllCall($ghGDIPDLL, "uint", "GdipFillPath", "hwnd", $hGfxBuffer, "hwnd", $hBrush, "hwnd", $hPath)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    DllCall($ghGDIPDLL, "uint", "GdipDeletePath", "hwnd", $hPath)
    EndFunc ;==>_Zentriere

    [/autoit]
  • Wenn du es vor ALLEN Fenstern haben möchtest, dann kannst du einfach GUISetStyle([Deine Styles] + $DS_SETFOREGROUND, -1, $handle) verwenden.
    Wenn du es nur vor deinem Programm haben willst, dann machst du es richtig, aber warum es nicht funktioniert, weiß ich nicht...

    Gruß
    Joriktos

    Edit: Okay, du warst viel schneller ^^ Blöd, mit dem Handy zu schreiben...

    Da es hier doch einige falsch machen:

    Zitat von einem User dieses Forums

    Die Standard-Standart eines Flamingos ist einbeinig. ;)

  • WinSetOnTop("", "", 1) oder WinSetOnTop($hGUI, "", 1) = keine Änderung!

    Iss auch des gleiche wie $WS_EX_TOPMOST.

    Edit:

    Habs jetzt erstmal so gelöst.

    Mit $WM_Paint Funktion und die "dummy"-GUI als parent vom Main-GUI.

    Bin weiter für bessere Lösung offen! Hab auch schon überlegt vllt. gleich aufn Monitor zu zeichnen, DC(0), hat da vllt. jemand was in der Schublade?

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #include <Misc.au3>
    #include <Array.au3>
    Global $hGraphics, $hBackBuffer, $hBrush, $hBitmap
    GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
    _GDIPlus_Startup()
    #Region ### START Koda GUI section ### Form=C:\Users\IBM\Desktop\Projekte\Heikos_Klicker\Autoit_Abstimmung\Abstimmung.kxf
    $Form1_1 = GUICreate("Form1", 712, 650, -1, -1);, Default, Default, $hDummy)
    $Group1 = GUICtrlCreateGroup("", 6, 0, 697, 58, BitOR($GUI_SS_DEFAULT_GROUP,$WS_CLIPSIBLINGS))
    $bStart = GUICtrlCreateButton("Start", 210, 12, 59, 37)
    $bDEL = GUICtrlCreateButton("DEL", 282, 12, 59, 37)
    $bCorrAntw = GUICtrlCreateButton("ANTW", 354, 12, 59, 37)
    $bDiagr = GUICtrlCreateButton("diagramm", 426, 12, 59, 37)
    $bPreQS = GUICtrlCreateButton("prev", 510, 12, 71, 37)
    $bNextQS = GUICtrlCreateButton("next", 618, 12, 71, 37)
    $Button7 = GUICtrlCreateButton("Button1", 117, 12, 71, 37)
    $inpTime = GUICtrlCreateInput("inpTime", 60, 20, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_RIGHT))
    $lTime = GUICtrlCreateLabel("Zeit:", 18, 19, 36, 21, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 10, 800, 4, "MS Sans Serif")
    $lQS = GUICtrlCreateLabel("1/1", 582, 19, 36, 23, BitOR($SS_CENTER,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Label1 = GUICtrlCreateLabel("Vorlesungs-ID für Abstimmung:", 6, 614, 296, 29)
    GUICtrlSetFont(-1, 14, 800, 0, "@Arial Unicode MS")
    $Label2 = GUICtrlCreateLabel("Stimmen", 618, 614, 86, 29)
    GUICtrlSetFont(-1, 14, 800, 0, "@Arial Unicode MS")
    $lVotes = GUICtrlCreateLabel("0", 593, 614, 16, 29, $SS_CENTER)
    GUICtrlSetFont(-1, 14, 800, 0, "@Arial Unicode MS")
    $lID = GUICtrlCreateLabel("222", 306, 614, 40, 29, $SS_CENTER)
    GUICtrlSetFont(-1, 14, 800, 0, "@Arial Unicode MS")
    $gOUT = GUICtrlCreateGraphic(30, 72, 650, 320, BitOR($GUI_SS_DEFAULT_GRAPHIC,$SS_CENTER,$SS_CENTERIMAGE))
    $hDummy = GUICreate("", Default, Default, Default,Default, Default,Default, $Form1_1) ; Dummy GUI, damit richtiges nicht in Taskleiste auftaucht.
    $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, BitOr($WS_POPUP, $DS_SETFOREGROUND), BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TRANSPARENT),$hDummy)
    GUISetState(@SW_SHOW, $Form1_1)
    GUISetState(@SW_SHOWNOACTIVATE, $hGUI)
    GUISetBkColor(0xABCDEF, $hGUI)
    _WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 255)
    ;Graphic-Objekt, Pinsel und Backbuffer erstellen und GUI anzeigen
    $hBrush = _GDIPlus_BrushCreateSolid (0xEE000000)
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, @DesktopHeight, $hGraphics)
    $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
    _Zentriere("Fischer, wie tief ist das Wasser?", @DesktopWidth / 2, @DesktopHeight / 5, 36, "Arial", $hBackbuffer)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
    #EndRegion ### END Koda GUI section ###
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_ImageDispose($hBackBuffer)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_Shutdown()
    Exit
    Case $bDEL
    ;~ $aList = WinList()
    ;~ _ArrayDisplay($aList)
    EndSwitch
    WEnd
    Func _Zentriere($sString, $iX, $iY, $fSize, $sFont, $hGfxBuffer)
    Local $aResult = DllCall($ghGDIPDLL, "uint", "GdipCreatePath", "int", 0, "int*", 0)
    Local $hPath = $aResult[2]
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    Local $tBounds = _GDIPlus_RectFCreate(0, 0, 0, 0)
    DllCall($ghGDIPDLL, "uint", "GdipAddPathString", "hwnd", $hPath, "wstr", $sString, "int", -1, "hwnd", $hFamily, "int", 0, "float", $fSize, "ptr", DllStructGetPtr($tLayout), "hwnd", $hFormat)
    DllCall($ghGDIPDLL, "uint", "GdipGetPathWorldBounds", "hwnd", $hPath, "ptr", DllStructGetPtr($tBounds), "hwnd", 0, "hwnd", 0)
    Local $fRectX = DllStructGetData($tBounds, "X")
    Local $fRectY = DllStructGetData($tBounds, "Y")
    Local $fRectW = DllStructGetData($tBounds, "Width")
    Local $fRectH = DllStructGetData($tBounds, "Height")
    Local $hMatrix = _GDIPlus_MatrixCreate()
    ;Rechteck um Schrift zeichnen
    $hBrush1 = _GDIPlus_BrushCreateSolid (0xFFEFEFEF)
    _GDIPlus_GraphicsFillRect($hGfxBuffer, (@DesktopWidth / 2) - ($fRectW / 2) - 2, (@DesktopHeight / 5) - ($fRectH / 2) - 2, $fRectW + 6, $fRectH + 4, $hBrush1)
    _GDIPlus_MatrixTranslate($hMatrix, -$fRectX - $fRectW / 2 + $iX, -$fRectY - $fRectH / 2 + $iY)
    DllCall($ghGDIPDLL, "uint", "GdipTransformPath", "hwnd", $hPath, "hwnd", $hMatrix)
    _GDIPlus_MatrixDispose($hMatrix)
    DllCall($ghGDIPDLL, "uint", "GdipFillPath", "hwnd", $hGfxBuffer, "hwnd", $hBrush, "hwnd", $hPath)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    DllCall($ghGDIPDLL, "uint", "GdipDeletePath", "hwnd", $hPath)
    EndFunc ;==>_Zentriere

    Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    ;_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    ;_Zentriere("Fischer, wie tief ist das Wasser?", @DesktopWidth / 2, @DesktopHeight / 5, 36, "Arial", $hBackbuffer)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
    ;_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
    EndFunc

    [/autoit]

    Bei defokussiertem Main-GUI und maximieren eines anderen Fensters ist die Vordergrund-Schrift wieder weg!

    Einmal editiert, zuletzt von Morrison (3. Februar 2013 um 02:54)

  • Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>

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

    Global $idGUI = GUICreate("Form1", 625, 443, 193, 125)
    GUISetState(@SW_SHOW)
    WinSetOnTop($idGUI, "",1)

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

    Do
    Until GUIGetMsg() = -3
    Exit

    [/autoit]


    funktiniert bei mir problemlos
    geht sogar über Taskleiste und Tsk-Mager drüber, auch wenn der Immer im Vordergrund ist

    P.S. hab Win7 Home Premium