1. I need help with a text edit window

Hi

 My program is using an edit text window for the user to
input but I want Windows to stop in the edit window untill
the user presses 'ENTER" after inputing text then have the
program continue on.

The way it is right now, the program continues to run
even though the text window has focus. The program needs
to interact with the input of this text window, but it
passes by before the text is input.

 I thought that if I got the cursor into that window the program would
wait for input but I was wrong.

Ive been trying for a couple hours to accomplish this but
cant figure it out.

   Please help.

  Thank you

      Gene

new topic     » topic index » view message » categorize

2. Re: I need help with a text edit window

> From: Gene Mannel
>
>  My program is using an edit text window for the user to
> input but I want Windows to stop in the edit window untill
> the user presses 'ENTER" after inputing text then have the
> program continue on.
>

What we need in win32lib is a way to use custom dialogs.  I've looked into
it a little bit now and then, and I get scared away almost every time.
Prolly not as hard as I think it is, but...

Until then, I came up with a hack that basically works.  I've put together a
couple of routines that allow you to run an extra event loop, so that you
can basically do what you want.  It's used similar to WinMain().

Suppose your edit window is named EditWin.  To open it, call:

EventLoop( EditWin, Modal )

Then, when this window is closed, be sure to call (most likely in the
onClose event for EditWin):

ExitEventLoop()

Some things to be careful about:  Don't allow more than one open modal
window.  This causes problems in win32lib.  Also, you need to make sure that
ExitEventLoop is called when the window is closed, or your program will
continue to run even after your main window is closed.

You can nest multiple event loops with this code, but you'll have to manage
closing the modal windows yourself.  In fact, it probably makes sense to
close the event loop before opening another.  But I haven't really figured
out the best way to do this.  Let me know if you find something that works
well!


-- eventloop.ew
-----------------------------------------------------------------
-- Added by Matt Lewis 3/10/00
-- to win32lib.
-- Allows extra event loops to be run!
sequence EventLoopExit
EventLoopExit = {}
global procedure EventLoop( integer id, integer style )
-- main routine
    atom hWnd
    atom msg
    atom ele

    -- allocate a message buffer
    msg = allocate_struct(SIZEOF_MESSAGE)

    EventLoopExit &= 0
    ele = length(EventLoopExit)
    openWindow( id, style )

    -- message loop
    while c_func( xGetMessage, { msg, NULL, 0, 0 } )  and not
        EventLoopExit[ele] do
        c_proc( xTranslateMessage, { msg } )
        c_proc( xDispatchMessage, { msg } )
    end while

    free(msg)

    EventLoopExit = EventLoopExit[1..ele-1]

end procedure
-- Back to original program
------------------------------------------------------------------

global procedure ExitEventLoop()

    if length(EventLoopExit) then
        EventLoopExit[length(EventLoopExit)] = 1
    end if

end procedure

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

3. Re: I need help with a text edit window

Hi Mat

  I added  eventloop.ew into in include dirictory. Should I have
added it onto the end of win32lib.ew instead?


 I then entered 'EventLoop( EditWin, Modal )' where I wanted
the text to be entered. In my case  EditWin is called TextWin.
Am I doing it right so far?

 It did stop the program and I was able write in the text window
at the same time.

 I added 'ExitEventLoop()' directly following that in
my code.

 Bear with me as Im not sure what im doing here. :o)
anyway, The program halts into the text window as I want but I
cant get back out it. LOL   Short of the 'control alt delete' end task
method.
 I know im leaving something out here. Do I need to tell it somehow
that a certain key should cause an exit or something?

  Im not sharp at all with some of code that I see I see in
the EW library.

   Thanks Gene
   Gene

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

4. Re: I need help with a text edit window

Derek Parnell wrote:

>  I'm not exactly sure by what you mean by "the program
> continues to run",
> but
> I assume you mean that the user is free to TAB or click into
> other fields.

Here's the generic situation:

Some event occurs, and suddenly your program needs some additional
information to continue processing.  In a console app, you might use
prompt_string/prompt_number to get some info from the user.  How would you
do this in win32lib?  You might create a separate window for this input, and
within your code:

--console
procedure someEvent()
--...do some stuff

--need something from the user to procede
x = prompt_string()

--...do more stuff
end procedure
-- end console

--windows
procedure someEvent()
--...do some stuff

--need something from the user to procede
openWindow(MyDialogWin, Modal)

--...do more stuff
end procedure
--end windows

In the console instance, your procedure doesn't continue until
prompt_string() returns a value.  In the windows instance, your code
continues immediately after the window is opened, without waiting for any
user input.  I had this argument with Irv, back when I originally came up
with implementing another event loop.

Here's a question :).  Do you use message boxes?  Same thing.

<snip>

>  This might sound "out-of-turn" so tell me if I should be quiet.
>
>  Environments that are event-driven, such as Windows
> programming,

<snip>

>  In short, dialog boxes are *not* in the pure philosophy on
> event-driven
>  programming. Instead, they are a way to make programmer's
> work easier, at
>  the cost of restricting users. Microsoft programs are great
> source of how
>  not to write programs. I recommend that you don't use Matt's
> work-around
>  (sorry Matt, nothing personal) but instead, make your code
> bend to the way
>  the user might want to work with the form. This is what
> *user-friendly* is
>  all about.

No offense taken.  This model of event driven programming is probably
sufficient for a database type application.  But suppose you're writing
something like a game.  You really need the functionality of a dialog box.
The way I'd implemented them, I call a function that 'wraps' the dialog.

Here's an example from my majuk project (a game based on Magic the
Gathering).  This is an excerpt of the code used to select a target.

-- begin code

-- target.ew
-- Matt Lewis
-- Choose Target Dialog
sequence target, TargetCards
atom TargetID
TargetID = 0
target = {}

--  Window TargetWindow
global constant TargetWindow = create( Window, "Choose Target", Main,
Default, Default, 352, 336+ 44, 0 )
constant TargetList = create( List, "List of targets here", TargetWindow, 8,
56, 328, 224, 0 )
constant TargetSelectButton = create( PushButton, "Select", TargetWindow,
36, 292, 90, 30, 0 )
constant TargetCancelButton = create( PushButton, "Cancel", TargetWindow,
204, 292, 90, 30, 0 )
constant TargetActionLabel = create( LText, "Targeting action description
here", TargetWindow, 8, 4, 332, 48, 0 )

procedure SetTarget()
-- fills controls with the data
end procedure --SetTarget

procedure TargetWindow_onOpen ()
    SetTarget()
end procedure
onOpen[TargetWindow] = routine_id("TargetWindow_onOpen")

procedure TargetSelectButton_onClick ()
    atom card
    card =  getIndex( HandList )
    if card then
        TargetID = card
        ExitEventLoop()
        closeWindow( TargetWindow )
    end if
end procedure
onClick[TargetSelectButton] = routine_id("TargetSelectButton_onClick")

procedure TargetCancelButton_onClick ()
    -- Cancel targeting...
    TargetID = 0
    closeWindow( TargetWindow )
end procedure
onClick[TargetCancelButton] = routine_id("TargetCancelButton_onClick")

global function choose_target(atom card, atom player,atom targets,
        sequence what)
    TargetID = 0
    target = { card, player, targets, what }
    EventLoop( TargetWindow, Modal )
    return TargetID
end function
-- end code

Basically, I can call this from any point to get a target.  It's like a
custom getSaveFileDialog.

>  In the situation you cited, which is not too uncommon, you can do few
> things
>  (if you must) to force the user to do things your way and not theirs.

<snipped a) & b)>

a) and b ) sound much too painful.

>  c) Create and open a new modal window that only has the one
> edit field on
>  it. The simplest from a programmer's point of view, but
> might not be very
>  user-friendly.

This is exactly the point, except that if you need the input from within a
routine, simply creating a modal window won't work.  You have to add that
pesky event loop.

Matt Lewis

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

5. Re: I need help with a text edit window

Hi again

 I found the following in WIN32LIB :

--/topic Controls
--/const DefPushButton
--/desc Default command button control.
-- A DefPushButton is a /PushButton, but
-- is displayed with an extra border indicating that this button
-- will automatically be selected if the user presses the Return
-- button on the keyboard.
--
-- Unfortunately, this behavior is not currently implemented, so it
-- simply behaves the same as a normal /PushButton.
--

snip

If it were implemented, well, that would be a big help in my orignal
question.

 Although I dont know much about the Win32Lib Ive looking farther
down Win32Lib and it appears that some or most of the code for
'DefPushButton' is already there. Perhaps it just needs to be
completed.

   Hhmmm,,   :¿)

  Gene

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

6. Re: I need help with a text edit window

Hi,
I implemented DefPushButton in a recent release of the library.

Try the following code...

include win32lib.ew
with trace

constant w =3D create(Window, "test", 0, 0, 0, 400, 400, 0),
         f =3D create(MleText, "", w, 5,100, 300, 200, 0)    ,
         b =3D create(DefPushButton, "&OK", w, 5, 25, 50, 50, 0)

procedure kpw(atom keycode, atom shifts)

end procedure
onKeyDown[f] =3D routine_id("kpw")

procedure xx()

trace(1)
end procedure
onClick[b] =3D routine_id("xx")

WinMain(w, 0)

------------

If focus is in the text box and you press the return key, the onClick
handler of the button is fired.

-------
cheers
Derek.


----- Original Message -----
From: "Gene Mannel" <mgene2 at GJ.NET>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Sunday, October 08, 2000 7:56 AM
Subject: Re: I need help with a text edit window


Hi again

 I found the following in WIN32LIB :

--/topic Controls
--/const DefPushButton
--/desc Default command button control.
-- A DefPushButton is a /PushButton, but
-- is displayed with an extra border indicating that this button
-- will automatically be selected if the user presses the Return
-- button on the keyboard.
--
-- Unfortunately, this behavior is not currently implemented, so it
-- simply behaves the same as a normal /PushButton.
--

snip

If it were implemented, well, that would be a big help in my orignal
question.

 Although I dont know much about the Win32Lib Ive looking farther
down Win32Lib and it appears that some or most of the code for
'DefPushButton' is already there. Perhaps it just needs to be
completed.

   Hhmmm,,   :=BF)

  Gene

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

7. Re: I need help with a text edit window

On Sun, 8 Oct 2000 09:40:13 +1100, Derek Parnell <dparnell at BIGPOND.NET.AU>
wrote:

>Hi,
>I implemented DefPushButton in a recent release of the library.
>
>Try the following code...
>
-snip

It worked like a charm, WOW !!!  Thanks Derek

>cheers
>Derek.
>
-snip

And cheers  to you to. :¿}


 Thanks,
   gene

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

Search



Quick Links

User menu

Not signed in.

Misc Menu