1. Displaying and image w/ the touch of a button

Well the change over from DOS to Windows has thrown me yet another curve.  My 
movement engine dosn't seem to be working.  I have simplified it and 
simplified it to see if I could find the problem and it has come down to 
this, displaying a single image by the press of a button (in this case "i")  
In DOS this seemed to work fine, but not in windows.  The only problem I can 
think of is that get_key may not be a windows command.  Heres my code, take a 
look:

include win32lib.ew
atom keystroke, walk_up1, man_position 

--create a window

constant MainWin= create( Window, "Theif", 0, Default, Default,600,600, 0 )
 
-- load bitmap and put it into a pixmap
walk_up1 = create(Pixmap,"image",0, 5, 5, 20, 20, 0 )
setPixmap(walk_up1,"image.bmp")


man_position = 50
-- ***********************************************************************
-- Display image by pressing i
keystroke = get_key()
if keystroke = 'i' then
            
        copyBlt(MainWin,35, man_position, walk_up1)
                
    end if
keystroke = get_key()
-- **********************************************************************
WinMain(MainWin,Normal)

-Dan Da Man  (Thanx for your help)

new topic     » topic index » view message » categorize

2. Re: Displaying and image w/ the touch of a button

From: <RedDan11 at AOL.COM>

>
> Well the change over from DOS to Windows has thrown me yet another curve.
My
> movement engine dosn't seem to be working.  I have simplified it and
> simplified it to see if I could find the problem and it has come down to
> this, displaying a single image by the press of a button (in this case
"i")
> In DOS this seemed to work fine, but not in windows.  The only problem I
can
> think of is that get_key may not be a windows command....

You're right, it isn't. Try onKeyPress.

Something like

procedure MyWin_onKeyPress (integer keycode, integer shift)
if keycode = VK_ESCAPE then ...do something
elsif keycode = VK_RETURN then ...do something else
end if
end procedure

onKeyPress[MyWin] = routine_id("MyWin_onKeyPress")

This is from memory - hope it is right.
Regards,
Irv

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

3. Re: Displaying and image w/ the touch of a button

> Well the change over from DOS to Windows has thrown me yet another curve.  My 
> movement engine dosn't seem to be working.  I have simplified it and 
> simplified it to see if I could find the problem and it has come down to 
> this, displaying a single image by the press of a button (in this case "i")  
> In DOS this seemed to work fine, but not in windows.  The only problem I can 
> think of is that get_key may not be a windows command.  Heres my code, take a 
> look:

Your suspicion is correct, you don't use get_key() in a windows 
program. Instead, try using an event like onKeyPress instead :)

(Hey, having a printed Win32Lib manual is sooooo very useful! 
Perhaps someone of us should start selling copies? Heh, I printed 
mine at school on a machine w/ IE, and had to handmake the index 
myself, and even the index has errors! (Caused by the fact there 
may not be some shortcuts in the manual to a few commands 
dealing with XPM's...) Another idea, Derek, can you maintain a list 
of errara'd items since the previous version of the manual? Or do I 
do that myself? :))

HTH,

--"LEVIATHAN"

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

4. Re: Displaying and image w/ the touch of a button

Hi,

> In DOS this seemed to work fine, but not in windows.  The only problem I
can
> think of is that get_key may not be a windows command.

Yeah, that'd do it. get_key() is not a Windows function.

The main difference (if there is only one) between DOS and Windows
programming is that DOS programming tends to be process driven and Windows
is event driven. In DOS the code causes the sequence of events, but in
Windows the code reacts to events.

Try something like this instead...

----------------
 include win32lib.ew
 atom keystroke, walk_up1, man_position

 --create a window

 constant MainWin= create( Window, "Theif", 0, Default, Default,600,600, 0 )

 -- load bitmap and put it into a pixmap
 walk_up1 = create(Pixmap,"image",0, 5, 5, 20, 20, 0 )
 setPixmap(walk_up1,"image.bmp")


 man_position = 50

 -- ***********************************************************************
procedure WaitingForI( integer keycode, integer shift )
 -- Display image by pressing i in either upper or lower case
    if find(keycode,"iI") != 0 then
         copyBlt(MainWin,35, man_position, walk_up1)

     end if
end procedure

-- The use of [Screen] here traps the event regardless of which control has
focus.
onKeyPress[Screen] = routine_id("WaitingForI")
 -- **********************************************************************
 WinMain(MainWin,Normal)

--------------------
Using this method, you have to keep track of the look of the screen so that
you can redraw it during an onPaint event.

If it isn't going to otherwise hurt your program you could do it like this
..

------------------
include win32lib.ew
 without warning
 atom keystroke, walk_up1, man_position

 --create a window
                                  --vvvvv-- Spelling change.
 constant MainWin= create( Window, "Thief", 0, Default, Default,600,600,0 )

 -- load bitmap and put it into a pixmap

 walk_up1 = create(Bitmap,"",MainWin, 5, 5, 20, 20, 0 )
 setVisible(walk_up1, 0)
 setBitmap(walk_up1, "sad.bmp")
 man_position = 50

 -- ***********************************************************************
procedure WaitingForI( integer keycode, integer shift )
 -- Display image by pressing i in either upper or lower case
    if find(keycode,"iI") != 0 then

         setRect(walk_up1, 35, man_position, 20,20, 1)
         setVisible(walk_up1, 1)

     end if
end procedure
onKeyPress[Screen] = routine_id("WaitingForI")
 -- **********************************************************************

 WinMain(MainWin,Normal)
-------------------

which is almost the same, only using a Bitmap control instead of a Pixmap.
Windows then handles the repainting for you.
-----------
Derek Parnell
Melbourne, Australia
"To finish a job quickly, go slower."

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

Search



Quick Links

User menu

Not signed in.

Misc Menu