Sign in to follow this  
Followers 0
topten

Problem: Use gdiplus graphics on the child gui

7 posts in this topic

#1 ·  Posted (edited)

I create a parent gui and then I create a child gui. My idea is so I could move(drug)  the child gui within the parent gui without moving out of the parent gui borders

Then I try to add gdiplus graphics onto child gui, but nothing happens (It worked on the normal gui before). What could be done wrong?

Great thanx in advance!

PS.

If you remove this line

DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($Child2_GUI), "hwnd", WinGetHandle($Child1_GUI))

Then the graphics is drawn on the child gui, but the child gui can be moved out of the parent gui borders, which gives the problem

#include <array.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <GuiConstants.au3>
Global Const $Pi = 4 * ATan(1)
Global Const $width = 700
Global Const $height = 400
Global $hGUI, $hWnd, $hGraphic, $ParticleBitmap, $ParticleBuffer, $hBrush0, $Brush, $hBrush2, $Pen
Global $starting_point, $i, $j, $k, $xcoord, $ycoord, $size, $red, $green, $blue, $start


$Main_GUI = GUICreate("Main", @DeskTopWidth-50,@DeskTopHeight-100)
GUISetState(@SW_SHOW, $Main_GUI)
$Child1_GUI = GUICreate("Child", @DeskTopWidth-50, @DeskTopHeight-100, 0, 0, $WS_CHILD, -1, $Main_GUI)
$Btn_Exit = GUICtrlCreateButton("E&xit", 10, 10, 90, 20)
GUISetState(@SW_SHOW, $Child1_GUI)

$Child2_GUI = GUICreate("Child2", $width, $height, 150, 150, $GUI_WS_EX_PARENTDRAG)
GUISetState(@SW_SHOW, $Child2_GUI)

$hWnd = WinGetHandle($Child2_GUI)
_GDIPlus_Startup ()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd) ;create graphic
$ParticleBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic) ;create bitmap
$ParticleBuffer = _GDIPlus_ImageGetGraphicsContext($ParticleBitmap) ;create buffer
 $Brush = _GDIPlus_BrushCreateSolid(0x7F777777)
_GDIPlus_GraphicsClear($ParticleBuffer) ;clear buffer
$Pen = _GDIPlus_PenCreate(0xFF8080FF, 1)
 _GDIPlus_GraphicsDrawLine($ParticleBuffer, 10, 10, 10, 300, $Pen)

 _GDIPlus_GraphicsDrawImageRect($hGraphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap


GUISetState(@SW_SHOW, $Child2_GUI)




$Btn_Test = GUICtrlCreateButton("Test", 10, 10, 90, 20)
GUISetState(@SW_SHOW, $Child2_GUI)
DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($Child2_GUI), "hwnd", WinGetHandle($Child1_GUI))
While 1
   Switch GUIGetMsg()
   Case $GUI_EVENT_CLOSE, $Btn_Exit
      Exit
   Case $Btn_Test
      MsgBox(0, "Test", "Hit Button on Child Window")
   EndSwitch
WEnd
Edited by topten

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this:

#include <array.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <GuiConstants.au3>

Global Const $Pi = 4 * ATan(1)
Global Const $width = 700
Global Const $height = 400
Global $hGUI, $hWnd, $hGraphic, $ParticleBitmap, $ParticleBuffer, $hBrush0, $Brush, $hBrush2, $Pen
Global $starting_point, $i, $j, $k, $xcoord, $ycoord, $size, $red, $green, $blue, $start


$Main_GUI = GUICreate("Main", @DeskTopWidth-50,@DeskTopHeight-100)
GUISetState(@SW_SHOW, $Main_GUI)

$Child1_GUI = GUICreate("Child", @DeskTopWidth-50, @DeskTopHeight-100, 0, 0, $WS_CHILD, -1, $Main_GUI)
$Btn_Exit = GUICtrlCreateButton("E&xit", 10, 10, 90, 20)
GUISetState(@SW_SHOW, $Child1_GUI)

$Child2_GUI = GUICreate("Child2", $width, $height, 150, 150, -1, $GUI_WS_EX_PARENTDRAG)
GUISetState(@SW_SHOW, $Child2_GUI)

DllCall("user32.dll", "int", "SetParent", "hwnd", $Child2_GUI, "hwnd", $Child1_GUI)

_GDIPlus_Startup ()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($Child2_GUI) ;create graphic
$ParticleBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic) ;create bitmap
$ParticleBuffer = _GDIPlus_ImageGetGraphicsContext($ParticleBitmap) ;create buffer
$Brush = _GDIPlus_BrushCreateSolid(0x7F777777)
_GDIPlus_GraphicsClear($ParticleBuffer) ;clear buffer
$Pen = _GDIPlus_PenCreate(0xFF8080FF, 1)
_GDIPlus_GraphicsDrawLine($ParticleBuffer, 10, 10, 10, 300, $Pen)

_GDIPlus_GraphicsDrawImageRect($hGraphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap

$Btn_Test = GUICtrlCreateButton("Test", 10, 10, 90, 20)


While 1
   Switch GUIGetMsg()
       Case $GUI_EVENT_CLOSE, $Btn_Exit
           _GDIPlus_BrushDispose($Brush)
           _GDIPlus_PenDispose($Pen)
           _GDIPlus_GraphicsDispose($ParticleBuffer)
           _GDIPlus_GraphicsDispose($hGraphic)
           _GDIPlus_BitmapDispose($ParticleBitmap)
           GUIDelete()
            Exit
    Case $Btn_Test
        MsgBox(0, "Test", "Hit Button on Child Window")
   EndSwitch
WEnd

Br,

UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thank you so much it works like a charm!

UEZ, there is another small problem. If I minimize the window and then I make it active again- the graphic is gone again and I see only parent and child windows but no graphics on it. Is there a way to solve it?

Share this post


Link to post
Share on other sites

Repaint the GFX (_GDIPlus_GraphicsDrawImageRect($hGraphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap) on $GUI_EVENT_RESTORE message.

Br,

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

I tried this:

1. I made a function for drawing (drawthegraph ())

2. Added this piece of code if not winactive"Child" then drawthegraph()

Now it redraws the graphic, but I think it is working in background and overusing my cpu- everyhing is freezing

I understand that somewhere I should free the gdi+ resources- But how can I do it in a correct way?

I think that your way should be even more correct UEZ, just I dont know how to Repaint the GFX (_GDIPlus_GraphicsDrawImageRect($hGraphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap) on $GUI_EVENT_RESTORE message. :sweating:

#include <array.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <GuiConstants.au3>

Global Const $Pi = 4 * ATan(1)
Global Const $width = 700
Global Const $height = 400
Global $hGUI, $hWnd, $hGraphic, $ParticleBitmap, $ParticleBuffer, $hBrush0, $Brush, $hBrush2, $Pen
Global $starting_point, $i, $j, $k, $xcoord, $ycoord, $size, $red, $green, $blue, $start


$Main_GUI = GUICreate("Main", @DeskTopWidth-50,@DeskTopHeight-100)
GUISetState(@SW_SHOW, $Main_GUI)

$Child1_GUI = GUICreate("Child", @DeskTopWidth-50, @DeskTopHeight-100, 0, 0, $WS_CHILD, -1, $Main_GUI)
$Btn_Exit = GUICtrlCreateButton("E&xit", 10, 10, 90, 20)
GUISetState(@SW_SHOW, $Child1_GUI)

$Child2_GUI = GUICreate("Child2", $width, $height, 150, 150, -1, $GUI_WS_EX_PARENTDRAG)
GUISetState(@SW_SHOW, $Child2_GUI)

DllCall("user32.dll", "int", "SetParent", "hwnd", $Child2_GUI, "hwnd", $Child1_GUI)

drawthegraph()

$Btn_Test = GUICtrlCreateButton("Test", 10, 10, 90, 20)


While 1

   if not WinActive ("Child") then drawthegraph()
   Switch GUIGetMsg()
       Case $GUI_EVENT_CLOSE, $Btn_Exit
           _GDIPlus_BrushDispose($Brush)
           _GDIPlus_PenDispose($Pen)
           _GDIPlus_GraphicsDispose($ParticleBuffer)
           _GDIPlus_GraphicsDispose($hGraphic)
           _GDIPlus_BitmapDispose($ParticleBitmap)
           GUIDelete()
            Exit
    Case $Btn_Test
        MsgBox(0, "Test", "Hit Button on Child Window")
   EndSwitch
WEnd


func drawthegraph()

   _GDIPlus_Startup ()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($Child2_GUI) ;create graphic
$ParticleBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic) ;create bitmap
$ParticleBuffer = _GDIPlus_ImageGetGraphicsContext($ParticleBitmap) ;create buffer
$Brush = _GDIPlus_BrushCreateSolid(0x7F777777)
_GDIPlus_GraphicsClear($ParticleBuffer) ;clear buffer
$Pen = _GDIPlus_PenCreate(0xFF8080FF, 1)
_GDIPlus_GraphicsDrawLine($ParticleBuffer, 10, 10, 10, 300, $Pen)
_GDIPlus_GraphicsDrawRect ( $ParticleBuffer, 10, 10,  10, 10 ,$Pen )

_GDIPlus_GraphicsDrawImageRect($hGraphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap




   endfunc

Share this post


Link to post
Share on other sites

Try this:
 

#include <array.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <GuiConstants.au3>

Global Const $Pi = 4 * ATan(1)
Global Const $width = 700
Global Const $height = 400
Global $hGUI, $hWnd, $hGraphic, $ParticleBitmap, $ParticleBuffer, $hBrush0, $Brush, $hBrush2, $Pen
Global $starting_point, $i, $j, $k, $xcoord, $ycoord, $size, $red, $green, $blue, $start


$Main_GUI = GUICreate("Main", @DeskTopWidth-50,@DeskTopHeight-100)
GUISetState(@SW_SHOW, $Main_GUI)

$Child1_GUI = GUICreate("Child", @DeskTopWidth-50, @DeskTopHeight-100, 0, 0, $WS_CHILD, -1, $Main_GUI)
$Btn_Exit = GUICtrlCreateButton("E&xit", 10, 10, 90, 20)
GUISetState(@SW_SHOW, $Child1_GUI)

$Child2_GUI = GUICreate("Child2", $width, $height, 150, 150, -1, $GUI_WS_EX_PARENTDRAG)
$Btn_Test = GUICtrlCreateButton("Test", 10, 10, 90, 20)

DllCall("user32.dll", "int", "SetParent", "hwnd", $Child2_GUI, "hwnd", $Child1_GUI)

_GDIPlus_Startup ()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($Child2_GUI) ;create graphic
$ParticleBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic) ;create bitmap
$ParticleBuffer = _GDIPlus_ImageGetGraphicsContext($ParticleBitmap) ;create buffer
$Brush = _GDIPlus_BrushCreateSolid(0x7F777777)
_GDIPlus_GraphicsClear($ParticleBuffer) ;clear buffer
$Pen = _GDIPlus_PenCreate(0xFF8080FF, 1)
_GDIPlus_GraphicsDrawLine($ParticleBuffer, 10, 10, 10, 300, $Pen)

Global $hRegion = _GDIPlus_RegionCreateFromRect(0, 0, $width, $height)
Global $hChild = _WinAPI_GetWindow($Child2_GUI, $GW_CHILD)
Global $aRect
Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, $aRect[0], $aRect[1], $aRect[2], $aRect[3], 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
Until Not $hChild
_GDIPlus_GraphicsSetClipRegion($hGraphic, $hRegion)
_GDIPlus_RegionDispose($hRegion)
GUISetState(@SW_SHOW, $Child2_GUI)

_GDIPlus_GraphicsDrawImageRect($hGraphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap


GUIRegisterMsg(0x000F, "WM_PAINT") ;$WM_PAINT = 0x000F

While 1
   Switch GUIGetMsg()
       Case $GUI_EVENT_CLOSE, $Btn_Exit
           _GDIPlus_BrushDispose($Brush)
           _GDIPlus_PenDispose($Pen)
           _GDIPlus_GraphicsDispose($ParticleBuffer)
           _GDIPlus_GraphicsDispose($hGraphic)
           _GDIPlus_BitmapDispose($ParticleBitmap)
           GUIDelete()
            Exit
       Case $GUI_EVENT_RESTORE
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap
    Case $Btn_Test
        MsgBox(0, "Test", "Hit Button on Child Window")
   EndSwitch
WEnd

Func WM_PAINT()
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap
    Return "GUI_RUNDEFMSG"
EndFunc

Br,

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Great thanx UEZ,  it deffinitely does an excellent job

Case $GUI_EVENT_RESTORE
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $ParticleBitmap, 0, 0, $width, $height) ;copy to bitmap

Share this post


Link to post
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
Sign in to follow this  
Followers 0