8 posts in this topic
I have a working program currently driven largely through menu selections. I would like to add a toolbar where most of the tollbar button actions are basically the same as menu items, but quicker to access. I have been wading around in toolbar examples, MSDN pages etc, it's clearly going to be a bit of a slog to get everything right, including tooltips etc. I thought I would start with something simple to prove the principle.
Using bits from the help file examples I have a small program that successfully displays a toolbar. However, what seemed like the most elegant way to deal with the button commands does not seem to work. My understanding was that a toolbar button fires a WM_COMMAND message, with the command Id set by the second parameter in the call to
_GUICtrlToolbar_AddButton ( $hWnd, $iID, $iImage)
so I though it would be a good idea to set this Id to the same value as my menu item Id; then it would run the same task which is what I wanted. This did not work. I am using message loop mode and would like to stick with this because some of my scripts run hardware at the same time as the gui; it is easier if I don't have to worry about code being interrupted with the hardware in an unknown state . So I added a handler for WM_COMMAND, with some cribbed display code to try and see why. The toolbar button defintely fired a WM_COMMAND message and the Id looked the same, so no explanation there.
I guess the issue is with GUIGetMsg() which may be constructed to ignore all but a limited number of control handles, i.e. those made with the GuiCtrlCreate... commands; this is speculation.
I would dearly love to find a tidy way to get around this. Having some controls handled in the message loop and some in a WM_COMMAND handler, performing the same task, feels ugly. I would be very grateful for further insight from someone experienced with handling a toolbar. Perhaps I should be trying to fire the menu item. I have attached a code snippet to try and illustrate the issue.
This is the info of the interface:
Title: Password Safe
Advanced (Class): [CLASS:ToolbarWindow32; INSTANCE:2]
1: 32003 Make New Database
2: 32002 Open Another Database
3: 32004 Close Database
4: 32005 Save Database
6: 32066 Copy Password to Clipboard
7: 32068 Copy Username to Clipboard
8: 32069 Copy Notes to Clipboard
9: 32065 Clear the clipboard contents
I wanted to click on 1: 32003 Make New Database. But unfortunately, I'm unable to click on that. Any help is much appreciated. Below are the code I tried:
$Title = "Password Safe" $Class = "[CLASS:ToolbarWindow32; INSTANCE:2]" WinWaitActive($Title) Sleep(500) Dim $hWnd = WinGetHandle($Title,"") Dim $hToolBar = ControlGetHandle($hWnd, '', $Class) ConsoleWrite($hWnd & @TAB & $hToolBar & @LF) _GUICtrlToolbar_ClickIndex($hToolBar, 32003)
I want to click on a button that is inside a custom ToolBar on a nonAutoIT created form. I've been using MouseClick but that fails if the toolbar is detached or if the form is resized.
There is no ID associated with the toolbar but there is a handle. I'm thinking that to get the handle I need a ControlID but that only gets me to the toolbar and I'd then need to have a way to identify the position of a button in order to click on it.
I'd found a discussion about identifying the position of a noname button by, I believe, it's Tip text back in December but I can't find it now. Memory is a bit fuzzy on how I even got to the topic because at the time I was searching for something else. I'll continue to search but if anyone has seen the topic, or knows of another solution could you please point me in that direction.
I'm working on a GUI that has 2 explorer windows embedded inside of it.
Eventually I'm going to put 4 explorer windows inside of the GUI since it's convenient to have 1 program opened with 4 explorer windows embedded inside it, than having 4 seperate explorer windows opened.
Anyway, I ran into some space problems. I'm trying to remove the icons/toolbar that appears on top of the explorer windows since they take up so much space. Here's a pic of what I mean:
Here's my code:
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Constants.au3> Opt("WinTitleMatchMode", 4) Global $hMigration, $hExplHolder, $hExplorer, $hExplorer2, $sStartDir = "C:\" Global $iWidth = 800, $iHeight = 400 ;Create the Explorer GUI $hExplHolder = GUICreate("Explorer", $iWidth, $iHeight, Default, Default) Run('explorer.exe /n, "' & $sStartDir & '"') WinWait("[CLASS:CabinetWClass]") ;Wait until the window appears WinSetState("[CLASS:CabinetWClass]","",@SW_HIDE) WinMove($hExplorer, "", 0, 0, 400, 400) $hExplorer = WinGetHandle("[CLASS:CabinetWClass]") Run('explorer.exe /n, "' & $sStartDir & '"') WinWait("[CLASS:CabinetWClass]") ;Wait until the window appears WinSetState("[CLASS:CabinetWClass]","",@SW_HIDE) WinMove($hExplorer2, "", 400, 0, 400, 400) $hExplorer2 = WinGetHandle("[CLASS:CabinetWClass]") ;WinSetState($hExplorer, "", @SW_HIDE) ;WinMove($hExplorer, "", 0, 0, 400, 400) ;WinSetState($hExplorer2, "", @SW_HIDE) ;WinMove($hExplorer2, "", 400, 0, 400, 400) _WinAPI_SetParent($hExplorer, $hExplHolder) ;Puts the explorer window inside the GUI _WinAPI_SetWindowLong($hExplorer, $GWL_STYLE, -1064828928) ;Minuses the x button in the windows explorer (I think?) _WinAPI_SetParent($hExplorer2, $hExplHolder) ;Puts the explorer window inside the GUI _WinAPI_SetWindowLong($hExplorer2, $GWL_STYLE, -1064828928) ;Minuses the x button in the windows explorer (I think?) ControlListView($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]", "ViewChange", "list") ControlListView($hExplorer2, "", "[CLASS:SysListView32; INSTANCE:1]", "ViewChange", "list") $hList = GUICtrlCreateListView ("File", $iWidth + 4, 4, 292, 200, 0x0003 + 0x0008 + 0x0004) GUICtrlSetState (-1, 8) WinSetState($hExplorer, "", @SW_SHOW) WinSetState($hExplorer2, "", @SW_SHOW) GUISetState(@SW_SHOW, $hExplHolder) While 1 $msg = GUIGetMsg() Switch $msg Case -3 Exit Case -13 GUICtrlCreateListViewItem (@GUI_DRAGFILE, $hList) EndSwitch WEnd How can I remove those top icons/toolbar so that there's more room for the file listing?
Edit: Extra props to whoever can make it so that the 2 explorer windows not do the brief flash before it disappears into the GUI.
Why the text it's not vertically aligned in toolbar control?
#include <GuiReBar.au3> #include <GuiToolbar.au3> #include <Constants.au3> Global Enum $Item1 = 1000, $Item2, $Item3 Local $hGUI = GUICreate('Example',450,300) Local $hRebar = _GUICtrlRebar_Create($hGUI, BitOR($RBS_FIXEDORDER,$CCS_NODIVIDER,$RBS_BANDBORDERS)) Local $hToolbar = _GUICtrlToolbar_Create($hGUI,$TBSTYLE_TRANSPARENT) _GUICtrlToolbar_AddString($hToolbar,'Item# 1') _GUICtrlToolbar_AddString($hToolbar,'Item# 2') _GUICtrlToolbar_AddString($hToolbar,'Item# 3') _GUICtrlToolbar_AddButton($hToolbar,$Item1,-2,0) _GUICtrlToolbar_AddButton($hToolbar,$Item1,-2,1) _GUICtrlToolbar_AddButton($hToolbar,$Item1,-2,2) _GUICtrlToolbar_SetButtonSize($hToolbar,32,150) _GUICtrlRebar_AddToolBarBand($hRebar,$hToolbar) GUISetState(@SW_SHOW,$hGUI) Do Sleep(10) Until GUIGetMsg() = -3 ; GUI_EVENT_CLOSE The code above will prodoce a window that will look like