Jump to content

Resize tabs relative to GUI width


iCode
 Share

Recommended Posts

A few quick searched yielded no results, so...
 
This sets the width of the tabs for a tab control according to the gui width. Additionally, it can control min/max gui size.
 
One benefit of this is, if you have a custom background color for your gui, you no longer have to do something 'sneaky' like adding a colored label to cover that unsightly gray area of the tab control.

This was updated to address the bug that @funkey found

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 3 -w 4 -w 5
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

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

Global $Form1 = GUICreate("Form1", 214, 121, 645, 124, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP))
Global $Tab1 = GUICtrlCreateTab(0, 0, 213, 120, $TCS_FIXEDWIDTH) ; $TCS_FIXEDWIDTH required!
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
GUICtrlCreateTabItem("TabSheet1")
GUICtrlCreateTabItem("TabSheet2")
GUICtrlCreateTabItem("")

Global $aTabCtrlPos, $aWinPos = WinGetPos($Form1)

; set initial tab width
_Tab_SetWidth(1) ; the parameter = the number of additional pixels to subtract from the tab width to avoid having the previous/next tab control show

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
;GUIRegisterMsg($WM_SIZE, "WM_SIZE") ; without the minimum gui size constraints (comment out above line)

While 1
    Switch GUIGetMsg()

        Case $GUI_EVENT_CLOSE
            Exit

        Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
            _Tab_SetWidth(2)

    EndSwitch
WEnd

Func _Tab_SetWidth($i) ; sets the tab width

    Local $aRet = ControlGetPos($Form1, "", $Tab1) ; used to set tab width
    ; size tabs - need to subtract a small number of pixels, else sometimes the previous/next tab control will show - the more tabs, the more we need to subtract
    ; the "2" in "/ 2" = the number of tabs in the tab control
    If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aRet[2] / 2) - $i)

EndFunc

Func WM_GETMINMAXINFO($hWnd, $MsgID, $wParam, $lParam)

    #forceref $MsgID, $wParam

    If Not IsHWnd($hWnd) Then Return $GUI_RUNDEFMSG

    Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)

    DllStructSetData($minmaxinfo, 7, $aWinPos[2]) ; enforce a minimum width for the gui (min width will be the initial width of the gui)
    DllStructSetData($minmaxinfo, 8, $aWinPos[3]) ; enforce a minimum height for the gui (min height will be the initial height of the gui)
    _Tab_SetWidth(2)

    Return $GUI_RUNDEFMSG

EndFunc

; without the minimum gui size constraints (comment out WM_GETMINMAXINFO function)...
#cs
Func WM_SIZE($hWnd, $MsgID, $wParam, $lParam)

    #forceref $MsgID, $wParam, $lParam

    If Not IsHWnd($hWnd) Then Return $GUI_RUNDEFMSG

    _Tab_SetWidth(2)

    Return $GUI_RUNDEFMSG

EndFunc
#ce
Edited by iCode

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Link to comment
Share on other sites

Works great, but not when maximizing and restoring the window.

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 comment
Share on other sites

Never tested that :)
 
Looks like i might need some help; WM_SIZE should work, but this is not working for me...

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

Global $Form1 = GUICreate("Form1", 214, 121, 645, 124, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP))
Global $Tab1 = GUICtrlCreateTab(0, 0, 213, 120, $TCS_FIXEDWIDTH) ; $TCS_FIXEDWIDTH required!
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
GUICtrlCreateTabItem("TabSheet1")
GUICtrlCreateTabItem("TabSheet2")
GUICtrlCreateTabItem("")

Global $aWinPos = WinGetPos($Form1) ; used only to set min/max gui size (optional)

_Tab_SetWidth() ; set initial tab width

GUISetState(@SW_SHOW)

;GUIRegisterMsg($WM_GETMINMAXINFO, "_WINMSG")
;GUIRegisterMsg($WM_WINDOWPOSCHANGING, "_WINMSG")
;GUIRegisterMsg($WM_SYSCOMMAND, "_WINMSG")
GUIRegisterMsg($WM_SIZE, "_WINMSG")

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

Func _Tab_SetWidth() ; sets the initial tab width to fit the tab control

    Local $aRet = ControlGetPos($Form1, "", $Tab1) ; used to set tab width
    If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aRet[2] / 2) - 1) ; size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show

EndFunc

Func _WINMSG($hWnd, $MsgID, $wParam)

    If Not IsHWnd($hWnd) Then Return $GUI_RUNDEFMSG

    ;Switch $wParam
        ;Case 2
            ConsoleWrite("ok" & @LF)
            Local $aCtrlPosTab = ControlGetPos($Form1, "", $Tab1) ; we need the tab control width to set the tab size
            If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aCtrlPosTab[2] / 2) - 2) ; size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show
    ;EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc

reference:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms632646(v=vs.85).aspx

Edited by iCode

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Link to comment
Share on other sites

This works, but i would like to see if anyone can do the same using only the Window Message instead of having the extra Case

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

Global $Form1 = GUICreate("Form1", 214, 121, 645, 124, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP))
Global $Tab1 = GUICtrlCreateTab(0, 0, 213, 120, $TCS_FIXEDWIDTH) ; $TCS_FIXEDWIDTH required!
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
GUICtrlCreateTabItem("TabSheet1")
GUICtrlCreateTabItem("TabSheet2")
GUICtrlCreateTabItem("")

Global $aCtrlPosTab, $aWinPos = WinGetPos($Form1) ; used only to set min/max gui size (optional)

_Tab_SetWidth() ; set initial tab width

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_GETMINMAXINFO, "_WINMSG")
;GUIRegisterMsg($WM_WINDOWPOSCHANGING, "_WINMSG")
;GUIRegisterMsg($WM_SYSCOMMAND, "_WINMSG")
;GUIRegisterMsg($WM_SIZE, "_WINMSG")
;GUIRegisterMsg($WM_ENTERSIZEMOVE, "_WINMSG")
;GUIRegisterMsg($WM_EXITSIZEMOVE, "_WINMSG")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
            $aCtrlPosTab = ControlGetPos($Form1, "", $Tab1) ; we need the tab control width to set the tab size
            If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aCtrlPosTab[2] / 2) - 2) ; size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show

    EndSwitch
WEnd

Func _Tab_SetWidth() ; sets the initial tab width to fit the tab control

    Local $aRet = ControlGetPos($Form1, "", $Tab1) ; used to set tab width
    If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aRet[2] / 2) - 1) ; size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show

EndFunc

Func _WINMSG($hWnd, $MsgID, $wParam, $lParam)

    If Not IsHWnd($hWnd) Then Return $GUI_RUNDEFMSG

    Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)

    DllStructSetData($minmaxinfo, 7, $aWinPos[2]) ; min width
    DllStructSetData($minmaxinfo, 8, $aWinPos[3]) ; min height
    $aCtrlPosTab = ControlGetPos($Form1, "", $Tab1) ; we need the tab control width to set the tab size
    If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aCtrlPosTab[2] / 2) - 2) ; size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show

    Return $GUI_RUNDEFMSG

EndFunc

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
 
Global $Form1 = GUICreate("Form1", 214, 121, 645, 124, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP))
Global $Tab1 = GUICtrlCreateTab(0, 0, 213, 120, $TCS_FIXEDWIDTH) ; $TCS_FIXEDWIDTH required!
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
GUICtrlCreateTabItem("TabSheet1")
GUICtrlCreateTabItem("TabSheet2")
GUICtrlCreateTabItem("")
 
Global $aCtrlPosTab, $aWinPos = WinGetPos($Form1) ; used only to set min/max gui size (optional)
 
_Tab_SetWidth() ; set initial tab width
 
GUISetState(@SW_SHOW)
 
GUIRegisterMsg($WM_GETMINMAXINFO, "_WINMSG")
GUIRegisterMsg($WM_SYSCOMMAND, "_WINMSG")
;GUIRegisterMsg($WM_WINDOWPOSCHANGING, "_WINMSG")
;GUIRegisterMsg($WM_SIZE, "_WINMSG")
;GUIRegisterMsg($WM_ENTERSIZEMOVE, "_WINMSG")
;GUIRegisterMsg($WM_EXITSIZEMOVE, "_WINMSG")
 
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
#cs
Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
$aCtrlPosTab = ControlGetPos($Form1, "", $Tab1) ; we need the tab control width to set the tab size
If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aCtrlPosTab[2] / 2) - 2) ; size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show
#ce
 
EndSwitch
WEnd
 
Func _Tab_SetWidth() ; sets the initial tab width to fit the tab control
 
Local $aRet = ControlGetPos($Form1, "", $Tab1) ; used to set tab width
If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aRet[2] / 2) - 1) ; size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show
 
EndFunc   ;==>_Tab_SetWidth
 
Func _WINMSG($hWnd, $MsgID, $wParam, $lParam)
 
If Not IsHWnd($hWnd) Then Return $GUI_RUNDEFMSG
 
If $MsgID = $WM_SYSCOMMAND Then
Switch BitAND($wParam, 0xFFF0)
Case 0xF030, 0xF120 ; SC_MINIMIZE = 0xF020; SC_MAXIMIZE = 0xF030; SC_RESTORE = 0xF120
AdlibRegister("_Resize_Tab", 10)
EndSwitch
Return $GUI_RUNDEFMSG
EndIf
 
Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
 
DllStructSetData($minmaxinfo, 7, $aWinPos[2]) ; min width
DllStructSetData($minmaxinfo, 8, $aWinPos[3]) ; min height
$aCtrlPosTab = ControlGetPos($Form1, "", $Tab1) ; we need the tab control width to set the tab size
If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aCtrlPosTab[2] / 2) - 2) ; size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show
 
Return $GUI_RUNDEFMSG
 
EndFunc   ;==>_WINMSG
 
Func _Resize_Tab()
Local $aCtrlPosTab = ControlGetPos($Form1, "", $Tab1) ; we need the tab control width to set the tab size
If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aCtrlPosTab[2] / 2) - 2) ; size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show
AdlibUnRegister("_Resize_Tab")
EndFunc   ;==>_Resize_Tab
Link to comment
Share on other sites

Hello KaFu

Am i correct in assessing that there is essentially no difference between using your AdLibRegister and my Case method? If so, personally i prefer using the extra Case.

Windows Messages are not a strong point for me, so if i may ask, where does the '0xFFF0' come from in: Switch BitAND($wParam, 0xFFF0)?

Edit: i shortened the code and updated the first post

Edited by iCode

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Link to comment
Share on other sites

Am i correct in assessing that there is essentially no difference between using your AdLibRegister and my Case method? If so, personally i prefer using the extra Case.

 

Not quite. The WM message and also the Adlib is fired even if the working loop is currently occupied.

 

Windows Messages are not a strong point for me, so if i may ask, where does the '0xFFF0' come from in: Switch BitAND($wParam, 0xFFF0)?

 

From the MSDN documentation for WM_SYSCOMMAND :)...

"In WM_SYSCOMMAND messages, the four low-order bits of the wParam parameter are used internally by the system. To obtain the correct result when testing the value of wParam, an application must combine the value 0xFFF0 with the wParam value by using the bitwise AND operator."

Link to comment
Share on other sites

1) I was only interested in resizing if the max/restore control was pressed (and of course if the resize was done by dragging the window frame)

2) Oh, i see! I was looking at the wrong doc :)

Thanks!

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Link to comment
Share on other sites

  • 3 months later...

In one of my projects I have a problem that I see is also found here.

HOWTO:
Open Kafu modified script in SciTE4AutoIt

Run it using F5 key.

When window Appear use following key combination in this order:
WIN + UP
WIN + DOWN
WIN + LEFT
WIN + RIGHT
WIN + RIGHT

Now you can see that, tab do not resize automaticaly.

Do you have any idea how to make change Tab size in this case?

 

EDIT:

I have this issue in my Acrobat Reader - ActiveX Viewer

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

Good point, this version works for me under the stated conditions.

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

Global $Form1 = GUICreate("Form1", 214, 121, 645, 124, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP))
Global $Tab1 = GUICtrlCreateTab(0, 0, 213, 120, $TCS_FIXEDWIDTH) ; $TCS_FIXEDWIDTH required!
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
GUICtrlCreateTabItem("TabSheet1")
GUICtrlCreateTabItem("TabSheet2")
GUICtrlCreateTabItem("")

Global $aCtrlPosTab, $aWinPos = WinGetPos($Form1) ; used only to set min/max gui size (optional)

_Tab_SetWidth() ; set initial tab width

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_GETMINMAXINFO, "_WINMSG")
GUIRegisterMsg($WM_SYSCOMMAND, "_WINMSG")

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

Func _Tab_SetWidth() ; sets the initial tab width to fit the tab control

    Local $aRet = ControlGetPos($Form1, "", $Tab1) ; used to set tab width
    If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aRet[2] / 2) - 1) ; size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show

EndFunc   ;==>_Tab_SetWidth

Func _WINMSG($hWnd, $MsgID, $wParam, $lParam)

    If Not IsHWnd($hWnd) Then Return $GUI_RUNDEFMSG

    Switch $MsgID
        Case $WM_SYSCOMMAND
            Switch BitAND($wParam, 0xFFF0)
                Case 0xF030, 0xF120 ; SC_MINIMIZE = 0xF020; SC_MAXIMIZE = 0xF030; SC_RESTORE = 0xF120
                    AdlibRegister("_Resize_Tab", 10)
            EndSwitch
        Case $WM_GETMINMAXINFO
            #cs
                Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
                DllStructSetData($minmaxinfo, 7, $aWinPos[2]) ; min width
                DllStructSetData($minmaxinfo, 8, $aWinPos[3]) ; min height
                $aCtrlPosTab = ControlGetPos($Form1, "", $Tab1) ; we need the tab control width to set the tab size
                If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aCtrlPosTab[2] / 2) - 2) ; size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show
            #ce
            AdlibRegister("_Resize_Tab", 10)
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WINMSG

Func _Resize_Tab()
    Local $aCtrlPosTab = ControlGetPos($Form1, "", $Tab1) ; we need the tab control width to set the tab size
    If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aCtrlPosTab[2] / 2) - 2) ; size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show
    AdlibUnRegister("_Resize_Tab")
EndFunc   ;==>_Resize_Tab
Link to comment
Share on other sites

Awesome.

Thanks @KaFu

mLipok

ps.

for other intresting tab stuff look here

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

A little more verstaile from KaFu's example. Now it gets the tab count.

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


Global $Form1 = GUICreate("Form1", 214, 121, 645, 124, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP))
Global $Tab1 = GUICtrlCreateTab(0, 0, 213, 120, $TCS_FIXEDWIDTH) ; $TCS_FIXEDWIDTH required!
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
GUICtrlCreateTabItem("TabSheet1")
GUICtrlCreateTabItem("TabSheet2")
GUICtrlCreateTabItem("TabSheet3")
GUICtrlCreateTabItem("TabSheet4")
GUICtrlCreateTabItem("TabSheet5")
GUICtrlCreateTabItem("TabSheet6")
GUICtrlCreateTabItem("")

Global $aCtrlPosTab, $aWinPos = WinGetPos($Form1) ; used only to set min/max gui size (optional)

_Tab_SetWidth() ; set initial tab width

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_GETMINMAXINFO, "_WINMSG")
GUIRegisterMsg($WM_SYSCOMMAND, "_WINMSG")

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

Func _Tab_SetWidth() ; sets the initial tab width to fit the tab control

    Local $aCtrlPosTab = ControlGetPos($Form1, "", $Tab1) ; used to set tab width
    If Not @error Then _GUICtrlTab_SetItemSize($Tab1, Int($aCtrlPosTab[2] / _GUICtrlTab_GetItemCount($Tab1)) - 2, 0); size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show

EndFunc   ;==>_Tab_SetWidth

Func _WINMSG($hWnd, $MsgID, $wParam, $lParam)

    If Not IsHWnd($hWnd) Then Return $GUI_RUNDEFMSG

    Switch $MsgID
        Case $WM_SYSCOMMAND
            Switch BitAND($wParam, 0xFFF0)
                Case 0xF030, 0xF120 ; SC_MINIMIZE = 0xF020; SC_MAXIMIZE = 0xF030; SC_RESTORE = 0xF120
                    AdlibRegister("_Resize_Tab", 10)
            EndSwitch
        Case $WM_GETMINMAXINFO
            #cs
                Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
                DllStructSetData($minmaxinfo, 7, $aWinPos[2]) ; min width
                DllStructSetData($minmaxinfo, 8, $aWinPos[3]) ; min height
                $aCtrlPosTab = ControlGetPos($Form1, "", $Tab1) ; we need the tab control width to set the tab size
                If Not @error Then GUICtrlSendMsg($Tab1, $TCM_SETITEMSIZE, 0, Int($aCtrlPosTab[2] / 2) - 2) ; size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show
            #ce
            AdlibRegister("_Resize_Tab", 10)
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WINMSG

Func _Resize_Tab()
    Local $aCtrlPosTab = ControlGetPos($Form1, "", $Tab1) ; we need the tab control width to set the tab size
    If Not @error Then _GUICtrlTab_SetItemSize($Tab1, Int($aCtrlPosTab[2] / _GUICtrlTab_GetItemCount($Tab1)) - 2, 0); size tabs - need to deduct 1-2px, else sometimes the previous/next tab control will show
    AdlibUnRegister("_Resize_Tab")
EndFunc   ;==>_Resize_Tab

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Without Global variables (which isn't my style.) I also added $SC_RESTORE, which isn't present in KaFu's example.

#include <GUIConstants.au3>
#include <GuiTab.au3>
#include <MenuConstants.au3>
#include <WindowsConstants.au3>

Global Enum $CONTROLGETPOS_XPOS, $CONTROLGETPOS_YPOS, $CONTROLGETPOS_WIDTH, $CONTROLGETPOS_HEIGHT

Example()

Func Example()
    Local $hGUI = GUICreate('', 214, 121, 645, 124, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
    Local $iTab = GUICtrlCreateTab(0, 0, 213, 120, $TCS_FIXEDWIDTH) ; $TCS_FIXEDWIDTH is required.
    GUICtrlSetResizing($iTab, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)

    GUICtrlCreateTabItem('TabSheet 1')
    GUICtrlCreateTabItem('TabSheet 2')
    GUICtrlCreateTabItem('')

    ; Assign the handle and tab control.
    _Tab_SetWidth($hGUI, $iTab)

    GUIRegisterMsg($WM_GETMINMAXINFO, _Event_Proc)
    GUIRegisterMsg($WM_SYSCOMMAND, _Event_Proc)

    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd

    GUIDelete($hGUI)
EndFunc   ;==>Example

Func _Event_Proc($hWnd, $iMsg, $wParam, $lParam)
    If IsHWnd($hWnd) Then
        Switch $iMsg
            Case $WM_SYSCOMMAND
                Switch _WinAPI_LoWord($wParam)
                    Case $SC_MINIMIZE, $SC_MAXIMIZE, $SC_RESTORE, $SC_SIZE
                        AdlibRegister(_Tab_ResizeWidth, 10)

                EndSwitch

            Case $WM_GETMINMAXINFO
                AdlibRegister(_Tab_ResizeWidth, 10)

        EndSwitch
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_Event_Proc

Func _Tab_ResizeWidth()
    Return __Tab_SetWidth(Default, Default)
EndFunc   ;==>_Tab_ResizeWidth

Func _Tab_SetWidth($hWnd, $iTab)
    Return __Tab_SetWidth($hWnd, $iTab)
EndFunc   ;==>_Tab_SetWidth

Func __Tab_SetWidth($hWnd = Default, $iTab = Default)
    Local Static $hWnd_Static = 0, $iTab_Static = -9999
    If IsHWnd($hWnd) And IsInt($iTab) And $iTab > 0 Then
        $hWnd_Static = $hWnd
        $iTab_Static = $iTab
    ElseIf IsKeyword($hWnd) And IsKeyword($iTab) Then
        Local $aCtrlPosTab = ControlGetPos($hWnd_Static, '', $iTab_Static)
        If Not @error Then
            Local $iWidth = Floor($aCtrlPosTab[$CONTROLGETPOS_WIDTH] / _GUICtrlTab_GetItemCount($iTab_Static)) - 2 ; Deduct 2px for the left/right arrows.
            _GUICtrlTab_SetItemSize($iTab_Static, $iWidth, 0)
        EndIf
        AdlibUnRegister(_Tab_ResizeWidth)
    EndIf
    Return True
EndFunc   ;==>__Tab_SetWidth
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

very nice guinness

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

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

×
×
  • Create New...