![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
The Basics of
BASIC | GFA Beginners | Getting Started with the GFA Enviroment
Beginners to Windows
How does programming in Windows differ from programming for DOS, the ST or the Ameoba? There are a few things you should remember:
You really have to put a PEEKEVENT, GETEVENT or SLEEP in every loop that is going to take any amount of time. Without a calling a function like these Windows just siezes up and is of little use to anybody. The mouse goes odd and hardly any API's (the commands of Windows) work. You'll find a PEEKEVENT wont slow down your program too much (for any normal program to notice) but will allow Windows to do all the things it does to make life easier.
Windows messages are at the heart of Windows. Whenever something happens in your window(s) a message is sent to your program telling you what has happened. These messages take the following form: hWnd - the handle of the window that the message is for. Mess - the number of the message (Windows uses constants to make the remembering of these messages easier eg. a WM_PAINT message is number 15 but you never have to remember this, whenever you check for which message it is you just put IF [The Message Variable]=WM_PAINT ). wParam - a WORD value (2 bytes) that is message specific. lParam - a LONG value (4 bytes) that is message specific. There is more info on Windows messages in the Amateurs Zone, also a great help file of Windows messages, with what they mean and what they put in/need in wParam and lParam, comes with Dale Bryant's incredibly useful GFAWHELP file that can be downloaded from http://www.gfawhelp.gfa.net/.
Have a central redrawing routine. A Windows program should be able to redraw everything in it's window(s) as quick as possible, just in case it gets obscured by another window or it's contents get deleted for some other reason. If this happens your window will recieve a WM_PAINT and a WM_NCPAINT (if it has a sizable border) message. Making a central redrawing routine can be tricky for some programs, you may think of using GET to store the whole window as a bitmap and then PUT it if you get a redraw message, be warned though, if there is another window over your one you will GET that too!
You can't directly access the screen, all drawing must go through Windows. Windows uses DCs to draw to, you can think of them as logical screens as they work in a similar way. Instead of the address of memory a DC is a handle which Windows uses to tell it where to draw. So if you are familiar with screen-flipping you can do the same effect by creating a DC, drawing everything to that, and then BITBLTing from that DC to your window.
You never have to write a GUI (Graphical User Interface) again, if you don't want to. The Windows 'controls' (comboboxes, listboxes, edit boxes etc.) are very good and very easy to program. I don't know about you, but I was getting well and truely sick of writing a new text-entering routine for every GUI I created on the ST, now I just use Windows edit boxes and they do all the hard work for me and comboboxes are fantastic for saving space!
Free up resources. When you get a bitmap, or create a DC or many other Windows specific things, Windows will give memory over to that thing and give you back a handle so you can use it. If you don't tell Windows to free the memory afterwards it will never go away, so you will find your resources rapidly diminish. Here's a list of things you have to free: DCs (FREEDC),Bitmaps (FREEBMP), Brushes (DeleteObject), Pens (DeleteObject), Fonts (FREEFONT), DLLs (FREEDLL), Clipping Regions (DeleteObject), Palettes (DeleteObject) and Atoms (DeleteAtom), there are a few others but these are the ones to remember. This is very important though, anything created in your program must be deleted before you quit, there is nothing more infuriating than a program that uses up all your resources. Note - Bitmaps can be created in many ways (LOADBMP, GET, CREATEBMP, ~^LoadImage (see Expert Zone ) etc.) but they all can and must be freed with FREEBMP.
I hope this has helped you convert your programs to Windows, I think you'll find the advantages outweigh the disadvantages when programming in Windows.
The
Basics of BASIC | GFA Beginners | Getting Started with the GFA Enviroment
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()