In the previous chapter you saw a simple Windows program that displayed a single line of text in the center of its client area. The client area occupies all the space of the window that is not taken up by the caption bar, the window-sizing border, the menu bar (if any), and scroll bars (if any). The client area is the part of the window on which a program is free to draw. You can do almost anything you want with that client area—anything, that is, except assume that it will be a particular size or that the size will remain constant while your program is running. If you are accustomed to writing programs for the IBM PC, this exception may come as a bit of a shock. You can no longer think in terms of 25 lines and 80 columns of text. Your program shares the video display with other Windows programs. The user controls how the programs are arranged on the screen. Your program must accept the size it's given and do something reasonable with it. (A program could create a window of a specific fixed size, but it isn't very common.)
This works both ways. Just as your program may find itself with a client area barely large enough in which to say ”Hello,“ it may also someday be run on a big-screen high-resolution video system and discover a client area big enough for two entire pages of text and plenty of closet space besides. Dealing intelligently with both these eventualities is an important part of Windows programming.
Although Windows has extensive Graphics Device Interface (GDI) functions for displaying graphics, in this chapter I'll stick to displaying simple lines of text. I'll also ignore the various fonts (typefaces) and font sizes that Windows makes available and use only Windows' default ”system font.“ This may seem limiting, but it really isn't. The problems we encounter—and solve—in this chapter apply to all Windows programming. When you display a combination of text and graphics (as, for instance, the Windows CALENDAR, CARDFILE, and CALCULATOR programs do), the character dimensions of Windows' default system font often determine the dimensions of the graphics.
This chapter is ostensibly about learning how to paint, but it's really about learning the basics of device-independent programming. Windows programs can assume little about their environment. Instead, they must use the facilities that Windows provides to obtain information about the environment.