Secondary window
- Posted by "J. Kenneth Riviere" <kriviere at MINDSPRING.COM> Aug 12, 2000
- 474 views
I've been working on a problem which I've not been able to resolve. I hope someone here has some suggestions. I've written a game using Win32Lib and I want to be able to prompt the user for their name. I looked for something like a promptbox() routine similar to the useful messagebox() function, but have not been able to find one. So I declared a second window, put a label, text field, and OK button in it planning to have the OK button's routine store the results which had been entered into the text field and close the window. However, I've not been able to get the button to work at all. I've included a simple program which demonstrates the problem below. I've been able to achieve the functionality I need by adding an onClose call for the window (see the commented-out line) and then commenting out the closeWindow call within the function. However, I'd rather have users be able to click on the OK button instead of just closing the window. Any help would be greatly appreciated. -J. Kenneth Riviere (JoKeR) ------------------------------------------------------------ include win32lib.ew without warning integer result sequence userName userName = {} constant Win = create( Window, "TestWindow", 0, Default, Default, 200, 200, 0 ), testButton = create( PushButton, "Push Me!", Win, 30, 60, 120, 40, 0 ) constant PromptWin = create( Window,"Enter your name",0,Default,Default,260,120,0), PromptLbl = create( LText, "Please enter your name", PromptWin, 10, 15, 120, 20, 0 ), PromptFld = create( EditText, "", PromptWin, 10, 45, 120, 20, 0 ), OKButton = create( PushButton, "OK", PromptWin, 180, 40, 30, 30, 0 ) onClick[ OKButton ] = routine_id("onClick_OKButton") global procedure onClick_OKButton() -- use the data from the text field to demonstrate this code is executing userName = getText( NameFld ) result = message_box( sprintf("Name = %s", {userName}), "Player's name", 0 ) closeWindow(PromptWin) end procedure --onClose [ PromptWin ] = routine_id("onClick_OKButton") -- the test button's behavior global procedure onClick_TestButton() if length(userName) > 0 then result = message_box( sprintf("Name = %s", {userName}), "Player's name", 0 ) end if openWindow( PromptWin, Normal ) end procedure -- tell Windows when to do the action onClick[testButton] = routine_id( "onClick_TestButton" ) WinMain(Win, Normal)