Champak Posted March 4, 2008 Share Posted March 4, 2008 I have one menu that I want to show on two GUIs. I tried putting the menu in a function and calling it from each GUI, but that didn't work, and I don't want to make two separate menus. Is it possible to have one menu show up in two separate GUIs? I did a search for multiple gui/window, but I got nothing. Link to comment Share on other sites More sharing options...
GEOSoft Posted March 4, 2008 Share Posted March 4, 2008 I have one menu that I want to show on two GUIs. I tried putting the menu in a function and calling it from each GUI, but that didn't work, and I don't want to make two separate menus. Is it possible to have one menu show up in two separate GUIs? I did a search for multiple gui/window, but I got nothing.It sounds like your GUI should have been built with the second window as a child. Apart from that you can create your menu in a function which is in a separate au3 file (hereafter refered to as _Menu() and MyMenu.au3) in the script directory. Then at the top of the main script you use #Include "MyMenu.au3" The top line in MyMenu.au3 should be #Include-once. Then your main script will use $Main_GUI = GUICreate("Main") <Anysettings for the GUI like GUISetFont() or GUISetBKColor()> _Menu() $Sec_GUI = GUICreate("Secondary") <Anysettings for the GUI like GUISetFont() or GUISetBKColor()> _Menu() And the same _Menu() function will work even when it's not in a #included file. Just put it in the main script and make sure that you don't make any errors when calling it using the same method as shown in the code block above. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Champak Posted March 4, 2008 Author Share Posted March 4, 2008 (edited) The function way doesn't work...still. I should have been a little clearer with the function part, when I put the menu in a function, only the second GUI calling the function will have a working menu. The first GUI that called the menu wont have a working menu, and that is the same case when I put it in an include file. I put the _Menu() call both before and tried it after the GUISetState(). I'll look into the child GUI way now...but how exactly would that differ? Edited March 4, 2008 by Champak Link to comment Share on other sites More sharing options...
GEOSoft Posted March 4, 2008 Share Posted March 4, 2008 The function way doesn't work...still. I should have been a little clearer with the function part, when I put the menu in a function, only the second GUI calling the function will have a working menu. The first GUI that called the menu wont have a working menu, and that is the same case when I put it in an include file. I put the _Menu() call both before and tried it after the GUISetState(). I'll look into the child GUI way now...but how exactly would that differ?Then either you are calling it improperly or you are using a window style that will not allow a menu because it does work. I've done it many times. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Champak Posted March 4, 2008 Author Share Posted March 4, 2008 (edited) Here is a quick working example of what I'm doing. What am I doing wrong? The menu will only work on GUI2. expandcollapse popup#include <GUIConstants.au3> Global $menuButton $GUI1 = GUICreate('GUI1', 220, 120) $BUTTON1 = GUICtrlCreateButton("Switch",10,10,60,30) GUICtrlCreateLabel("Page 1", 10, 50, 50, 20) _Menu() GUISetState(@SW_HIDE) $GUI2 = GUICreate('GUI2', 220, 120) $BUTTON2 = GUICtrlCreateButton("Switch",10,10,60,30) GUICtrlCreateLabel("Page 2", 10, 50, 50, 20) _Menu() GUISetState(@SW_SHOW) Func _Menu() $menu = GUICtrlCreateMenu("Menu") $menuButton = GUICtrlCreateMenuItem("Test", $menu) EndFunc While 1 $msg = GUIGetMsg() Select Case $msg = $BUTTON1 GUISetState(@SW_SHOW, $GUI2) GUISetState(@SW_HIDE, $GUI1) Case $msg = $BUTTON2 GUISetState(@SW_SHOW, $GUI1) GUISetState(@SW_HIDE, $GUI2) Case $msg = $menuButton MsgBox(0,0,"Working") Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd Edited March 4, 2008 by Champak Link to comment Share on other sites More sharing options...
GEOSoft Posted March 4, 2008 Share Posted March 4, 2008 This is definitly one of those cases where using child windows would have been better. I'll work one up from your code in a while. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
GEOSoft Posted March 4, 2008 Share Posted March 4, 2008 Here you are expandcollapse popup#include <GUIConstants.au3> Global $menuButton, $WS_Child = 0x40000000 $Main_GUI = GUICreate("Main GUI", 220,120) _Menu() GUISetState() $GUI1 = GUICreate('GUI1', 220, 120, 0, 0, $WS_CHILD, -1, $Main_GUI) $BUTTON1 = GUICtrlCreateButton("Switch",10,10,60,30) GUICtrlCreateLabel("Page 1", 10, 50, 50, 20) $GUI2 = GUICreate('GUI2', 220, 120, 0, 0, $WS_CHILD, -1, $Main_GUI) $BUTTON2 = GUICtrlCreateButton("Switch",10,10,60,30) GUICtrlCreateLabel("Page 2", 10, 50, 50, 20) ; _Menu() GUISetState(@SW_HIDE, $GUI1) GUISetState(@SW_SHOW, $GUI2) While 1 $msg = GUIGetMsg() Select Case $msg = $BUTTON1 GUISetState(@SW_SHOW, $GUI2) GUISetState(@SW_HIDE, $GUI1) Case $msg = $BUTTON2 GUISetState(@SW_SHOW, $GUI1) GUISetState(@SW_HIDE, $GUI2) Case $msg = $menuButton MsgBox(0,0,"Working") Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd Func _Menu() $menu = GUICtrlCreateMenu("Menu") $menuButton = GUICtrlCreateMenuItem("Test", $menu) EndFunc George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Champak Posted March 4, 2008 Author Share Posted March 4, 2008 Thanks, it works great, I've never used child GUIs before, and I can pretty much see its uses now, but it seems that I will be unable to use it with what I want. I'm trying to incorporate it with the sliding toolbar, and since everything is within the parent window, the toolbar can't "slide out". So it seems that I will have to just make two menus then. Thanks anyway. Link to comment Share on other sites More sharing options...
GEOSoft Posted March 4, 2008 Share Posted March 4, 2008 (edited) Thanks, it works great, I've never used child GUIs before, and I can pretty much see its uses now, but it seems that I will be unable to use it with what I want. I'm trying to incorporate it with the sliding toolbar, and since everything is within the parent window, the toolbar can't "slide out". So it seems that I will have to just make two menus then. Thanks anyway.I wouldn't bet on that. Show a better example. I'm thinking that the Toolbar can be created as part of the Main GUI and then reposition the child windows. I would show you a better example of using child windows but the code has 25 windows and a lot of control code (619 controls)EDIT: Actually if you just post your Toolbar code I can probably work another example sometime today. Edited March 4, 2008 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Champak Posted March 5, 2008 Author Share Posted March 5, 2008 I believe I've put in all things that would/wouldn't affect the functionality of this. There are other GUIs that are a part of the script that wont be children, but they don't need to access the menu item, so I didn't include them in the example to keep everything short and sweet. expandcollapse popup#include <GUIConstants.au3> Global $menuButton, $menuExit;, $WS_Child = 0x40000000 $Main_GUI = GUICreate("Main GUI", 60,89, 0, 300,BitOr($WS_POPUP,$WS_BORDER), BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW)) WinSetTrans($Main_GUI, "",240) _Menu() GUISetState() $Slide1 = GUICreate("Sliding Toolbar", 600, 85, 0, 0, BitOr($WS_CHILD,$WS_BORDER), BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW),$Main_GUI) $Show = GUICtrlCreateButton(">", 2, 4, 55, 60, BitOR($BS_CENTER, $BS_FLAT)) GuiSetState(@SW_SHOW) $Slide2 = GUICreate("Sliding Toolbar", 60, 85, 0, 0, BitOr($WS_CHILD,$WS_BORDER), BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW),$Main_GUI) $Button1 = GUICtrlCreateButton("Btn 1", 20, 35, 73, 41) GUICtrlCreateLabel("Button 1", 28, 6, 60, 28, $SS_CENTER) $Button2 = GUICtrlCreateButton("Btn 2", 100, 35, 73, 41) GUICtrlCreateLabel("Button 2", 108, 6, 60, 28, $SS_CENTER) $Button3 = GUICtrlCreateButton("Btn 3", 180, 35, 73, 41) GUICtrlCreateLabel("Button 3", 194, 6, 43, 17) $Button4 = GUICtrlCreateButton("Btn 4", 260, 35, 73, 41) GUICtrlCreateLabel("Button 4", 280, 6, 75, 17) $Button5 = GUICtrlCreateButton("Btn 5", 340, 35, 73, 41) GUICtrlCreateLabel("Button 5", 350, 6, 75, 17) $Button6 = GUICtrlCreateButton("Btn 6", 420, 35, 73, 41) GUICtrlCreateLabel("Button 6", 436, 6, 40, 17) $Hide = GUICtrlCreateButton("<", 542, 4, 55, 60, BitOR($BS_CENTER, $BS_FLAT)) GuiSetState(@SW_HIDE) Func _Menu() $menu = GUICtrlCreateMenu("Menu") $menuButton = GUICtrlCreateMenuItem("Test", $menu) $menuExit = GUICtrlCreateMenuItem("Exit", $menu) EndFunc While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Show Slide_in() Case $msg = $Hide Slide_out() Case $msg = $menuButton MsgBox(0,0,"Working") Case $msg = $menuExit Exit EndSelect WEnd Func Slide_in() DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Slide1, "int", 0, "long", 0x00050002);slide out to left DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Slide2, "int", 625, "long", 0x00040001);slide in from left GuiSetState(@SW_SHOW,$Slide2) EndFunc ;==>Slide_in Func Slide_out() DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Slide2, "int", 625, "long", 0x00050002);slide out to left DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Slide1, "int", 0, "long", 0x00040001);slide in from left GuiSetState(@SW_SHOW,$Slide1) EndFunc ;==>Slide_out Link to comment Share on other sites More sharing options...
GEOSoft Posted March 5, 2008 Share Posted March 5, 2008 It's getting late so I'll work at it tomorrow. It won't look like that when you get it back. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Champak Posted March 5, 2008 Author Share Posted March 5, 2008 That's cool, anything you can do to help. Thanks. Link to comment Share on other sites More sharing options...
ReFran Posted March 5, 2008 Share Posted March 5, 2008 Hi,your code remember me to this: http://www.autoitscript.com/forum/index.ph...t=0&start=0HTH, Reinhard Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now