1. Input Box by Greg Haberek
- Posted by Tony Steward <tony.steward at gmail.com> Jul 03, 2005
- 532 views
------=_Part_3869_16648547.1120388047096 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Content-Disposition: inline Hi Greg or anyone who can help, I have begun using you input box routine although I did have to modify lines 60 to 75 and have added it below. Anyway my problem is if I call input box and set style to password all is great but if I then call the routine again later and don't want password style it won't change. It remains as password, I'm guessing because the object does not get re-created? How can I fix this? [code] -- input_box.ew -- by Greg Haberek <ghaberek at gmail.com> -- creates an popup message box that requires user input integer Popup_Window, Popup_LText, Popup_EditText, Popup_PushButton1, Popup_PushButton2 Popup_Window = 0 -- Main Window Popup_LText = 0 -- Prompt Text Popup_EditText = 0 -- Input Text Popup_PushButton1 = 0 -- 'OK' Button Popup_PushButton2 = 0 -- 'Cancel' Button sequence Popup_ReturnText Popup_ReturnText = "" -- Text returned to user procedure Popup_Handler( integer pSelf, integer pEvent, sequence pParams ) if pSelf = Popup_Window then -- play the message_box sound --Beep( MB_OK ) Beep( MB_ICONQUESTION) elsif pSelf = Popup_EditText then if pParams[1] = VK_ENTER then -- Enter = OK VOID = invokeHandler( Popup_PushButton1, w32HClick, {} ) elsif pParams[1] = VK_ESCAPE then -- Escape = Cancel VOID = invokeHandler( Popup_PushButton1, w32HClick, {} ) end if elsif pSelf = Popup_PushButton1 then -- OK clicked -- get the return text Popup_ReturnText = getText( Popup_EditText ) -- close the window destroy(Popup_EditText) closeWindow( Popup_Window ) elsif pSelf = Popup_PushButton2 then -- Cancel clicked -- set the return text to nothing Popup_ReturnText = "" -- close the window destroy(Popup_EditText) closeWindow( Popup_Window ) end if end procedure global function input_box( sequence pPrompt, sequence pTitle, integer pStyle ) -- pPrompt is either a single sequence for the user prompt, -- or a sequence of two sequences in the form {prompt, def_text} -- where def_text is the default text for the input box -- -- pTitle is the title of the input box -- -- pStyle sets the style of the EditText (ES_NUMERIC, ES_PASSWORD) -- Example: -- -- only accept numeric characters -- text = input_box( "Give me a number", "User Input", ES_NUMERIC ) sequence defText if Popup_Window = 0 then -- window not created -- create the controls Popup_Window = create( Window, "", 0, Center, Center, 340, 120, {WS_SYSMENU,WS_DLGFRAME} ) Popup_LText = create( LText, "", Popup_Window, 10, 10, {w32Edge,-100}, 40, 0 ) if pStyle=ES_PASSWORD then Popup_EditText = createEx( EditText, "", Popup_Window, 10, {w32AltEdge,-30}, {w32Edge,-10}, 20, w32or_all({ES_PASSWORD}) ,0) elsif pStyle = ES_NUMERIC then Popup_EditText = createEx( EditText, "", Popup_Window, 10, {w32AltEdge,-30}, {w32Edge,-10}, 20, w32or_all({ES_NUMERIC}) ,0) else Popup_EditText = createEx( EditText, "", Popup_Window, 10, {w32AltEdge,-30}, {w32Edge,-10}, 20, 0 ,0) end if Popup_PushButton1 = create( DefPushButton, "OK", Popup_Window, {w32AltEdge,-100}, 10, 90, 20, 0 ) Popup_PushButton2 = create( PushButton, "Cancel", Popup_Window, {w32AltEdge,-100}, 30, 90, 20, 0 ) -- set the event handlers setHandler( Popup_Window, w32HActivate, routine_id("Popup_Handler") ) setHandler( Popup_EditText, w32HKeyDown, routine_id("Popup_Handler") ) setHandler( {Popup_PushButton1, Popup_PushButton2}, w32HClick, routine_id("Popup_Handler") ) end if -- determine if pPrompt is just a prompt or {prompt, def_text} if length(pPrompt) = 2 and sequence(pPrompt[1]) and sequence(pPrompt[2]) then -- pPrompt = {prompt, def_text} defText = pPrompt[2] pPrompt = pPrompt[1] else defText = "" end if -- set the text for the controls setText( Popup_Window, pTitle ) setText( Popup_LText, pPrompt ) setText( Popup_EditText, defText ) -- add the style if necessary if pStyle then addStyle( Popup_EditText, pStyle ) end if -- open the window as a dialog -- set focus to the text box openDialog( {Popup_Window, Popup_EditText} ) -- remove the style if pStyle then removeStyle( Popup_EditText, pStyle ) end if -- return the text return Popup_ReturnText end function ------=_Part_3869_16648547.1120388047096 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Content-Disposition: inline Hi Greg or anyone who can help,<br> I have begun using you input box routine although I did have to modify lines 60 to 75 and have added it below.<br> <br> Anyway my problem is if I call input box and set style to password all is great but if I then call the routine again later and don't want password style it won't change. It remains as password, I'm guessing because the object does not get re-created?<br> <br> How can I fix this?<br> <br> <br> [code]<br> -- input_box.ew<br> -- by Greg Haberek <<a href="mailto:ghaberek at gmail.com">ghaberek at gmail.com</a>><br> -- creates an popup message box that requires user input<br> <br> integer Popup_Window, Popup_LText, Popup_EditText,<br> Popup_PushButton1, Popup_PushButton2<br> <br> Popup_Window = 0 -- Main Window<br> Popup_LText = 0 -- Prompt Text<br> Popup_EditText = 0 -- Input Text<br> Popup_PushButton1 = 0 -- 'OK' Button<br> Popup_PushButton2 = 0 -- 'Cancel' Button<br> <br> sequence Popup_ReturnText<br> Popup_ReturnText = "" -- Text returned to user<br> <br> procedure Popup_Handler( integer pSelf, integer pEvent, sequence pParams )<br> <br> if pSelf = Popup_Window then<br> -- play the message_box sound<br> --Beep( MB_OK )<br> Beep( MB_ICONQUESTION)<br> <br> elsif pSelf = Popup_EditText then<br> if pParams[1] = VK_ENTER then<br> -- Enter = OK<br> VOID = invokeHandler( Popup_PushButton1, w32HClick, {} )<br> elsif pParams[1] = VK_ESCAPE then<br> -- Escape = Cancel<br> VOID = invokeHandler( Popup_PushButton1, w32HClick, {} )<br> end if<br> <br> elsif pSelf = Popup_PushButton1 then -- OK clicked<br> -- get the return text<br> Popup_ReturnText = getText( Popup_EditText )<br> -- close the window<br> destroy(Popup_EditText)<br> closeWindow( Popup_Window )<br> <br> elsif pSelf = Popup_PushButton2 then -- Cancel clicked<br> -- set the return text to nothing<br> Popup_ReturnText = ""<br> -- close the window<br> destroy(Popup_EditText)<br> closeWindow( Popup_Window )<br> <br> end if<br> <br> end procedure<br> <br> global function input_box( sequence pPrompt, sequence pTitle, integer pStyle )<br> -- pPrompt is either a single sequence for the user prompt,<br> -- or a sequence of two sequences in the form {prompt, def_text}<br> -- where def_text is the default text for the input box<br> --<br> -- pTitle is the title of the input box<br> --<br> -- pStyle sets the style of the EditText (ES_NUMERIC, ES_PASSWORD)<br> -- Example:<br> -- -- only accept numeric characters<br> -- text = input_box( "Give me a number", "User Input", ES_NUMERIC )<br> sequence defText<br> <br> if Popup_Window = 0 then<br> -- window not created<br> -- create the controls<br> Popup_Window = create( Window, "", 0, Center, Center, 340, 120, {WS_SYSMENU,WS_DLGFRAME} )<br> Popup_LText = create( LText, "", Popup_Window, 10, 10, {w32Edge,-100}, 40, 0 )<br> if pStyle=ES_PASSWORD then<br> Popup_EditText = createEx( EditText, "", Popup_Window, 10, {w32AltEdge,-30}, {w32Edge,-10}, 20, w32or_all({ES_PASSWORD}) ,0)<br> elsif pStyle = ES_NUMERIC then<br> Popup_EditText = createEx( EditText, "", Popup_Window, 10, {w32AltEdge,-30}, {w32Edge,-10}, 20, w32or_all({ES_NUMERIC}) ,0)<br> else<br> Popup_EditText = createEx( EditText, "", Popup_Window, 10, {w32AltEdge,-30}, {w32Edge,-10}, 20, 0 ,0)<br> end if<br> Popup_PushButton1 = create( DefPushButton, "OK", Popup_Window, {w32AltEdge,-100}, 10, 90, 20, 0 )<br> Popup_PushButton2 = create( PushButton, "Cancel", Popup_Window, {w32AltEdge,-100}, 30, 90, 20, 0 )<br> -- set the event handlers<br> setHandler( Popup_Window, w32HActivate, routine_id("Popup_Handler") )<br> setHandler( Popup_EditText, w32HKeyDown, routine_id("Popup_Handler") )<br> setHandler( {Popup_PushButton1, Popup_PushButton2}, w32HClick, routine_id("Popup_Handler") )<br> end if<br> <br> -- determine if pPrompt is just a prompt or {prompt, def_text}<br> if length(pPrompt) = 2 and sequence(pPrompt[1]) and sequence(pPrompt[2]) then<br> -- pPrompt = {prompt, def_text}<br> defText = pPrompt[2]<br> pPrompt = pPrompt[1]<br> else<br> defText = ""<br> end if<br> <br> -- set the text for the controls<br> setText( Popup_Window, pTitle )<br> setText( Popup_LText, pPrompt )<br> setText( Popup_EditText, defText )<br> <br> -- add the style if necessary<br> if pStyle then<br> addStyle( Popup_EditText, pStyle )<br> end if<br> <br> -- open the window as a dialog<br> -- set focus to the text box<br> openDialog( {Popup_Window, Popup_EditText} )<br> <br> -- remove the style<br> if pStyle then<br> removeStyle( Popup_EditText, pStyle )<br> end if<br> <br> -- return the text<br> return Popup_ReturnText<br> end function<br> <br> ------=_Part_3869_16648547.1120388047096--
2. Re: Input Box by Greg Haberek
- Posted by Greg Haberek <ghaberek at gmail.com> Jul 03, 2005
- 548 views
- Last edited Jul 04, 2005
Add this: removeStyle( Popup_EditText, or_bits(ES_READONLY, ES_PASSWORD) ) Before this: -- add the style if necessary if pStyle then addStyle( Popup_EditText, pStyle ) end if It should remedy the problem. ~Greg