GUI nur teilweise neu zeichnen bei $WM_PAINT-Ereignis (bei Popup-GUI mit benutzerdefinierter Funktion)

  • Guten Tag,

    wie im Titel beschrieben möchte ich bei Auftreten des $WM_PAINT-Ereignisses die GUI nur teilweise neu zeichnen, da mir das Neuzeichnen aller Elemente zu lange dauert und unnötiges Flickern auslöst...
    Ich habe das in einem kleinen Beipsiel versucht zu erklären (siehe Anhang).

    Hier trotzdem nochmal der Quellcode:

    Spoiler anzeigen
    [autoit]

    #include-once
    #include <GuiConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #include <WinAPI.au3>

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

    Opt("GUIOnEventMode", 1) ; Wechsle in den OnEvent Modus

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

    $h_Wnd = GUICreate('GUI', 800, 600, -1, -1,$WS_POPUP );
    GUISetOnEvent($GUI_EVENT_CLOSE, "_exitMain")

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

    $Lbl_Title = GUICtrlCreateLabel('', 0, 0, 800, 25, -1, $GUI_WS_EX_PARENTDRAG)
    GUICtrlSetState ( $Lbl_Title, $GUI_ONTOP )
    _GDIPlus_Startup()

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

    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hBrush = _GDIPlus_BrushCreateSolid (0xFFFFFFFF)
    $hFont = _GDIPlus_FontCreate ($hFamily, 12, 0,2)

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

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($h_Wnd)
    $hImg_Title = _GDIPlus_ImageLoadFromFile("Title.png")

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

    GUISetState()
    _Redraw_GUI()
    GUIRegisterMsg($WM_PAINT, "_Redraw_GUI")

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

    While True
    Sleep(1000)
    WEnd

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

    Func _exitMain()
    _CollectGarbage()
    _GDIPlus_Shutdown()
    Exit
    EndFunc

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

    Func _Redraw_GUI()
    _WinAPI_RedrawWindow($h_Wnd, 0, 0, $RDW_UPDATENOW)

    _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg_Title, 0,0,_GDIPlus_ImageGetWidth($hImg_Title)-1,_GDIPlus_ImageGetHeight($hImg_Title),0,0,800,25)

    $hBrush = _GDIPlus_BrushCreateSolid (0xFFFFFFFF)
    $tLayout = _GDIPlus_RectFCreate ( 20, 8, 450, 18)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, "This is my Title - Exit with {ESC}", $hFont, $tLayout, $hFormat, $hBrush)

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

    _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg_Title, 0,0,_GDIPlus_ImageGetWidth($hImg_Title)-1,_GDIPlus_ImageGetHeight($hImg_Title),100,200,100,100)
    $tLayout = _GDIPlus_RectFCreate ( 105, 205, 90, 30)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, "This is GUIpart 1", $hFont, $tLayout, $hFormat, $hBrush)

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



    _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg_Title, 0,0,_GDIPlus_ImageGetWidth($hImg_Title)-1,_GDIPlus_ImageGetHeight($hImg_Title),600,200,100,100)
    $tLayout = _GDIPlus_RectFCreate ( 605, 205, 90, 30)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, "This is GUIpart 2", $hFont, $tLayout, $hFormat, $hBrush)

    $hBrush = _GDIPlus_BrushCreateSolid (0xFF000000)
    $tLayout = _GDIPlus_RectFCreate ( 200, 405, 400, 100)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, "When parts of the GUI are hidden by other Windows and this GUI is activated again, how can I optimize the _RedrawGUI() to only redraw the previous hidden parts?"&@lf&@lf& _
    "Try Moving the GUI party out of the desktop, and then moving back. You will see the flicker/delay when redraw occurs...I want to minimize that.", $hFont, $tLayout, $hFormat, $hBrush)

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


    _WinAPI_RedrawWindow($h_Wnd, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
    EndFunc

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

    Func _CollectGarbage()
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImg_Title)
    Endfunc

    [/autoit]

    Für einen Hinweis wäre ich dankbar

    Grüße
    JStaxton

    • Offizieller Beitrag

    Welches Betriebssystem benutz du eigentlich? Bei mir flackert nichts. Hab das unter Vista/Windows 7 getestet.

  • Ich habees auf meinem neuen Rechnen mit Win7 Probiert da ging es super, hat nix geflackert, dann hab ich es auf meinem alten 32Bit-XP-Rechner Probiert, da hat es gering Geflackert, hielt sich aber in grenzen

    mfg. Jam00