Vegar Posted January 5, 2009 Share Posted January 5, 2009 (edited) hello ... i'm trying to make a clock in a "GuiCtrlCreateMenu", but the clock just freezes, is there any way to prewent this`? $n=GUICtrlCreateDate ( "", 20, 20, 100, 20, $DTS_TIMEFORMAT) GuiCtrlCreateMenu (" " & GUICtrlRead($n)) Edited January 5, 2009 by Vegar Link to comment Share on other sites More sharing options...
rover Posted January 5, 2009 Share Posted January 5, 2009 (edited) the GUICtrlCreateDate() control requires updating, otherwise it remains at the time set on control creation.why do you want the time in a menu bar header?anyway this rough modified example from the help files for timers and menu should give you something to work with.post an example script demonstrating your method.Edit missed the timer callback function when copy/pasting, my apologiesexpandcollapse popup#include <GUIConstantsEx.au3> #include <DateTimeConstants.au3> #include <Timers.au3> Opt('MustDeclareVars', 1) Global $hGUI, $cMenu Example1() Func Example1() Local $msg, $filemenu, $openitem, $helpmenu $hGUI = GUICreate("Select 'File' menu item 'Open'", 400, 200) $filemenu = GUICtrlCreateMenu("&File") $openitem = GUICtrlCreateMenuItem("Open", $filemenu) GUICtrlCreateMenu("?") GUICtrlCreateMenuItem("Save", $filemenu) GUICtrlCreateMenuItem("Info", $helpmenu) GUICtrlCreateMenuItem("Exit", $filemenu) GUICtrlCreateMenu("Recent Files", $filemenu, 1) $cMenu = GuiCtrlCreateMenu(" " & StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC)) _Timer_SetTimer($hGUI, 1000, "_UpdateMenuClock"); create timer GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Switch $msg Case $openitem MsgBox(262144,"Messageloop block test","See how the clock is still working?", 0, $hGUI) Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd EndFunc ; call back function Func _UpdateMenuClock($hWnd, $Msg, $iIDTimer, $dwTime) #forceref $hWnd, $Msg, $iIDTimer, $dwTime GUICtrlSetData($cMenu, " " & StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC)) EndFunc ;==>_UpdateMenuClock Edited January 6, 2009 by rover I see fascists... Link to comment Share on other sites More sharing options...
Vegar Posted January 6, 2009 Author Share Posted January 6, 2009 (edited) I get som kind of error: Badly formatted "Func" statement.: $hCallBack = DllCallbackRegister($sTimerFunc, "none", "hwnd;int;int;dword") Edited January 6, 2009 by Vegar Link to comment Share on other sites More sharing options...
Malkey Posted January 6, 2009 Share Posted January 6, 2009 I get som kind of error: Badly formatted "Func" statement.: $hCallBack = DllCallbackRegister($sTimerFunc, "none", "hwnd;int;int;dword")Here is a rover's working example I experimented with. expandcollapse popup#include <GUIConstantsEx.au3> #include <DateTimeConstants.au3> #include <Timers.au3> #Include <Date.au3> Opt('MustDeclareVars', 1) Global $hGUI, $cMenu, $hLabel Example1() Func Example1() Local $msg, $filemenu, $openitem, $helpmenu, $cMenuSaveItem $hGUI = GUICreate("Select 'File' menu item 'Open'", 400, 200) $filemenu = GUICtrlCreateMenu("&File") $openitem = GUICtrlCreateMenuItem("Open", $filemenu) ;GUICtrlCreateMenu("?") GUICtrlCreateMenuItem("Save", $filemenu) GUICtrlCreateMenuItem("Info", $helpmenu) GUICtrlCreateMenuItem("Exit", $filemenu) GUICtrlCreateMenu("Recent Files", $filemenu, 1) $cMenu = GuiCtrlCreateMenu("Time ") $cMenuSaveItem = GUICtrlCreateMenuItem("Save", $cMenu) $hLabel = GUICtrlCreateLabel("Time ",10,160,180,20) _Timer_SetTimer($hGUI, 1000, "_UpdateMenuClock"); create timer GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Switch $msg Case $openitem MsgBox(262144,"Messageloop block test","See how the clock is still working?", 0, $hGUI) Case $cMenuSaveItem MsgBox(262144,"Messageloop Save Item test","See how the clock is still working?", 0, $hGUI) Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd EndFunc func _UpdateMenuClock($hWnd, $Msg, $iIDTimer, $dwTime) GUICtrlSetData ( $cMenu, _DateDayOfWeek( @WDAY, 0 ) & ", " & _now()) GUICtrlSetData ( $hLabel, _DateDayOfWeek( @WDAY, 0 ) & ", " & _now()) return EndFunc Link to comment Share on other sites More sharing options...
charvi Posted January 6, 2009 Share Posted January 6, 2009 Excellent, Malkey ! I'm sure Vegar will be happy ! I'm happy too ! But now, can I right align the clock on the menu bar -- for aesthetic reasons -- ? Cheers, Charvi Link to comment Share on other sites More sharing options...
rover Posted January 6, 2009 Share Posted January 6, 2009 Thanks Malkey It would have helped if I hadn't missed the timer callback function when copying to the clipboard corrected my post above. I see fascists... Link to comment Share on other sites More sharing options...
charvi Posted January 6, 2009 Share Posted January 6, 2009 (edited) Thanks Malkey It would have helped if I hadn't missed the timer callback function when copying to the clipboard corrected my post above.@rover To forget is human It happens often to me too... Anyway, I made a little addition to your script to right align the clock on the menubar, with spaces (it's the easiest way I think). On my system, with the dialog you defined, the maximum allowed is 95 before the menubar has a double height. Is there a way to get the value 95 programmatically? Because every menu and dialog is different... Cheers, Charvi EDIT: forgot to add the script - you see, it happens... (what a coincidence that it happens just now!) expandcollapse popup#include <GUIConstantsEx.au3> #include <DateTimeConstants.au3> #include <Timers.au3> #include <String.au3> Opt('MustDeclareVars', 1) Global $hGUI, $cMenu Example1() Func Example1() Local $msg, $filemenu, $openitem, $helpmenu $hGUI = GUICreate("Select 'File' menu item 'Open'", 400, 200) $filemenu = GUICtrlCreateMenu("&File") $openitem = GUICtrlCreateMenuItem("Open", $filemenu) GUICtrlCreateMenu("?") GUICtrlCreateMenuItem("Save", $filemenu) GUICtrlCreateMenuItem("Info", $helpmenu) GUICtrlCreateMenuItem("Exit", $filemenu) GUICtrlCreateMenu("Recent Files", $filemenu, 1) $cMenu = GuiCtrlCreateMenu(_StringRepeat(" ", 95) & StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC)) _Timer_SetTimer($hGUI, 1000, "_UpdateMenuClock"); create timer GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Switch $msg Case $openitem MsgBox(262144,"Messageloop block test","See how the clock is still working?", 0, $hGUI) Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd EndFunc ; call back function Func _UpdateMenuClock($hWnd, $Msg, $iIDTimer, $dwTime) #forceref $hWnd, $Msg, $iIDTimer, $dwTime GUICtrlSetData($cMenu, _StringRepeat(" ", 95) & StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC)) EndFunc;==>_UpdateMenuClock Edited January 6, 2009 by charvi Link to comment Share on other sites More sharing options...
youknowwho4eva Posted January 6, 2009 Share Posted January 6, 2009 (edited) did you compensate for the extra digit for the hours of 10 11 and 12? or will they extend the menu bar, or cut it off. Edit: I really like how the clock keeps ticking... I'm going to have to use that. Edited January 6, 2009 by youknowwho4eva Giggity Link to comment Share on other sites More sharing options...
rover Posted January 6, 2009 Share Posted January 6, 2009 (edited) @charviI addressed the OP's issue at hand with the menubar clock and didn't bother to change the right-justifying spaces in the code posted.this next example illustrates the proper way to do it.@youknowwho4evausing Stringformat() sets padding for digits@Vegar, Allmenubar with right justified clock menu itemlook at Malkeys example, the help file, Date.au3 and forum examples for time/date formatting of your choicesubclassing or message processing would be needed to eliminate the mouseover highlite of the clock.probably an example somewhere on the forum of this already...see also time in StatusBar example in helpfile for _Timer_SetTimer()Edit added missing _Timer_KillAllTimers($hGUI)expandcollapse popup#include <GUIConstantsEx.au3> #include <DateTimeConstants.au3> #include <Timers.au3> #include <String.au3> #include <GuiMenu.au3> Opt('MustDeclareVars', 1) Global $hGUI, $hMenu, $cMenu MenuBarClock() Func MenuBarClock() Local $msg, $filemenu, $openitem, $helpmenu, $iMenuCnt, $cMenuTimeItem $hGUI = GUICreate("Select 'File' menu item 'Open' or select clock item", 400, 200) $filemenu = GUICtrlCreateMenu("&File") $openitem = GUICtrlCreateMenuItem("Open", $filemenu) GUICtrlCreateMenu("Recent Files", $filemenu, 1) GUICtrlCreateMenuItem("Save", $filemenu) GUICtrlCreateMenuItem("Exit", $filemenu) $helpmenu = GUICtrlCreateMenu("?") GUICtrlCreateMenuItem("Info", $helpmenu) $cMenu = GUICtrlCreateMenu(StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC)) $cMenuTimeItem = GUICtrlCreateMenuItem("Set Time", $cMenu) $hMenu = _GUICtrlMenu_GetMenu($hGUI) $iMenuCnt = _GUICtrlMenu_GetItemCount($hMenu) _GUICtrlMenu_SetItemType($hMenu, ($iMenuCnt - 1), $MFT_RIGHTJUSTIFY, True) _Timer_SetTimer($hGUI, 1000, "_UpdateMenuClock"); create timer GUISetState() Sleep(2000) Beep(1000, 5) GUICtrlCreateMenu("Add menu item test", -1, 2); if menu position not used, menu item would be added after clock While 1 $msg = GUIGetMsg() Switch $msg Case $openitem, $cMenuTimeItem MsgBox(262144, "Messageloop block test", "See how the clock is still working?", 0, $hGUI) Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd EndFunc ;==>MenuBarClock ; call back function Func _UpdateMenuClock($hWnd, $msg, $iIDTimer, $dwTime) #forceref $hWnd, $Msg, $iIDTimer, $dwTime GUICtrlSetData($cMenu, StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC)) EndFunc ;==>_UpdateMenuClock Edited January 6, 2009 by rover I see fascists... Link to comment Share on other sites More sharing options...
charvi Posted January 6, 2009 Share Posted January 6, 2009 Really good, it looks perfect. Many thanks, Rover. Link to comment Share on other sites More sharing options...
rover Posted January 6, 2009 Share Posted January 6, 2009 Really good, it looks perfect. Many thanks, Rover.thanksI should add you can use AdlibEnable()/AdlibDisable()instead of the timers UDF.I prefer the timers UDF.over to Vegar now I see fascists... Link to comment Share on other sites More sharing options...
Vegar Posted January 6, 2009 Author Share Posted January 6, 2009 Very Nice Exactly what i needed Perfect Link to comment Share on other sites More sharing options...
rover Posted January 7, 2009 Share Posted January 7, 2009 thanks Vegar glad it works for you Cheers I see fascists... 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