Jump to content

Recommended Posts

Posted

Hello everyone,

For a measurement application, I need to put a 2D graphic inside a tab control (inside the second tab). But I can’t get the graph to appear only in the second tab.

Please, what am I doing wrong?

 

#include <GraphGDIPlus_UDF.au3>


$ID0 = GUICreate("TEST 2D Graphic",1000,600)
$idTabCAB = GUICtrlCreateTab(10,10,980,500)

; TabItem definition ************************
$TAB1 = GUICtrlCreateTabItem(" TAB 1  ")
GUICtrlCreateLabel("First Tab.",50,70,400,25)
;---------------------------------------
$TAB2 = GUICtrlCreateTabItem(" TAB 2  ")
GUICtrlCreateLabel("Second Tab.",50,70,400,25)

GUICtrlCreateLabel("Title of the graphic",520,70,400,25)
GUICtrlSetFont(-1,10,800,0,"Arial Narrow")
$Graph = _GraphGDIPlus_Create($ID0,520,100,400,200,0xFF000000,0xFFE0F0FF)
_GraphGDIPlus_Set_RangeX($Graph,1,52,25,1,0)
_GraphGDIPlus_Set_RangeY($Graph,0,100,10,1,0)
;----- Trace the curve -----------------
TraceCurve()

;---------------------------------------
$TAB3 = GUICtrlCreateTabItem(" TAB 3  ")
GUICtrlCreateLabel("Third Tab.",50,70,400,25)
;***********************************************
GUICtrlCreateTabItem(""); end tabitem definition

GUISetState()

While 1
   Local $msg = GUIGetMsg()
   Select
      Case $msg = -3 ;[Exit]
         ExitLoop
   EndSelect
WEnd
;----- close down GDI+ and clear graphic -----
_GraphGDIPlus_Delete($ID0,$Graph)
GUISetState(@SW_HIDE)
Exit



Func TraceCurve()
   _GraphGDIPlus_Set_PenColor($Graph,0xFF0084FF)
   _GraphGDIPlus_Set_PenSize($Graph,2)
   _GraphGDIPlus_Plot_Start($Graph,0,0)
   For $X=1 to 52 Step 1
      $Y = Random(1,100,1) ; Random values for example.
      _GraphGDIPlus_Plot_Line($Graph,$X,$Y)
      _GraphGDIPlus_Refresh($Graph)
   Next
EndFunc

Someone is so kind to help me.  This is my script.   thank you very much in advance.

  • Developers
Posted

@AMFC,
Please pay attention to where you post in the future - the <b>Examples forum</b> is not for questions. 

I have moved this topic to the appropriate forum.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

I will be interested to know how myself.  I suspect the answer might reside in the gui tab management under the User defined function reference,  Set a specific tab to be the focus then draw. 

Posted

Is this your suggestion?...
;*********************************************************************
; How to put a 2D graphic inside Tabs ?
;*********************************************************************
#include <GraphGDIPlus_UDF.au3>
#include <GuiConstantsEx.au3>

$ID0 = GUICreate("TEST 2D Graphic",1000,600)
$idTabCAB = GUICtrlCreateTab(10,10,980,500)

; TabItem definition ************************
$TAB1 = GUICtrlCreateTabItem(" TAB 1  ")
GUICtrlCreateLabel("First Tab. The graphic should not be seen.",50,70,400,25)
;---------------------------------------
$TAB2 = GUICtrlCreateTabItem(" TAB 2  ")
GUICtrlCreateLabel("Second Tab. The graph must be seen.",50,70,400,25)

GUICtrlSetState($TAB2, $GUI_SHOW); <<<<<<<<<<<<<<<<<<<<<<<<<<<<   will be display first

GUICtrlCreateLabel("Title of the graphic",520,70,400,25)
GUICtrlSetFont(-1,10,800,0,"Arial Narrow")
$Graph = _GraphGDIPlus_Create($ID0,520,100,400,200,0xFF000000,0xFFE0F0FF)
_GraphGDIPlus_Set_RangeX($Graph,1,52,25,1,0)
_GraphGDIPlus_Set_RangeY($Graph,0,100,10,1,0)
;----- Trace the curve -----------------
TraceCurve()

;---------------------------------------
$TAB3 = GUICtrlCreateTabItem(" TAB 3  ")
GUICtrlCreateLabel("Third Tab. The graphic should not be seen.",50,70,400,25)
;***********************************************
GUICtrlCreateTabItem(""); end tabitem definition

GUISetState()

While 1
   Local $msg = GUIGetMsg()
   Select
      Case $msg = -3 ;[Exit]
         ExitLoop
   EndSelect
WEnd
;----- close down GDI+ and clear graphic -----
_GraphGDIPlus_Delete($ID0,$Graph)
GUISetState(@SW_HIDE)
Exit

 

Posted (edited)

I was referring to the help file. Anyway I tried what I suggested and no joy.  I think you are out of luck with drawing graphs on tabs , probably should just open another window for each.  Here is the code I tried.

#include <GraphGDIPlus.au3>
#include <GuiTab.au3>

$ID0 = GUICreate("TEST 2D Graphic",1000,600)
$idTabCAB = GUICtrlCreateTab(10,10,980,500)

; TabItem definition ************************
$TAB1 = GUICtrlCreateTabItem(" TAB 1  ")
GUICtrlCreateLabel("First Tab.",50,70,400,25)
;---------------------------------------
$TAB2 = GUICtrlCreateTabItem(" TAB 2  ")
GUICtrlCreateLabel("Second Tab.",50,70,400,25)

GUICtrlCreateLabel("Title of the graphic",520,70,400,25)
GUICtrlSetFont(-1,10,800,0,"Arial Narrow")
GUICtrlCreateTabItem(""); end tabitem definition

;----- Trace the curve -----------------
_GUICtrlTab_SetCurFocus ( $ID0, 0 )

$Graph = _GraphGDIPlus_Create($ID0,520,100,400,200,0xFF000000,0xFFE0F0FF)
_GraphGDIPlus_Set_RangeX($Graph,1,52,25,1,0)
_GraphGDIPlus_Set_RangeY($Graph,0,100,10,1,0)
TraceCurve()



GUISetState()

While 1
   Local $msg = GUIGetMsg()
   Select
      Case $msg = -3 ;[Exit]
         ExitLoop
   EndSelect
WEnd
;----- close down GDI+ and clear graphic -----
_GraphGDIPlus_Delete($ID0,$Graph)
GUISetState(@SW_HIDE)
Exit

Func TraceCurve()
   _GraphGDIPlus_Set_PenColor($Graph,0xFF0084FF)
   _GraphGDIPlus_Set_PenSize($Graph,2)
   _GraphGDIPlus_Plot_Start($Graph,0,0)
   For $X=1 to 52 Step 1
      $Y = Random(1,100,1) ; Random values for example.
      _GraphGDIPlus_Plot_Line($Graph,$X,$Y)
      _GraphGDIPlus_Refresh($Graph)
   Next
EndFunc

 

GraphGDIPlus.au3

Edited by aiter
Posted (edited)

1) use helper picture control (instead of main GUI) as background for your graph

2) redraw graph accordingly in TCN_SELCHANGE event

3) look here 

 

 

Something like this (only concept - has to be finished ...) :

#include <GraphGDIPlus.au3>
#include <GuiTab.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

$ID0 = GUICreate("TEST 2D Graphic",1000,600)
$idTabCAB = GUICtrlCreateTab(10,10,980,500)
$hTab = GUICtrlGetHandle($idTabCAB)

; TabItem definition ************************
$TAB1 = GUICtrlCreateTabItem(" TAB 1  ")
GUICtrlCreateLabel("First Tab.",50,70,400,25)
$idPic = GUICtrlCreatePic('',0,0,1000,600)
$hWndPic = GUICtrlGetHandle($idPic)
;---------------------------------------
$TAB2 = GUICtrlCreateTabItem(" TAB 2  ")
GUICtrlCreateLabel("Second Tab.",50,70,400,25)

GUICtrlCreateLabel("Title of the graphic",520,70,400,25)
GUICtrlSetFont(-1,10,800,0,"Arial Narrow")
GUICtrlCreateTabItem(""); end tabitem definition

;----- Trace the curve -----------------
_GUICtrlTab_SetCurFocus ( $ID0, 0 )

;~ $Graph = _GraphGDIPlus_Create($ID0,520,100,400,200,0xFF000000,0xFFE0F0FF)
$Graph = _GraphGDIPlus_Create($hWndPic,520,100,400,200,0xFF000000,0xFFE0F0FF)
_GraphGDIPlus_Set_RangeX($Graph,1,52,25,1,0)
_GraphGDIPlus_Set_RangeY($Graph,0,100,10,1,0)
TraceCurve()

GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
   Local $msg = GUIGetMsg()
   Select
      Case $msg = -3 ;[Exit]
         ExitLoop
   EndSelect
WEnd
;----- close down GDI+ and clear graphic -----
_GraphGDIPlus_Delete($ID0,$Graph)
GUISetState(@SW_HIDE)
Exit

Func TraceCurve()
   _GraphGDIPlus_Set_PenColor($Graph,0xFF0084FF)
   _GraphGDIPlus_Set_PenSize($Graph,2)
   _GraphGDIPlus_Plot_Start($Graph,0,0)
   For $X=1 to 52 Step 1
      $Y = Random(1,100,1) ; Random values for example.
      _GraphGDIPlus_Plot_Line($Graph,$X,$Y)
      _GraphGDIPlus_Refresh($Graph)
   Next
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab, $fValid
    $hWndTab = $hTab

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTab
            Switch $iCode
                Case $TCN_SELCHANGE
                    If _GUICtrlTab_GetCurSel($hTab) = 0 Then ; zero based index of current selected TabItem
;~                         _GUICtrlIpAddress_ShowHide ($IPAddress1, @SW_SHOW)
;~                      _GraphGDIPlus_Refresh($Graph) ; ?
                        _GraphGDIPlus_ReDraw($hWndPic)
                    Else
;~                         _GUICtrlIpAddress_ShowHide ($IPAddress1, @SW_HIDE)
;~                      _GraphGDIPlus_Refresh($Graph) ; ?
                        _GraphGDIPlus_ReDraw($hWndPic)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Edited by Zedna
Posted

Thanks Aiter and Zedna. I have finally found a way to solve my problem...

The Taitel method works perfectly, although its graph is 3D instead of 2D

 

 

 

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
×
×
  • Create New...