Jump to content
Tipulatoid

Drawing lines in tabitems

Recommended Posts

Tipulatoid

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.

Share this post


Link to post
Share on other sites
Deye

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
  • Like 1

Share this post


Link to post
Share on other sites
Tipulatoid
4 minutes ago, Deye said:

try for example 

 

Sorry, this doesn't look like a decision.... maybe I didn't catch your idea.

 I need to draw a line in tabitem1

Edited by Tipulatoid

Share this post


Link to post
Share on other sites
Deye

The previous example was for: how to get the controls not related to GDI ..

check the modified above code ..

Share this post


Link to post
Share on other sites
Tipulatoid

Oh, I see.

The idea is  to draw line each time when user clicks needed tabitem and erase it when he clicks another. Didn't think in such direction.

Thank you very much, Deye

Share this post


Link to post
Share on other sites
Deye

your welcome, added a on restore event , just in case  .. :)

Share this post


Link to post
Share on other sites
funkey

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.

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.