1. Secondary window

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)

new topic     » topic index » view message » categorize

2. Re: Secondary window

On Sat, 12 Aug 2000, you wrote:
> I've been working on a problem which I've not been able to resolve.
>snip
>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)

It's just a matter of positioning. You were assigning the onClick function
before there was any such  function to call.

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)

--** was here **

global procedure onClick_OKButton()
-- use the data from the text field to demonstrate this code -- is executing
userName = getText( PromptFld ) -- ** changed from NameFld, which doesn't exist
result = message_box( sprintf("Name = %s", {userName}),"Player's name", 0 )
closeWindow(PromptWin)
end procedure
onClick[ OKButton ] = routine_id("onClick_OKButton")
-- the test button's behavior
-- ** now here **
onClick[ OKButton ] = routine_id("onClick_OKButton")

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)
>
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: Secondary window

Well, that was it!  Thanks much.  Now that you've pointed out my
error it helps me get a better insight into how Win32Lib is working.
I had thought that it was simply storing a string for later usage.
Now I see that it is immediately using that string to be able to
establish the link to the subroutine name I was passing.  Thanks.

I have to admit that I'm still struggling with the shift to gui and
Windows programming.  Too many years writing the controls directly
makes it difficult to remember the many ramifications and possibilities
of multiple parallel actions within my program.  I haven't yet tried
to do something where I establish a lengthy transaction and then
invoke an event and try to see how well the long transaction
handles the interruption.

Thanks again.

      -jkr

new topic     » goto parent     » topic index » view message » categorize

4. Re: Secondary window

On Sat, 12 Aug 2000, I wrote:

> onClick[ OKButton ] = routine_id("onClick_OKButton")
> -- the test button's behavior
> -- ** now here **
> onClick[ OKButton ] = routine_id("onClick_OKButton")

Looks like I put that line in twice, which is unnecessary, but does no harm.
Irv

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu