Moderators SmOke_N Posted July 15, 2006 Moderators Posted July 15, 2006 Yeah. But he also wanted a notification of when the user was approaching the limit.I did this the other day (for you even merriman http://www.autoitscript.com/forum/index.ph...st&p=205862 ), and skruge reminded me of the option.... The notification is (nothing else is being typed ) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
merriman Posted July 15, 2006 Author Posted July 15, 2006 Thanks for all your help guys. I must apologise for not explaining very well. What I am actually working on is a GUI to send a SMS message to a mobile phone. The edit control is for entering the SMS message, and can only be a maximum 136 characters. I understand that I could use the GUICtrlSetLimit() function to set the limit. However, I want to make it more user friendly by displaying to the user how many characters they have left before they reach the maximum. As the user types in each character I want to decrement a counter and display it to the user exactly how many characters they have left Best Regards Merriman
nitekram Posted July 15, 2006 Posted July 15, 2006 (edited) Thanks for all your help guys. I must apologise for not explaining very well. What I am actually working on is a GUI to send a SMS message to a mobile phone. The edit control is for entering the SMS message, and can only be a maximum 136 characters. I understand that I could use the GUICtrlSetLimit() function to set the limit. However, I want to make it more user friendly by displaying to the user how many characters they have left before they reach the maximum. As the user types in each character I want to decrement a counter and display it to the user exactly how many characters they have leftHere is my last attempt at what you want - this should be enough for you to work out the kinks on your own. expandcollapse popup#include <GuiConstants.au3> Global $stop = 0, $test, $count = 0 Opt("GUIOnEventMode", 1) GUICreate("MyGUI", 392, 316, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Edit_1 = GUICtrlCreateEdit("", 80, 50, 270, 170) GUICtrlCreateLabel("Amount of Characters Used: ", 5, 280, 280, 80) $Box_1 = GUICtrlCreateLabel($count, 140, 280, 260, 80) GUISetOnEvent($Edit_1, "EditCltEvent") GUISetOnEvent($GUI_EVENT_CLOSE, "close") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Pressed_Left_Button") GUISetState() GUISetState(@SW_SHOW) While 1 Sleep(10) $String = GUICtrlRead($Edit_1) If StringLen($String) > $count Then showhowmany() If StringLen($String) >= 162 And $stop = 0 Then;or w/e number $test = StringLen($String) exceed() ElseIf StringLen($String) >= 163 And $stop = 1 Then $test = StringLen($String) EditCltEvent() EndIf WEnd Exit Func showhowmany() $count = $count + 1 GUICtrlSetData($Box_1, 163 - $count) EndFunc ;==>showhowmany Func exceed() MsgBox(0, "Exceeded Characters", "Only one more left " & $test & " " & $String) $stop = 1 EndFunc ;==>exceed Func EditCltEvent() MsgBox(0, "", "Maxed OUT" & " test = " & $test & " " & $String) $stop = 5 EndFunc ;==>EditCltEvent Func Pressed_Left_Button() MsgBox(0, "Button Press", "You pressed the left Button on the MOUSE") EndFunc ;==>Pressed_Left_Button Func close() If @GUI_CtrlId = $GUI_EVENT_CLOSE Then Exit EndFunc ;==>close Edit changed max count number Edited July 15, 2006 by nitekram 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator
merriman Posted July 16, 2006 Author Posted July 16, 2006 Here is my last attempt at what you want - this should be enough for you to work out the kinks on your own. expandcollapse popup#include <GuiConstants.au3> Global $stop = 0, $test, $count = 0 Opt("GUIOnEventMode", 1) GUICreate("MyGUI", 392, 316, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Edit_1 = GUICtrlCreateEdit("", 80, 50, 270, 170) GUICtrlCreateLabel("Amount of Characters Used: ", 5, 280, 280, 80) $Box_1 = GUICtrlCreateLabel($count, 140, 280, 260, 80) GUISetOnEvent($Edit_1, "EditCltEvent") GUISetOnEvent($GUI_EVENT_CLOSE, "close") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Pressed_Left_Button") GUISetState() GUISetState(@SW_SHOW) While 1 Sleep(10) $String = GUICtrlRead($Edit_1) If StringLen($String) > $count Then showhowmany() If StringLen($String) >= 162 And $stop = 0 Then;or w/e number $test = StringLen($String) exceed() ElseIf StringLen($String) >= 163 And $stop = 1 Then $test = StringLen($String) EditCltEvent() EndIf WEnd Exit Func showhowmany() $count = $count + 1 GUICtrlSetData($Box_1, 163 - $count) EndFunc;==>showhowmany Func exceed() MsgBox(0, "Exceeded Characters", "Only one more left " & $test & " " & $String) $stop = 1 EndFunc;==>exceed Func EditCltEvent() MsgBox(0, "", "Maxed OUT" & " test = " & $test & " " & $String) $stop = 5 EndFunc;==>EditCltEvent Func Pressed_Left_Button() MsgBox(0, "Button Press", "You pressed the left Button on the MOUSE") EndFunc;==>Pressed_Left_Button Func close() If @GUI_CtrlId = $GUI_EVENT_CLOSE Then Exit EndFunc;==>close Edit changed max count number nitekram, thanks very much for your code, its exactly what I am trying to do, and it works perfectly. Best Regards Merriman
GaryFrost Posted July 16, 2006 Posted July 16, 2006 (edited) just to show anything is possible in an animated cartoon: (Requires Beta) expandcollapse popup#include <GuiConstants.au3> Global Const $WM_COMMAND = 0x0111 Global Const $EN_CHANGE = 0x300 Global Const $EN_SETFOCUS = 0x100 Global Const $EN_KILLFOCUS = 0x200 Global Const $DebugIt = 1 Global $changed = 0 GUICreate("My GUI") ; will create a dialog box that when displayed is centered $edit = GUICtrlCreateEdit("This is a test, this is only a test", 80, 50, 270, 170) ; create first item $btn = GUICtrlCreateButton("Ok", 40, 230, 60, 20) GUISetState() GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $changed = 1 ;---------------------------------------------------------------------------------------------- If $DebugIt Then _DebugPrint("Edit Changed:" & GUICtrlRead($edit)) If $DebugIt Then _DebugPrint(StringLen(GUICtrlRead($edit))) ;---------------------------------------------------------------------------------------------- $changed = 0 EndSelect WEnd Func _Edit_Changed() $changed = 1 EndFunc ;==>_Edit_Changed Func _Edit_GotFocus() ;---------------------------------------------------------------------------------------------- If $DebugIt Then _DebugPrint("Edit Got Focus") ;---------------------------------------------------------------------------------------------- EndFunc ;==>_Edit_GotFocus Func _Edit_LostFocus() ;---------------------------------------------------------------------------------------------- If $DebugIt Then _DebugPrint("Edit Lost Focus") ;---------------------------------------------------------------------------------------------- EndFunc ;==>_Edit_LostFocus Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $nNotifyCode = _HiWord($wParam) Local $nID = _LoWord($wParam) Local $hCtrl = $lParam Switch $nID Case $edit Switch $nNotifyCode Case $EN_CHANGE _Edit_Changed() Case $EN_SETFOCUS _Edit_GotFocus() Case $EN_KILLFOCUS _Edit_LostFocus() EndSwitch EndSwitch ; Proceed the default Autoit3 internal message commands. ; You also can complete let the line out. ; !!! But only 'Return' (without any value) will not proceed ; the default Autoit3-message in the future !!! Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_COMMAND Func _DebugPrint($s_text) ConsoleWrite( _ "!===========================================================" & @LF & _ "+===========================================================" & @LF & _ "-->" & $s_text & @LF & _ "+===========================================================" & @LF) EndFunc ;==>_DebugPrint Func _HiWord($x) Return BitShift($x, 16) EndFunc ;==>_HiWord Func _LoWord($x) Return BitAND($x, 0xFFFF) EndFunc ;==>_LoWord Added got focus and lost focus events and correct debug statement, was quick and dirty from another script of mine. Edited July 16, 2006 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.
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