Jump to content

What styles work in _GuiCtrlToolbar?


c.haslam
 Share

Recommended Posts

I am working on a Styles dialog for Koda. It (and those for other controls) accept that not every combination of styles works -- even those that MSDN is silent on! So, as well as offering the user to opportunity to try any styles he likes, it has Presets: combinations that are known to work and are fairly commonly used.

The dialog also shows a sample of how the control will look and behave with each combination of styles.

For almost all other controls, the dialogs have been written and tested. This has involved a lot of experimentation: starting from MSDN, and through experiments figuring out what MSDN should have said!

The Toolbar control is proving to be a tough one. For example, using the Style parameter of _GuiCtrlToolbar_Create, $TBSTYLE_TRANSPARENT and $TBSTYLE_FLAT work as expected, but in order to get the appearance that MSDN claims for $TBSTYLE_LIST, I have to use BitOR($TBSTYLE_TRANSPARENT,$TBSTYLE_LIST).

I have tried following the examples in the AutoIt help; there the styles are set using _GuiCtrlToobar_SetStyles. The examples I have run, and modified (to try various styles) always seem to produce the same appearance: toolbar transparent, button transparent..

I do note that MSDN says that an external image list is required if the control is created with CreateWindowEx. _GuiCtrlToolbox_Create calls CreateWindowEx. The examples mostly use the internal imagelists. So it is surprising that they work at all.

At this point, I think that the UDFs can be trusted -- that the fault lies with MSDN and Windows: there seems to be a lot Microsoft is not telling!

I am running AutoIt 3.6.3 on XP SP3.

I have been working on this control for a week or so now. Ideas do occur to me in my morning shower; perhaps one day I will get a good idea! (It happened for the other controls.)

Can anyone guide me in the right direction? I am willing to accept that a few style combinations don't work, but at this point most don't work!

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

What is a toolbox control?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thank you for pointing out my error: Toolbox should be Toolbar. How can I get the Title changed?

Edited by c.haslam
Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

Consider the following script:

#include 
#include 
#include 
#include 

Opt('MustDeclareVars', 1)

Local $hGUI, $hToolbar
Local Enum $idNew = 1000, $idOpen, $idSave, $idHelp

; Create GUI
$hGUI = GUICreate("Toolbar", 400, 300)
GUISetBkColor(0x990000)
$hToolbar = _GUICtrlToolbar_Create ($hGUI) ; no call to _GuiCtrlToolBar_SetStyle ;=> TB transparent, Buttons opaque, TB at top => OK
;$hToolbar = _GUICtrlToolbar_Create ($hGUI,$TBSTYLE_TRANSPARENT)    ;=> TB transparent, Buttons opaque, TB at top => OK
;$hToolbar = _GUICtrlToolbar_Create ($hGUI,$TBSTYLE_FLAT)       ;=> TB transparent, Buttons opaque, TB at top => OK
;$hToolbar = _GUICtrlToolbar_Create ($hGUI,$TBSTYLE_LIST)           ;=> TB opaque, Buttons opaque, TB at top => bad

;_GUICtrlToolbar_SetStyle($hToolbar,$TBSTYLE_TRANSPARENT)   ;=> TB transparent, Buttons opaque, TB at bottom => bad
;_GUICtrlToolbar_SetStyle($hToolbar,$TBSTYLE_FLAT)          ;=> TB opaque, Buttons opaque, TB at bottom => bad
;_GUICtrlToolbar_SetStyle($hToolbar,$TBSTYLE_LIST)          ;=> TB opaque, Buttons opaque, TB at bottom => bad
GUISetState()

  ; Add standard system bitmaps
Switch _GUICtrlToolbar_GetBitmapFlags($hToolbar)
    Case 0
        _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_SMALL_COLOR)
    Case 2
        _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)
EndSwitch

; Add buttons
_GUICtrlToolbar_AddButton ($hToolbar, $idNew, $STD_FILENEW)
_GUICtrlToolbar_AddButton ($hToolbar, $idOpen, $STD_FILEOPEN)
_GUICtrlToolbar_AddButton ($hToolbar, $idSave, $STD_FILESAVE)
_GUICtrlToolbar_AddButtonSep ($hToolbar)
_GUICtrlToolbar_AddButton ($hToolbar, $idHelp, $STD_HELP)

;_GUICtrlToolbar_SetStyle($hToolbar,$TBSTYLE_TRANSPARENT)   ;=> TB transparent, Buttons opaque, TB at bottom => bad
;_GUICtrlToolbar_SetStyle($hToolbar,$TBSTYLE_FLAT)          ;=> TB transparent, Buttons tranparent, TB at bottom => bad
_GUICtrlToolbar_SetStyle($hToolbar,$TBSTYLE_LIST)           ;=> TB transparent, Buttons tranparent, TB at bottom => bad

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

It is based on the examples in the AutoIt help, but I have added call to GuiSetBkColor so transparency (and opacity) can be seen. Try changing which lines are commented out. "OK" means appearance agrees wirh MSDN; "bad" means that it doesn't, in some way.

There seems to be no line at which to set the styles where the control works as advertised! The only solution I see for Koda is to place _GUICtrlToolbar_SetStyle just before the message loop, with $CCS_TOP BitORed with the style.

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

Excerpted from GuiToolbar.au3:

Func _GUICtrlToolbar_SetStyle($hWnd, $iStyle)
    If $Debug_TB Then __UDF_ValidateClassName($hWnd, $__TOOLBARCONSTANT_ClassName)

    $iStyle = BitOR($iStyle, $__UDFGUICONSTANT_WS_CHILD, $__TOOLBARCONSTANT_WS_CLIPSIBLINGS, $__UDFGUICONSTANT_WS_VISIBLE)
    _SendMessage($hWnd, $TB_SETSTYLE, 0, $iStyle)
EndFunc   ;==>_GUICtrlToolbar_SetStyle

Func __GUICtrlToolbar_SetStyleEx($hWnd, $iStyle, $fStyle)
    Local $iN = _GUICtrlToolbar_GetStyle($hWnd)
    If $fStyle Then
        $iN = BitOR($iN, $iStyle)
    Else
        $iN = BitAND($iN, BitNOT($iStyle))
    EndIf
    Return _GUICtrlToolbar_SetStyle($hWnd, $iN)
EndFunc   ;==>__GUICtrlToolbar_SetStyleEx

Func _GUICtrlToolbar_SetStyleFlat($hWnd, $fState)
    Return __GUICtrlToolbar_SetStyleEx($hWnd, $TBSTYLE_FLAT, $fState)
EndFunc   ;==>_GUICtrlToolbar_SetStyleFlat

Func _GUICtrlToolbar_GetStyle($hWnd)
    If $Debug_TB Then __UDF_ValidateClassName($hWnd, $__TOOLBARCONSTANT_ClassName)

    Return _SendMessage($hWnd, $TB_GETSTYLE)
EndFunc   ;==>_GUICtrlToolbar_GetStyle

If I read this code correctly, _GuiCtrlToolbar_SetStyleFlat($hToolbar,True) would add the TBSTYLE_FLAT style to the styles already set, i.e. by _GuiCtrlToolbar_Create. But _Create defaults to setting TBSTYLE_FLAT (0x800). So the example in the help changes nothing! So I wonder why the author bothered to include the _GuiCtrlToolbar_SetStyleFlat UDF.

To me, reading MSDN Toolbar Control and Button Styles here, in the form for my styles script, TBSTYLE_FLAT, TBSTYLE_LIST and TBSTYLE_TRANSPARENT should be 3 radio buttons in a Group. So I would expect _GuiCtrlToolbar_SetStyleTransparent to do

$nuStyles = BitOR($TB_TRANSPARENT,BitAND($oldStyles,BitNOT(bitOR($TBSTYLE_FLAT,$TBSTYLE_LIST)))

but it is coded as:

Func _GUICtrlToolbar_SetStyleTransparent($hWnd, $fState)
    Return __GUICtrlToolbar_SetStyleEx($hWnd, $TBSTYLE_TRANSPARENT, $fState)
EndFunc   ;==>_GUICtrlToolbar_SetStyleTransparent

The Toolbar in the example for _GUICtrlToolbar_SetStyleTransparent has both styles: TBSTYLE_FLAT and TBSTYLE_TRANSPARENT! When I run this example, I think I realize that TBSTYLE_FLAT, TBSTYLE_TRANSPARENT and TBSTYLE_LIST should not be a group of radio buttons.Perhaps TBSTYLE_FLAT is the basic style: toolbar and buttons transparent, hot-tracking enabled, and text under the icons. Perhaps one can then add either TBSTYLE_LIST (text moves to to the right of icon) or TB_STYLETRANSPARENT (buttons cease to be transparent). If this idea is correct, MSDN is wrong (not the first time!) and _GuiCtrlToolbar_SetStyleFlat should never be called with False as the second parameter.

Any thoughts?

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

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