CompuServe Messages

Drawing in Windows

    11-Mar-94 10:52:32
Sb: #163342-Drawing in Windows
Fm: Spec Bowers 70731,3710
To: Jeff Davis 72624,2726
In a multi-window environment – Mac, Windows, Motif, etc. – there is a very important technique which is not immediately obvious, not emphasized in the documentation, but which makes all drawing work much better. You probably are writing directly into a window in response to a user event. E.g. when your user clicks a button you create your graph window, then draw directly into it. The right technique is to draw into your windows only in response to update events, not in response to user actions. You should maintain data structures that describe the contents of your windows, then draw (redraw) a window from these data structures whenever the windows need to be redrawn (I.e. whenever the Mac delivers an update event). You respond to user actions by updating your internal data structures, then issuing InvalRect toolbox calls to tell the Mac that portions of your window are out of date. The Mac creates an update event, to which your application responds by drawing the contents of the window. Later, as windows are covered and uncovered, the Mac will issue more update events, and your program will redraw the window contents. You'll still do things like DrawString, MoveTo, etc. but you'll do them from your UpdateMainWindow routine instead of in the various parts of your code that respond to clicks, keystrokes, etc. In the case of a dialog you'll usually put the drawing code into a draw proc for a user item. The toolbox Dialog Manager will automatically call the draw proc as needed (provided that you issue the appropriate InvalRect calls to tell the Mac that parts of your dialog need to be redrawn).