Jump to content

Drawing lines in tabitems


Recommended Posts

Hello. 

Maybe this issue was discussed before, but I spent about a hour and didn't get the answer. Probably I used wrong search params.
I am trying to draw a line in tabitem. That's is a sample script:
 

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

Example()

Func Example()
    Local $hGUI, $hGraphic, $hPen

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

    $hTab = GUICtrlGetHandle(GuiCtrlCreateTab(20, 10, 350, 280)) ; handle is got

    $hTabItem0 = GUICtrlGetHandle(GuiCtrlCreateTabItem("tabitem0")) ; doesn't get handle
    GuiCtrlCreateLabel("Test0", 100, 100)

    $hTabItem1 = GUICtrlGetHandle(GuiCtrlCreateTabItem("tabitem1")) ; doesn't get handle
    GuiCtrlCreateLabel("Test1", 200, 200)


    ConsoleWrite ($hTab & @CRLF)
    ConsoleWrite ($hTabItem0 & @CRLF)
    ConsoleWrite ($hTabItem1 & @CRLF)


    ; Draw line
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hTab)
    $hPen = _GDIPlus_PenCreate()
    _GDIPlus_GraphicsDrawLine($hGraphic, 25, 150, 300, 120, $hPen)

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

    ; Clean up resources
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

The line is drawn in the GUI, not in the needed tabitem (say, tabitem1). I think, I need to get the handle of the tabitem, but I don't know how.
Thanks in advance.

Link to post
Share on other sites

try for example 

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

Global $hGraphic, $hPen
$hGUI = GUICreate("GDI+", 400, 300)

_GDIPlus_Startup()
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate()
OnAutoItExitRegister("_On_Exit")

$hTab = GUICtrlCreateTab(20, 10, 350, 280)

GUICtrlCreateTabItem("tabitem0")
GUICtrlCreateLabel("Test0", 100, 100)

GUICtrlCreateTabItem("tabitem1")
GUICtrlCreateLabel("Test1", 200, 200)

GUISetState()

_Drawline()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hTab
            If GUICtrlRead($hTab) = 0 Then
                _Drawline()
            Else
                _WinAPI_InvalidateRect($hGUI)
            EndIf
        Case $GUI_EVENT_RESTORE
            If GUICtrlRead($hTab) = 0 Then _Drawline()
    EndSwitch
WEnd

Exit

Func _Drawline()
    _GDIPlus_GraphicsDrawLine($hGraphic, 25, 150, 300, 120, $hPen)
EndFunc   ;==>_Drawline

Func _On_Exit()
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>_On_Exit

 

Edited by Deye
Link to post
Share on other sites

Why not use GUICtrlCreateGraphic for the line?

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...