Jump to content

GdiPlus with Child Gui


Recommended Posts

Hi,

I'm starting with GDIPlus functions and I've got problem (of course 😑 ).

Here is the code :

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPISysWin.au3>
#include <WinAPIGdi.au3>

Opt("GUIOnEventMode", 1)


Local $hGUI, $hGraphics, $hBackbuffer, $hBitmap
Local Const $iX = Int(@DesktopWidth * 0.5), $iY = Int(@DesktopHeight * 0.5)

; Initialize GDI+
_GDIPlus_Startup()

Local $GUI_title = "GDI+"
$hGUI = GUICreate($GUI_title, $iX, $iY, -1, -1, BitOR($GUI_SS_DEFAULT_GUI,$WS_THICKFRAME,$WS_TABSTOP))
GUISetState()

Local $Child_Gui1 = GUICreate("Child1", 200, 200, 50, 50)
GUISetBkColor(0x99B4D1)
GUISetState()
_WinAPI_SetParent($Child_Gui1, $hGUI)

Local $Child_Gui2 = GUICreate("Child2", 200, 200, 300, 300)
GUISetBkColor(0x99B4D1)
GUISetState()
_WinAPI_SetParent($Child_Gui2, $hGUI)



$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iX, $iY, $hGraphics)
$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
; Using antialiasing
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)

Local $hPen = _GDIPlus_PenCreate(0xFF000000, 2)


GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

GUIRegisterMsg(0x0216, "WM_MOVING")


While 1

    Sleep(20)
WEnd


Func WM_MOVING($hWnd, $Msg, $wParam, $lParam)
    Local $trect
;~  typedef struct _RECT {
;~   LONG left;
;~   LONG top;
;~   LONG right;
;~   LONG bottom;
;~ } RECT, *PRECT;

    If $hWnd = $Child_Gui2 Then
        $winposChild1 = WinGetPos($Child_Gui1) ; absolute coord

        ; coord conversion absolute to relative for child1
        $tPoint_parent = DllStructCreate("int X;int Y")
        DllStructSetData($tPoint_parent, "X", $winposChild1[0])
        DllStructSetData($tPoint_parent, "Y", $winposChild1[1])
        _WinAPI_ScreenToClient($hGUI, $tPoint_parent)

        $X_relative_child1 = DllStructGetData($tPoint_parent, "X")
        $Y_relative_child1 = DllStructGetData($tPoint_parent, "Y")


        $trect = DllStructCreate("struct;long left;long top;long right;long bottom;endstruct" ,$lParam) ; absolute

        ; coord conversion absolute to relative for child2
        $tPoint_parent = DllStructCreate("int X;int Y")
        DllStructSetData($tPoint_parent, "X", DllStructGetData($trect, "left"))
        DllStructSetData($tPoint_parent, "Y", DllStructGetData($trect, "top"))
        _WinAPI_ScreenToClient($hGUI, $tPoint_parent)

        $X_relative_child2 = DllStructGetData($tPoint_parent, "X")
        $Y_relative_child2 = DllStructGetData($tPoint_parent, "Y")


        ; Drawing
        _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF)
        _GDIPlus_GraphicsDrawLine($hBackbuffer, $X_relative_child2, $Y_relative_child2, $X_relative_child1, $Y_relative_child1, $hPen) ; relative coord
        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iX, $iY)

        _WinAPI_RedrawWindow($hGUI)
    EndIf

    Return 0
EndFunc

Func _Exit()
    ; Clean up
    _GDIPlus_BrushDispose($hPen)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)

    ; Uninitialize GDI+
    _GDIPlus_Shutdown()
    Exit
EndFunc

Just move the Child2, you should see a line between the 2 childs and this line follow the movement of the child2.

The repaint works but it flickers a lot. How can I handle that ?

 

Thanks for your time.

 

 

EDIT : Here is a screenshot of what I am looking for. I'm scanning a LAN with Alcatel Switches (through snmp) and I make this layout. I can move the child Gui and I would like that the line follow the gui I'm dragging. For now all the lines are drawn when I click the "Dessiner" button.

 

schema.jpg

Edited by tatane
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...