Re: Displaying and image w/ the touch of a button
- Posted by Derek Parnell <ddparnell at bigpond.com> Mar 17, 2001
- 448 views
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."