Jump to content

ToolBar


tonedeaf
 Share

Recommended Posts

  • 2 months later...
  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

The CCS_TOP and CCS_BOTTOM common control styles determine whether the toolbar is positioned along the top or bottom of the client area. By default, a toolbar has the CCS_TOP style.

The following places it at the bottom

#include "GuiToolbar.au3"
Opt("MustDeclareVars", 1)

Global Const $DebugIt = 1

Global Const $WM_NOTIFY = 0x4E

Global Const $IDM_NEW = 2001

Global Const $CCS_BOTTOM = 0x3

Global $iItem ; Command identifier of the button associated with the notification.

Global $mnuFile, $mnuEdit, $h_ToolBar, $h_Rebar, $mnuExit, $button
Global $h_ToolBar, $h_ToolBar1 ; only needs to be global if using wm_command
Global $IDM_OPEN, $IDM_SAVE, $IDM_CUT, $IDM_COPY, $IDM_PASTE, $IDM_UNDO, $IDM_REDO

_Main()

Func _Main()
   Local $msg, $hgui, $hReBar
   
   $hgui = GUICreate("ToolBar Example", 300, 150, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX, $WS_MAXIMIZEBOX))
   
   $mnuFile = GUICtrlCreateMenu("&File")
   $IDM_OPEN = GUICtrlCreateMenuItem("Open", $mnuFile)
   $IDM_SAVE = GUICtrlCreateMenuItem("Save", $mnuFile)
   GUICtrlCreateMenuItem("", $mnuFile, 2)    ; create a separator line
   $mnuExit = GUICtrlCreateMenuItem("Exit", $mnuFile)
   $mnuEdit = GUICtrlCreateMenu("&Edit")
   $IDM_CUT = GUICtrlCreateMenuItem("Cut", $mnuEdit)
   $IDM_COPY = GUICtrlCreateMenuItem("Copy", $mnuEdit)
   $IDM_PASTE = GUICtrlCreateMenuItem("Paste", $mnuEdit)
   GUICtrlCreateMenuItem("", $mnuEdit, 3)    ; create a separator line
   $IDM_UNDO = GUICtrlCreateMenuItem("Undo", $mnuEdit)
   $IDM_REDO = GUICtrlCreateMenuItem("Redo", $mnuEdit)
   
   $h_ToolBar = _GuiCtrlToolBarCreate ($hgui, BitOR($TBSTYLE_FLAT,$CCS_BOTTOM))
   _GuiCtrlToolBarAddStandardButton ($h_ToolBar, $IDM_NEW, $STD_FILENEW,1)
   _GuiCtrlToolBarAddStandardButton ($h_ToolBar, $IDM_OPEN, $STD_FILEOPEN,1)
   _GuiCtrlToolBarAddStandardButton ($h_ToolBar, $IDM_SAVE, $STD_FILESAVE,1)
   _GuiCtrlToolBarAddSeparator ($h_ToolBar)
   _GuiCtrlToolBarAddStandardButton ($h_ToolBar, $IDM_CUT, $STD_CUT,1)
   _GuiCtrlToolBarAddStandardButton ($h_ToolBar, $IDM_COPY, $STD_COPY,1)
   _GuiCtrlToolBarAddStandardButton ($h_ToolBar, $IDM_PASTE, $STD_PASTE,1)
   _GuiCtrlToolBarAddSeparator ($h_ToolBar)
   _GuiCtrlToolBarAddStandardButton ($h_ToolBar, $IDM_UNDO, $STD_UNDO,1)
   _GuiCtrlToolBarAddStandardButton ($h_ToolBar, $IDM_REDO, $STD_REDOW,1)

   $button = GUICtrlCreateButton("Exit", 100, 50, 100, 25)
   
   GUISetState(@SW_SHOW)
   ;Register WM_NOTIFY  events
   GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY_Events")
   
   While 1
      $msg = GUIGetMsg()
      
      Select
         
         Case $msg = $GUI_EVENT_CLOSE Or $msg = $button ; controls commands don't work here if using wm_command
            ;----------------------------------------------------------------------------------------------
            If $DebugIt Then    ConsoleWrite (_DebugHeader("Exit From Main"))
            ;----------------------------------------------------------------------------------------------
            Exit
            
      EndSelect
   WEnd
EndFunc   ;==>_Main

Func _DebugHeader($s_text)
   Return _
         "!===========================================================" & @LF & _
         "+===========================================================" & @LF & _
         "-->" & $s_text & @LF & _
         "+===========================================================" & @LF
EndFunc   ;==>_DebugHeader

Func ToolBar_Click($index)
   Switch $index
      Case 0
         ;----------------------------------------------------------------------------------------------
            If $DebugIt Then    ConsoleWrite (_DebugHeader("ToolBar NEW Selected"))
         ;----------------------------------------------------------------------------------------------
      Case 1
         ;----------------------------------------------------------------------------------------------
            If $DebugIt Then    ConsoleWrite (_DebugHeader("ToolBar OPEN Selected"))
         ;----------------------------------------------------------------------------------------------
      Case 2
         ;----------------------------------------------------------------------------------------------
            If $DebugIt Then    ConsoleWrite (_DebugHeader("ToolBar SAVE Selected"))
         ;----------------------------------------------------------------------------------------------
      Case 3, 7 ; not used
      Case 4
         ;----------------------------------------------------------------------------------------------
            If $DebugIt Then    ConsoleWrite (_DebugHeader("ToolBar CUT Selected"))
         ;----------------------------------------------------------------------------------------------
      Case 5
         ;----------------------------------------------------------------------------------------------
            If $DebugIt Then    ConsoleWrite (_DebugHeader("ToolBar COPY Selected"))
         ;----------------------------------------------------------------------------------------------
      Case 6
         ;----------------------------------------------------------------------------------------------
            If $DebugIt Then    ConsoleWrite (_DebugHeader("ToolBar PASTE Selected"))
         ;----------------------------------------------------------------------------------------------
      Case 8
         ;----------------------------------------------------------------------------------------------
            If $DebugIt Then    ConsoleWrite (_DebugHeader("ToolBar UNDO Selected"))
         ;----------------------------------------------------------------------------------------------
      Case 9
         ;----------------------------------------------------------------------------------------------
            If $DebugIt Then    ConsoleWrite (_DebugHeader("ToolBar REDO Selected"))
         ;----------------------------------------------------------------------------------------------
   EndSwitch
EndFunc   ;==>ToolBar_Click

Func _HiWord($x)
   Return BitShift($x, 16)
EndFunc   ;==>_HiWord

Func _LoWord($x)
   Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord

; convert the command to an index from the toolbar
Func _ToolBar_GetIndex($h_control, $control_id)
   Local $index = DllCall("user32.dll", "int", "SendMessage", "int", $h_control, "int", $TB_COMMANDTOINDEX, "int", $control_id, "int", 0)
   If Not @error Then
      Return $index[0]
   Else
      Return -1
   EndIf
EndFunc   ;==>_ToolBar_GetIndex

Func WM_NOTIFY_Events($hWndGUI, $MsgID, $wParam, $lParam)
   #forceref $hWndGUI, $MsgID
   Local $nmhdr, $hwndFrom, $idFrom, $code, $tagNMTOOLBAR
   
   $nmhdr = DllStructCreate("int;int;int", $lParam)
   $hwndFrom = DllStructGetData($nmhdr, 1)
   $idFrom = DllStructGetData($nmhdr, 2)
   $code = DllStructGetData($nmhdr, 3)
   Switch $code
      ;----------------------------------------------------------------------------------------------
      ; NMHDR STRUCTURED
      ;----------------------------------------------------------------------------------------------
      Case $NM_LDOWN
         ;----------------------------------------------------------------------------------------------
            If $DebugIt Then    ConsoleWrite (_DebugHeader("$NM_LDOWN"))
         ;----------------------------------------------------------------------------------------------
         Switch $iItem
            Case $IDM_NEW, $IDM_OPEN, $IDM_SAVE, $IDM_CUT, $IDM_COPY, $IDM_PASTE, $IDM_UNDO, $IDM_REDO
               ToolBar_Click(_ToolBar_GetIndex($h_ToolBar, $iItem))
         EndSwitch
        Case $TBN_BEGINDRAG
            $tagNMTOOLBAR = DllStructCreate("int;int;int;int", $lParam)
            $iItem = DllStructGetData($tagNMTOOLBAR, 4)
   EndSwitch
EndFunc   ;==>WM_NOTIFY_Events
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

$h_ToolBar = _GuiCtrlToolBarCreate ($hgui, BitOR($TBSTYLE_FLAT,$CCS_BOTTOM))

Not sure what the logic is for $CCS_BOTTOM=3? How can I have the tool bar in the my gui at x=500 & y=600?

Gary, can you also help me out with the listview colors being cleared after sorting the listview?

Link to comment
Share on other sites

The following quote is from MSDN

The CCS_TOP and CCS_BOTTOM common control styles determine whether the toolbar is positioned along the top or bottom of the client area. By default, a toolbar has the CCS_TOP style.

As to the sort, you might want to look at GUICtrlRegisterListViewSort function for sorting.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

How to resize toolbar/rebar on $GUI_EVENT_RESIZED event?

for a toolbar only

Case $msg = $GUI_EVENT_RESIZED
                DllCall("user32.dll","int","SendMessage","hwnd", $h_ToolBar, "int", $TB_AUTOSIZE, "int", 0, "int", 0)

not sure how for a rebar yet.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Local Const $RBS_AUTOSIZE = 0x2000

   $hReBar = _GuiCtrlReBarCreate ($hgui, $RBS_AUTOSIZE)
oÝ÷ Ù«­¢+Ø($$%
ÍÀÌØíµÍôÀÌØíU%}Y9Q}IM%i($$$%1½°ÀÌØíÁ½Ìô]¥¹ÑA½Ì ÀÌØí¡Õ¤¤($$$%1½°ÀÌØíÁ½ÌÈô]¥¹ÑA½Ì¡!]¹ ÀÌØí¡I    Ȥ¤($$$%]¥¹5½Ù¡!]¹ ÀÌØí¡I Ȥ°ÅÕ½ÐìÅÕ½Ðì°À°À°ÀÌØíÁ½ÍlÉt°ÀÌØíÁ½ÌÉlÍt¤(

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Whats that?:

CODE
C:\Programme\AutoIt3\Include\GuiToolBar.au3(36,30) : ERROR: $WM_USER previously declared as a 'Const'

Global Const $WM_USER = 0x400

Comment that line out, the files haven't been updated since $WM_USER was added to one of the standard includes.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Thank you very much Gary. Both examples (toolbar and rebar resizing) work very nice. Why do not propose to add the ToolBar UDF to the AutoIt package?

All the best

Peppe

1. I still think there are issues to work out

2. Have to register WM_COMMAND to use this, If some other control needs to register WM_COMMAND then you have to figure out how to support the other controls dynamically.

Think it'll just stay in scripts and scraps just like the GuiHyperLink

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Another question:

is it possible to enable/disable single toolbar buttons?

Thanks

Peppe

MsgBox(0,"Test",_SendMessage($h_ToolBar,$TB_GETSTATE, $IDM_OPEN))
    _SendMessage($h_ToolBar,$TB_ENABLEBUTTON,$IDM_OPEN,False)
    MsgBox(0,"Test",_SendMessage($h_ToolBar,$TB_GETSTATE, $IDM_OPEN))

if your going to disable buttons you'll have to add checks into the event function for this.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

MsgBox(0,"Test",_SendMessage($h_ToolBar,$TB_GETSTATE, $IDM_OPEN))
    _SendMessage($h_ToolBar,$TB_ENABLEBUTTON,$IDM_OPEN,False)
    MsgBox(0,"Test",_SendMessage($h_ToolBar,$TB_GETSTATE, $IDM_OPEN))

if your going to disable buttons you'll have to add checks into the event function for this.

Thanks again. You're the best GUI AutoIt programmer!

Best regards

Peppe

Link to comment
Share on other sites

Thanks again. You're the best GUI AutoIt programmer!

Best regards

Peppe

Forgot to tell you the Standard SendMessage Dllcall is in a Wrapper in the Misc.au3 file you can find it in the help

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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