liteswap Posted May 1, 2009 Share Posted May 1, 2009 (edited) Here's an oddity I can't find a solution to - and the function description says it all. Essentially, the button works with the keyboard but not with the mouse. Odd... expandcollapse popup$handle = _ToggleFormWithStop(0,"This is a test message") Exit ;**************************************************************** ;~ Name: _ToggleFormWithStop() ;~ Description: Toggles a small form with a stop button on and off ;~ Parameters: $handle - used to pass GUI handle back ;~ to the form when deleting or hiding it ;~ $msg - Message text to be displayed ;~ $sTitle - Title text for the window ;~ Usage: Send a zero handle and text when initiating the form ;~ and just the handle to hide it ;~ Returns: Handle to the form window ;~ Author: Manek Dubash (c) 2009 ;~ Notes: The STOP button works with the keyboard (eg space bar) ;~ but NOT when you click it with the mouse. Weird... ;**************************************************************** Func _ToggleFormWithStop($handle = 0, $sMessage = "", $sTitle = "") Local $nLongestString = StringLen($sMessage), $nCount = 0, $nMsg, $StopButton ; analyse message string:- ; find how many lines by counting carrage returns for $boxheight ; find longest string between @CRs for $boxwidth For $n = 1 To StringLen($sMessage) If StringMid($sMessage, $n, 1) = @CR Or StringMid($sMessage, $n, 1) = @CRLF Then $nCount += 1; count the carriage returns If $nLongestString < $n - $nLongestString Then $nLongestString = $n - $nLongestString; find longest string EndIf Next Local $boxwidth = _Min($nLongestString * 5.5, @DesktopWidth - 100), $boxheight = 85 + (15 * $nCount) If $handle = 0 Then; this is the first time the function's been called so fire up the text box $handle = GUICreate($sTitle, $boxwidth, $boxheight, @DesktopWidth / 12, @DesktopHeight / 12, $WS_CAPTION, $WS_EX_TOPMOST) GUICtrlCreateLabel($sMessage, 15, 16, $boxwidth - 10, $boxheight - 25) $StopButton = GUICtrlCreateButton("Stop", $boxwidth / 2 - 37, $boxheight - 37, 75) ;~ _GUICtrlButton_SetFocus($StopButton, True); not required GUISetState() While GUIGetMsg() <> $StopButton; keep looping until the button is pressed Sleep(50); don't hog the CPU WEnd GUIDelete(); kill the GUI Return 1; NB: also a True value Else; if function called with previously returned handle as parameter, kill the GUI GUIDelete($handle) EndIf Return $handle EndFunc ;==>_ToggleFormWithStop Thanks for any input as to how I could resolve this. Edited May 1, 2009 by liteswap Link to comment Share on other sites More sharing options...
CodyBarrett Posted May 1, 2009 Share Posted May 1, 2009 idk.. is your label covering up the button? i cannot test it Right now as i do not have scite on this computer [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
liteswap Posted May 1, 2009 Author Share Posted May 1, 2009 idk.. is your label covering up the button? i cannot test it Right now as i do not have scite on this computerNo, the button is completely visible, and has focus: hitting the space bar activates it - but clicking it with the mouse results in zero response. Weird, no? Link to comment Share on other sites More sharing options...
Yashied Posted May 1, 2009 Share Posted May 1, 2009 It would be nice if you provide ready to run a script, not just function.Add GUICtrlSetBkColor(-1, 0xAAAAAA) after GUICtrlCreateLabel() and you own everything you see. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
liteswap Posted May 1, 2009 Author Share Posted May 1, 2009 It would be nice if you provide ready to run a script, not just function.Add GUICtrlSetBkColor(-1, 0xAAAAAA) after GUICtrlCreateLabel() and you own everything you see.OK duly edited (you needed only to call the function....) to run as is. Link to comment Share on other sites More sharing options...
liteswap Posted May 1, 2009 Author Share Posted May 1, 2009 OK duly edited (you needed only to call the function....) to run as is....and fixed. Thank you for the hint with the label colour. A blank section of the label was covering the button - I hadn't checked that it was too big. @CodyBarrett - apologies - you were spot on. Link to comment Share on other sites More sharing options...
Yashied Posted May 1, 2009 Share Posted May 1, 2009 OK duly edited (you needed only to call the function....) to run as is.... and add follows. #Include <Math.au3> #Include <WindowsConstants.au3> In this case, people may find it easier and faster to help you. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Valuater Posted May 1, 2009 Share Posted May 1, 2009 ... and add follows. #Include <Math.au3> #Include <WindowsConstants.au3> In this case, people may find it easier and faster to help you. I agree, from the code above I saw this.... >09:06:48 Starting AutoIt3Wrapper v.1.10.1.14 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 3 CPU:X86 ANSI) >Running AU3Check (1.54.14.0) from:C:\Program Files\AutoIt3 C:\Program Files\AutoIt3\Examples\My Stuff\Test.au3(31,113) : WARNING: $WS_CAPTION: possibly used before declaration. $handle = GUICreate($sTitle, $boxwidth, $boxheight, @DesktopWidth / 12, @DesktopHeight / 12, $WS_CAPTION, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\Test.au3(31,129) : WARNING: $WS_EX_TOPMOST: possibly used before declaration. $handle = GUICreate($sTitle, $boxwidth, $boxheight, @DesktopWidth / 12, @DesktopHeight / 12, $WS_CAPTION, $WS_EX_TOPMOST) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\Test.au3(31,113) : ERROR: $WS_CAPTION: undeclared global variable. $handle = GUICreate($sTitle, $boxwidth, $boxheight, @DesktopWidth / 12, @DesktopHeight / 12, $WS_CAPTION, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\Test.au3(29,70) : ERROR: _Min(): undefined function. Local $boxwidth = _Min($nLongestString * 5.5, @DesktopWidth - 100) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Program Files\AutoIt3\Examples\My Stuff\Test.au3 - 2 error(s), 2 warning(s) !>09:06:48 AU3Check ended.rc:2 +>09:06:53 AutoIt3Wrapper Finished >Exit code: 0 Time: 5.622 And I decided NOT to help 8) Link to comment Share on other sites More sharing options...
Authenticity Posted May 1, 2009 Share Posted May 1, 2009 (edited) Indeed, it's the overlapping label control... ;]Change it to not overlap or call it after creating the button control:$StopButton = GUICtrlCreateButton("Stop", $boxwidth / 2 - 37, $boxheight - 37, 75) GUICtrlCreateLabel($sMessage, 15, 16, $boxwidth - 10, $boxheight - 25)Edit: Sigh, ugly way...Just change it to not overlap. By the way, you can use GetTextExtentPoint32 to calculate the width and height of the string according to the selected font of the specified HDC. Edited May 1, 2009 by Authenticity Link to comment Share on other sites More sharing options...
Valuater Posted May 1, 2009 Share Posted May 1, 2009 idk.. is your label covering up the button? i cannot test it Right now as i do not have scite on this computerLooks like you called it from the start Cody!!8) Link to comment Share on other sites More sharing options...
GEOSoft Posted May 1, 2009 Share Posted May 1, 2009 (edited) ...and fixed. Thank you for the hint with the label colour. A blank section of the label was covering the button - I hadn't checked that it was too big. @CodyBarrett - apologies - you were spot on.TIP: When Creating Labels Use a background color for the label (or any static control) until you are sure that you have it positioned properly $Frm_main = GUICreate("My Test Form") $My_Label = GUICtrlCreateLabel("My Label", 10, 30, 120, 50) GUICtrlSetBkColor(-1, 0xFFFF00) $Btn = GUICtrlCreateButton("My Button", 120, 30, 60, 25) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case -3, $Btn Exit Case Else EndSwitch Wend Also don't forget that when you set sizes by character or line count you will be wrong if the user has large fonts set. Make sure you specify the font size and face. Authenticitys idea is better. Edited May 1, 2009 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...
GEOSoft Posted May 1, 2009 Share Posted May 1, 2009 (edited) One more thing. Here are a couple of functions you might like if you insist on setting control sizes by the text character and line counts. I have not made headers for them but they are pretty easy to figure out if you just follow the example. expandcollapse popup;$sFile = ClipGet() $sFile = @ScriptFullPath $Count = _String_CountLines($sFile) MsgBox(0, "Line Count", $Count & " Lines") $Longest = _String_LongestLine($sFile) If NOT @Error Then If IsArray($Longest) Then MsgBox(0, "Longest String", "Character Count = " & $Longest[0] & @CRLF & @CRLF & $Longest[1]) Else MsgBox(0, "Longest String", $Longest) EndIf EndIf ;; If $iArray not == -1 or default then an array is returned where element 0 is the count and element 1 is the string ;; If $iCount == -1 or default then the count is returned else the string is returned (only If an array is not being returned) Func _String_LongestLine($sText, $iCount = -1, $iArray = -1) If FileExists($sText) Then $sText = FileRead($sText) If NOT $sText Then Return SetError(1,1, "Unable to read the text") $aText = StringRegExp($sText, "(.*?)(?:\v|\z)", 3) If @Error Then Return SetError(1,2, "RegExpression Error") Local $iLongest = StringLen($aText[0]), $sRtn = $aText[0] For $i = 1 To Ubound($aText) -1 If StringLen($aText[$i]) > $iLongest Then $iLongest = StringLen($aText[$i]) $sRtn = $aText[$i] EndIf Next If NOT StringRegExp($iArray, "(?i)-1|default") Then Local $aRtn[2] $aRtn[0] = $iLongest $aRtn[1] = $sRtn Return $aRtn EndIf If StringRegExp($iCount, "(?i)-1|default") Then Return $iLongest Return $sRtn EndFunc Func _String_CountLines($sText) If FileExists($sText) Then $sText = FileRead($sText) StringRegExpReplace($sText, "(?m:^).*\v|\z", "$1") Return @Extended EndFunc Edited May 1, 2009 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...
CodyBarrett Posted May 1, 2009 Share Posted May 1, 2009 (edited) Looks like you called it from the start Cody!!8)lmao all i did was think of a common problem that happens to me lol Edited May 1, 2009 by CodyBarrett [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
liteswap Posted May 2, 2009 Author Share Posted May 2, 2009 (edited) lmao all i did was think of a common problem that happens to me lolThanks Cody - I was hoping that someone had made the same booboo! And thanks too to Geosoft and Authenticity for the far more elegant way of doing what I was trying to do.And this was my first posting of problem code - so I hold up my hands: next time there'll be a full working example. OK? Edited May 2, 2009 by liteswap Link to comment Share on other sites More sharing options...
GEOSoft Posted May 2, 2009 Share Posted May 2, 2009 You're most welcome. I posted a more comprehensive version of the function in this post#677075 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...
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