Jump to content

GDI+ Child within parent gui, graphics escape


topten
 Share

Recommended Posts

I create a parent gui. Inside it I create a child gui, which is movable On that GUI I draw graphics. When I move the gui with graphics on it outside of the border and return it back all graphic information escapes. If I create another child gui with graph and then move it above first child gui, all the graphic information will also escape. Is there any possibility to control this? May be, should I convert the graphics into some image?

Here is the code

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout

    $Main_GUI = GUICreate("GDI+", 1400, 1300)

    GUISetState()
    Global $Child1_GUI = GUICreate("Child", 1200, 700, 300, 100, $WS_CHILD, -1, $Main_GUI)
GUISetBkColor (0x33334C, $Child1_GUI )
GUISetState()









    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)

    DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($hGUI), "hwnd", WinGetHandle($Child1_GUI))
    GUISetState(@SW_SHOW)












    ; Draw a string
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBrush = _GDIPlus_BrushCreateSolid(0x7F00007F)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
    $tLayout = _GDIPlus_RectFCreate(140, 110, 100, 20)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, "Hello world", $hFont, $tLayout, $hFormat, $hBrush)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

 

 

Great thanx in advance

Link to comment
Share on other sites

You have to repaint on GUI erase triggering.

Something like this here:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Global $hGUI, $hGraphic, $hBitmap, $hCanvas, $hBrush, $hFormat, $hFamily, $hFont, $tLayout

Example()

Func Example()
    $Main_GUI = GUICreate("GDI+", 1400, 1300)

    GUISetState()
    Global $Child1_GUI = GUICreate("Child", 1200, 700, 300, 100, $WS_CHILD, -1, $Main_GUI)
    GUISetBkColor (0x33334C, $Child1_GUI )
    GUISetState()









    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)

    DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($hGUI), "hwnd", WinGetHandle($Child1_GUI))
    GUISetState(@SW_SHOW)





    GUIRegisterMsg($WM_PAINT, "WM_PAINT")






    ; Draw a string
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBitmap = _GDIPlus_BitmapCreateFromScan0(400, 300)
    $hCanvas = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4)
    _GDIPlus_GraphicsSetTextRenderingHint($hCanvas, 4)

    $hBrush = _GDIPlus_BrushCreateSolid(0x7F00007F)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
    $tLayout = _GDIPlus_RectFCreate(140, 110, 100, 20)
    _GDIPlus_GraphicsDrawStringEx($hCanvas, "Hello world", $hFont, $tLayout, $hFormat, $hBrush)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 400, 300)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hCanvas)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 400, 300)
;~  _WinAPI_RedrawWindow($hGui, 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_PAINT

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thank you very much UEZ.  This function is a real invention for me. Just what I found now that the gui with graphic is flashing. And if the graphic will be more complicated and say if I have 3-4 graphics, that will be too much flashing. I want to try alternative way- Is it possible to convert the gdi-graphics into static picture? If yes, how can I do that?

Link to comment
Share on other sites

Create a pic control, create your bitmap and send the bitmap (gdi format - not gdi+ format!) to the pic control. That's all.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Sure. Here we go:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Global $hGUI, $hGraphic, $hBitmap, $hCanvas, $hBrush, $hFormat, $hFamily, $hFont, $tLayout

Example()

Func Example()
    Local $Main_GUI = GUICreate("GDI+", 1400, 1300)

    GUISetState()
    Local $Child1_GUI = GUICreate("Child", 1200, 700, 300, 100, $WS_CHILD, -1, $Main_GUI)
    GUISetBkColor (0x33334C, $Child1_GUI )
    GUISetState()


    ; Create GUI
    Local $hGUI = GUICreate("GDI+", 400, 300)
    Local $iPic = GUICtrlCreatePic("", 0, 0, 400, 300)
    DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($hGUI), "hwnd", WinGetHandle($Child1_GUI))
    GUISetState(@SW_SHOW)


    ; Draw a string
    _GDIPlus_Startup()
    $hBitmap = _GDIPlus_BitmapCreateFromScan0(400, 300) ;GDIPlus bitmap format!
    $hCanvas = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4)
    _GDIPlus_GraphicsSetTextRenderingHint($hCanvas, 4)
    _GDIPlus_GraphicsClear($hCanvas, 0xFFF0F0F0)
    $hBrush = _GDIPlus_BrushCreateSolid(0x7F00007F)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
    $tLayout = _GDIPlus_RectFCreate(140, 110, 100, 20)
    _GDIPlus_GraphicsDrawStringEx($hCanvas, "Hello world", $hFont, $tLayout, $hFormat, $hBrush)
    $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;GDI bitmap format!
    _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, $IMAGE_BITMAP, $hHBitmap)) ;$STM_SETIMAGE = 0x0172

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hCanvas)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Great, thank you very much UEZ

I wonder if I update it this way is it adding a new image or is it replacing old one?. I need to know for saving memory issues

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Global $hGUI, $hGraphic, $hBitmap, $hCanvas, $hBrush, $hFormat, $hFamily, $hFont, $tLayout

Example()

Func Example()
    Local $Main_GUI = GUICreate("GDI+", 1400, 1300)

    GUISetState()
    Local $Child1_GUI = GUICreate("Child", 1200, 700, 300, 100, $WS_CHILD, -1, $Main_GUI)
    GUISetBkColor (0x33334C, $Child1_GUI )
    GUISetState()


    ; Create GUI
    Local $hGUI = GUICreate("GDI+", 400, 300)
    Local $iPic = GUICtrlCreatePic("", 0, 0, 400, 300)
    DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($hGUI), "hwnd", WinGetHandle($Child1_GUI))
    GUISetState(@SW_SHOW)


    ; Draw a string
    _GDIPlus_Startup()
    $hBitmap = _GDIPlus_BitmapCreateFromScan0(400, 300) ;GDIPlus bitmap format!
    $hCanvas = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4)
    _GDIPlus_GraphicsSetTextRenderingHint($hCanvas, 4)
    _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)
    $hBrush = _GDIPlus_BrushCreateSolid(0x7F00007F)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
    $tLayout = _GDIPlus_RectFCreate(140, 110, 100, 20)
    _GDIPlus_GraphicsDrawStringEx($hCanvas, "Hello world", $hFont, $tLayout, $hFormat, $hBrush)
    $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;GDI bitmap format!
    _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, $IMAGE_BITMAP, $hHBitmap)) ;$STM_SETIMAGE = 0x0172



    MsgBox (0, "", "")


     $hBitmap = _GDIPlus_BitmapCreateFromScan0(400, 300) ;GDIPlus bitmap format!
    $hCanvas = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4)
    _GDIPlus_GraphicsSetTextRenderingHint($hCanvas, 4)
    _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)
    $hBrush = _GDIPlus_BrushCreateSolid(0x7F00007F)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
    $tLayout = _GDIPlus_RectFCreate(140, 110, 100, 20)
    _GDIPlus_GraphicsDrawStringEx($hCanvas, "Hello world2", $hFont, $tLayout, $hFormat, $hBrush)
    $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;GDI bitmap format!
    _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, $IMAGE_BITMAP, $hHBitmap)) ;$STM_SETIMAGE = 0x0172
















    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hCanvas)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

 

Link to comment
Share on other sites

I forgot to change _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0) to _GDIPlus_GraphicsClear($hCanvas, 0xFFF0F0F0) - sorry.

Anyhow, try this:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Global $hGUI, $hGraphic, $hBitmap, $hCanvas, $hBrush, $hFormat, $hFamily, $hFont, $tLayout

Example()

Func Example()
    Local $Main_GUI = GUICreate("GDI+", 1400, 1300)

    GUISetState()
    Local $Child1_GUI = GUICreate("Child", 1200, 700, 300, 100, $WS_CHILD, -1, $Main_GUI)
    GUISetBkColor (0x33334C, $Child1_GUI )
    GUISetState()


    ; Create GUI
    Local $hGUI = GUICreate("GDI+", 400, 300)
    Local $iPic = GUICtrlCreatePic("", 0, 0, 400, 300)
    DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($hGUI), "hwnd", WinGetHandle($Child1_GUI))
    GUISetState(@SW_SHOW)


    ; Draw a string
    _GDIPlus_Startup()
    $hBitmap = _GDIPlus_BitmapCreateFromScan0(400, 300) ;GDIPlus bitmap format!
    $hCanvas = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4)
    _GDIPlus_GraphicsSetTextRenderingHint($hCanvas, 4)
    _GDIPlus_GraphicsClear($hCanvas, 0xFFF0F0F0)
    $hBrush = _GDIPlus_BrushCreateSolid(0x7F00007F)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
    $tLayout = _GDIPlus_RectFCreate(140, 110, 100, 20)
    _GDIPlus_GraphicsDrawStringEx($hCanvas, "Hello world", $hFont, $tLayout, $hFormat, $hBrush)
    $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;GDI bitmap format!
    _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, $IMAGE_BITMAP, $hHBitmap)) ;$STM_SETIMAGE = 0x0172

    MsgBox (0, "", "")

    ; Loop until the user exits.
    Do
        _GDIPlus_GraphicsClear($hCanvas, 0xFFF0F0F0)
        _GDIPlus_GraphicsDrawStringEx($hCanvas, @SEC & ":" & @MSEC, $hFont, $tLayout, $hFormat, $hBrush)
        _WinAPI_DeleteObject($hHBitmap)
        $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;GDI bitmap format!
        _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, $IMAGE_BITMAP, $hHBitmap)) ;$STM_SETIMAGE = 0x0172
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hCanvas)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

 

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Ah, so nice. I understand now the code even better. Could you please explain just in few words what process is happening there? I mean

_GDIPlus_GraphicsClear($hCanvas, 0xFFF0F0F0)
        _GDIPlus_GraphicsDrawStringEx($hCanvas, @SEC & ":" & @MSEC, $hFont, $tLayout, $hFormat, $hBrush)
        _WinAPI_DeleteObject($hHBitmap)
        $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;GDI bitmap format!
        _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, $IMAGE_BITMAP, $hHBitmap)) ;$STM_SETIMAGE = 0x0172

Does it mean that a new builded graph is replacing the previous image? Or the graph is converted into image and then it is replacing the image?

Link to comment
Share on other sites

Sure:

_GDIPlus_GraphicsClear($hCanvas, 0xFFF0F0F0) ;clear the GDI+ bitmap, $hCanvas is something like a wrapper to draw to the bitmap
_GDIPlus_GraphicsDrawStringEx($hCanvas, @SEC & ":" & @MSEC, $hFont, $tLayout, $hFormat, $hBrush) ;draw string to the bitmap
_WinAPI_DeleteObject($hHBitmap) ;to avoid memory leak release GDI bitmap resource
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;create the new GDI bitmap as a copy of the GDI+ bitmap
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, 0x0172, $IMAGE_BITMAP, $hHBitmap)) ;send the GDI bitmap to the pic control - the control will be overpainted

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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