Jump to content

Calendar only on first tab


 Share

Recommended Posts

Is there a trick or alternative to displaying a selectable calendar on just the first tab.

Using the sample tab script: (The problem here is it shows up on all tabs since it's associated a window handle not a tab)

#include <GUIConstantsEx.au3>
#include <GuiMonthCal.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("Built-In Tab Example", 500, 500)
$hTab = GUICtrlCreateTab(10, 10, 480, 480)

; Create tabitems
For $i = 0 To 2
    GUICtrlCreateTabItem("Tab " & $i)
    If $i = 0 Then;If this is the first tab insert the calendar
       Global $g_hMonthCal = _GUICtrlMonthCal_Create($hGUI, 20, 200, $WS_BORDER)
    EndIf
    GUICtrlCreateButton("Button " & $i, 20 + ($i * 100), 40 + ($i * 50), 80, 30)
Next
; Close Tab definiton
GUICtrlCreateTabItem("")

GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Link to comment
Share on other sites

Hey,

* Haven't used a Tab or Calender before. Just an idea here

What if you look for GUI message for a tab activate/change/whatever and Set Calender state accordingly? You will have to search for how to implement though, until someone else provides a better answer/approach :) 

https://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateTabItem.htm (look at the example)

https://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm

https://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetState.htm

$GUI_SHOW (16) Control will be visible. On Tabitem control will select the first tab to be displayed.
$GUI_HIDE (32) Control will not be visible.

 

Scratch the next comment: You are using "if" :)

Also, if Calender can only be created on the GUI, as it is you may be creating 3 of them, and only using the last one created.

Edited by GokAy
Link to comment
Share on other sites

Thanks @GokAy but no luck if you mean something like this:

 

#include <GUIConstantsEx.au3>
#include <GuiMonthCal.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("Built-In Tab Example", 500, 500)
$hTab = GUICtrlCreateTab(10, 10, 480, 480)

; Create tabitems
For $i = 0 To 2
    GUICtrlCreateTabItem("Tab " & $i)
    If $i = 0 Then;If this is the first tab insert the calendar
       Global $g_hMonthCal = _GUICtrlMonthCal_Create($hGUI, 20, 200, $WS_BORDER)
    EndIf
    GUICtrlCreateButton("Button " & $i, 20 + ($i * 100), 40 + ($i * 50), 80, 30)
Next
; Close Tab definiton
GUICtrlCreateTabItem("")

GUISetState()
$prevTab = GUICtrlRead($hTab)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
   EndSwitch
   If GUICtrlRead($hTab) <> $prevTab Then
      $prevTab = GUICtrlRead($hTab)
      MsgBox(0,"Switched Tabs", $prevTab & " Visible state: " & GUICtrlGetState($g_hMonthCal))
      If $prevTab = 0 Then
         GUICtrlSetState($g_hMonthCal, $GUI_SHOW)
      Else
         GUICtrlSetState($g_hMonthCal, $GUI_HIDE)
      EndIf
   EndIf         
WEnd

It isn't hiding the tab. 

Edited by NassauSky
Link to comment
Share on other sites

I would guess more like (looking at the example)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hTab
            if GUICtrlRead($hTab) = 0 then
                GUICtrlSetState($g_hMonthCal, $GUI_SHOW)   
            else
                GUICtrlSetState($g_hMonthCal, $GUI_HIDE)
            endif
   EndSwitch
WEnd

 

Link to comment
Share on other sites

Try this :

#include <GUIConstantsEx.au3>
#include <GuiMonthCal.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>

$hGUI = GUICreate("Built-In Tab Example", 500, 500)
$hTab = GUICtrlCreateTab(10, 10, 480, 480)

; Create tabitems
For $i = 0 To 2
  GUICtrlCreateTabItem("Tab " & $i)
  If $i = 0 Then  ;If this is the first tab insert the calendar
    Global $g_hMonthCal = _GUICtrlMonthCal_Create($hGUI, 20, 200, $WS_BORDER)
  EndIf
  GUICtrlCreateButton("Button " & $i, 20 + ($i * 100), 40 + ($i * 50), 80, 30)
Next
; Close Tab definiton
GUICtrlCreateTabItem("")

GUISetState()
While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Exit
    Case $hTab
      If GUICtrlRead($hTab) = 0 Then
        If Not $g_hMonthCal Then $g_hMonthCal = _GUICtrlMonthCal_Create($hGUI, 20, 200, $WS_BORDER)
        _WinAPI_RedrawWindow($hGUI)
      ElseIf $g_hMonthCal Then
        _GUICtrlMonthCal_Destroy($g_hMonthCal)
        $g_hMonthCal = 0
      EndIf
  EndSwitch
WEnd

 

Link to comment
Share on other sites

@Nine Wouldn't this also loose the current date value in case it may be needed?

Maybe assign last date value to a variable before destroying, and re-assign after creation? Not sure about this part: Change code to read that variable instead (but it would require to set it each time a new date is selected?)

Link to comment
Share on other sites

  • Moderators

NassauSky,

Please read the Tabs tutorial in the Wiki - then you will find out how to keep the calendar on the correct page.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Alright here another way :

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

$hGUI = GUICreate("Built-In Tab Example", 500, 500)
$hTab = GUICtrlCreateTab(10, 10, 480, 480)

; Create tabitems
For $i = 0 To 2
  GUICtrlCreateTabItem("Tab " & $i)
  If $i = 0 Then  ;If this is the first tab insert the calendar
    Global $g_hMonthCal = _GUICtrlMonthCal_Create($hGUI, 20, 200, $WS_BORDER)
  EndIf
  GUICtrlCreateButton("Button " & $i, 20 + ($i * 100), 40 + ($i * 50), 80, 30)
Next
; Close Tab definiton
GUICtrlCreateTabItem("")

GUISetState()
While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Exit
    Case $hTab
      If GUICtrlRead($hTab) = 0 Then
        _WinAPI_ShowWindow ($g_hMonthCal, @SW_SHOW)
      Else
        _WinAPI_ShowWindow ($g_hMonthCal, @SW_HIDE)
      EndIf
  EndSwitch
WEnd

Should work better 

Link to comment
Share on other sites

Also this works, after checking out (not reading throughly) the tab wiki @Melba23 linked :P 

Edit: Notice that I pulled MonthCal creation outside the loop, since it is not tied to the tab

Edit2: and also forgot the Window Style I tried earlier in there. Fixed according to the original post.

#include <GUIConstantsEx.au3>
#include <GuiMonthCal.au3>
#include <WindowsConstants.au3>


test_gui()


func test_gui()

    Local $hGUI = GUICreate("Built-In Tab Example", 500, 500)
    Local $hTab = GUICtrlCreateTab(10, 10, 480, 480)
    Local $g_hMonthCal = _GUICtrlMonthCal_Create($hGUI, 20, 200, $WS_BORDER)
    
    ; Create tabitems
    For $i = 0 To 2
        GUICtrlCreateTabItem("Tab " & $i)
        GUICtrlCreateButton("Button " & $i, 20 + ($i * 100), 40 + ($i * 50), 80, 30)
    Next

    ; Close Tab definiton
    GUICtrlCreateTabItem("")

    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $hTab
                ConsoleWrite($hTab & " > " & GUICtrlRead($hTab) & @crlf)
                if GUICtrlRead($hTab) = 0 then
                    ControlShow($hGUI,"",$g_hMonthCal)
                else
                    ControlHide($hGUI,"",$g_hMonthCal)
                endif
        EndSwitch
    WEnd

EndFunc

 

Edited by GokAy
Link to comment
Share on other sites

  • Moderators

GokAy,

Quote

not reading throughly

I do recommend reading all the tutorials I wrote thoroughly - there are often some other hints hidden within them as a bonus for attentive readers.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@Melba23 You are definitely right, no argument there.

I usually check out a function/udf page to get an initial idea (if I know about the function), and/or ask google what I am trying to achieve with "autoit" prepended (usually lend in the forums, and sometimes in StackOverflow).

Read all I find relevant, get an idea of which functions are needed (go to their pages and read all)

Try to solve each step until I hit a bump, search/read some more.

Rinse/repeat until I achieve what I am trying to do.

However, when it comes to wikis I only read when someone mentions it in the topic. Maybe because they don't get listed all that often on my Google searches. :( 

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...