Jump to content
AMFC

2D graphic inside a tab control

Recommended Posts

AMFC

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.

Share this post


Link to post
Share on other sites
Jos

@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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
AMFC
Please, forgive my mistake. You're so kind to tell me where to put it.

Share this post


Link to post
Share on other sites
AMFC

 

Thank you very much  JOS.

Share this post


Link to post
Share on other sites
aiter

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. 

Share this post


Link to post
Share on other sites
AMFC

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

 

Share this post


Link to post
Share on other sites
aiter

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

Share this post


Link to post
Share on other sites
Zedna

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

Share this post


Link to post
Share on other sites
AMFC

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

 

 

 

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

  • Similar Content

    • water
      By water
      Extensive library to control and manipulate Microsoft Excel charts.
      Written by GreenCan and water.
      Theads: General Help & Support - Example Scripts
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort

      KNOWN BUGS (last changed: 2017-07-21)
      None. The COM error handling related bugs have been fixed.
       
    • pinkfoyd
      By pinkfoyd
      Hi all,
       
      For my work, i need to produce automatically chart that i will include in my morning email.
       
      First I tried the graph function of powershell with Microsoft Chart Controls , very nice looking, with help of this script : https://gallery.technet.microsoft.com/Drawing-charts-with-6ab5de4e#content
      BUT is useless as i can't sort data in graph ( object array is ***** in powershell, order is random )
       
      So trying back with autoit.
      After lot of forum research :
       
      RMChart : not working Another script not working, or working but only in autoit GUI ( or can't find the good topic ) Chart.udf : nice but not in GDI so can't produce image ImageMagick : possible but very hard to code the entire line can't use excel, because can't install it on the production server.
       
       
      In a perfect world i would produce this :

       
      But simplest will be fine too :

       
       
      Do you know an another solution, any help would be greatly appreciated.
    • Kanashius
      By Kanashius
      This UDF can be used to Display bar charts in a window. I hope you can need it.
      Exampleimage:
      If you like it, please leave me a comment, also if you have any suggestions to make it better or if you found bugs.
      Chart_UDF_source.zip
    • zbigj
      By zbigj
      Hi, I tried to use GraphGDIPlus UDF, it works perfectly for newbee like me, but I want to send mails with graphics to my customers and when I look at the JPG output file (creating with _GraphGDIPlus_SaveImage function) there is no axis values. The reason is because these values are not written to graph area. Had someone tried to solve this problem earlier? I tried to modify _GraphGDIPlus_Set_RangeX function but it's over my possibilites. I've found GraphGDIPlus convenient because of its saveImage function, maybe there is another UDF with same functionality? BR.
    • water
      By water
      In this thread you will find some useful scripts based on the ExcelChart UDF (for download please see my signature).
×