Windows MFC Programming I Long Table of Contents

Windows MFC Programming I Long Table of Contents

Back to previous book promo page(with page numbers)

Chapter 1 — The Basics of Windows Programming 1

Introduction to Windows Programming……….. 1
Coding the Windows API……….. 3
Common Windows Graphical Objects — A Review of Terms……….. 4
Resources……….. 9
Construction of Resources……….. 10
Resource Styles……….. 10
Windows Data Types and DEFINEs……….. 11
Structure Alignment……….. 14
Hungarian Notation and Coding Conventions……….. 17
Windows API Function Names……….. 19
My Sample Program Coding Notation……….. 19
Getting Started — The Software……….. 20
A Project’s Files……….. 20
Precompiled Headers — the Pch Files……….. 21
Pgm01a — A First Windows Program — The Hello World Program……….. 22
Using Comments……….. 27
The WinMain Function……….. 27
Programming Problems……….. 36

 

Chapter 2 — Outputting Text and Using Scroll Bars 37

The Paint Process……….. 37
Painting From Other Places……….. 39
A Better Way to Display Text — The TextOut Function……….. 40
Acquiring Text Measurements……….. 41
Using the Text Measurements……….. 44
Setting the TextOut Alignment……….. 45
Obtaining the Current Size of the Client Area……….. 46
Scroll Bars: Theory of Operation……….. 47
The New Style Scroll Bars……….. 49
Structuring a Program for Painting……….. 50
The SYSTEM METRICS Structure……….. 54
Pgm02a — The Wrong Way to Display with Variable Width Fonts……….. 54
Pgm02b — The Right Way to Display with Variable Width Fonts……….. 63
Pgm02c — Using the New Style Scroll Bars……….. 71
Another Way to Avoid the Complexities of Variable Width Fonts……….. 72
Determining the Dimensions a Text String Would Occupy……….. 72
Programming Problems……….. 73

 

Chapter 3 — Handling the Keyboard and the Mouse….. 74

Keyboard Basics……….. 74
The Windows Keyboard Messages……….. 75
Windows Virtual Key Identifiers……….. 76
Who Has the Input Focus?……….. 77
Responding to WM_KEYDOWN Messages……….. 77
Sending a Message to Your Own Application 78
Processing WM_CHAR Messages……….. 79
Inputting Text Lines — the Caret……….. 80
Writing a Text Editor — Or the Handling of Data Entry……….. 82
Windows Stock Fonts……….. 82
The Mouse Interface……….. 85
Client Area Mouse Messages……….. 86
The Non-Client Area Mouse Messages……….. 88
Button Click Pairing……….. 89
Other Mouse Functions……….. 89
Hit Testing……….. 89
Working With Coordinates……….. 90
Messages Sent Upon Closing an Application……….. 90
Some More Graphics Functions……….. 91
MessageBeep and MessageBox Functions……….. 91
Using Child Windows……….. 92
WNDCLASS and WINDOW Special IDs……….. 93
Window Longs: an Advanced Feature……….. 94
Putting Keystrokes and Mouse Actions and Child Windows into Action: Tic Tac Toe………. 95
Programming Problems……….. 110

 

Chapter 4 — Controlling Windows From C++— the MFC — Microsoft Foundation Classes.. 112

Introduction……….. 112
Beginning Actions — the Help System……….. 113
Getting Started — an Optimum Way……….. 115
Some Basic Properties of the MFC Class Library……….. 116
Building an MFC Project……….. 117
MFC Basic Applications……….. 119
Deriving Your Main Window Class……….. 121
The cycle to set up an Interface Object and its associated Interface Element……….. 122
CWnd and CFrameWnd Public Data Members……….. 124
The CFrameWnd and CWnd Constructors……….. 124
The CWnd Member Functions (and Thereby Inherited By CFrameWnd)……….. 125
MFC Message Response Tables and Windows WM_ Messages……….. 128
Predefined Headers — How to Make Them Work for You……….. 130
The Sample Hello World MFC Programs……….. 131
Sample Pgm04a — Your Model Shell……….. 132
Pgm04b — Everything in One File — for Magazine Articles……….. 135
Pgm04c — a Main Frame Window with a Child Client Window……….. 138
Handling Events — Pgm04d……….. 146
The OnSize Function……….. 155
The SetBkMode, SetBkColor, and SetTextcolor Functions……….. 156
The OnLButtonDown Function……….. 156
Sending Messages……….. 157
The OnClose Function 158
Using Fixed Fonts……….. 158
Programming Problems……….. 159

 

Chapter 5 — Timers, Colors, Brushes, and Resource Files… 160

Timers……….. 160
How the System Colors Are Handled……….. 161
Twenty-one System Color Identifiers……….. 162
Setting Colors……….. 163
Dynamic Alterations to WNDCLASS……….. 163
Creating Brushes and Pens……….. 164
Other MFC Text Member Functions……….. 166
Sample Program Pgm05a — Displaying the 21 System Colors……….. 166
Resource Files — an Introduction……….. 174
String Resources — a How To……….. 176
Retrieving Strings at Runtime……….. 182
The Improved Pgm05b Program……….. 183
Programming Problems……….. 186

 

Chapter 6 — Menus… 188

Menu Syntax……….. 188
Predefined MFC Menu ID Names and Numbers……….. 191
Sample Menu for Pgm06a……….. 192
Creation of a Menu Resource……….. 194
Installing a Menu C API Style……….. 196
C API Method 1: assign the menu in the window class structure……….. 196
C API Method 2: dynamically load and install a menu……….. 197
C API Method 3: manually build the menu from component menuitems………. 197
Installing a Menu the MFC Way……….. 197
MFC Method 1: pass the menu string name to the Create function……….. 197
MFC Method 2: use the C API Method 2 or 3……….. 197
MFC Method 3: Use a CMenu class to construct menu objects……….. 198
Working with the Menu Choices of the User……….. 198
MFC Style Menu Processing……….. 199
Dynamically Check Marking, Graying/unGraying, Enabling/Disabling Menu Items……….. 200
MFC Command Enablers……….. 201
Using CMenu Member Functions……….. 202
Free Floating Pop-up Menus……….. 203
Menu Accelerators……….. 204
Pgm06a Menu Example Program……….. 206
Stub Testing……….. 216
A Common Command Enabler Function……….. 216
Programming Problems……….. 217

 

Chapter 7 — Icons, Cursors, and Dialogs.. 218

Introduction……….. 218
Using Developer Studio to Browse Existing Resources……….. 219
Creation of Icons, Bitmaps, and Cursors……….. 219
Using Icons and Cursors……….. 220
Method 1 — Using the C API Functions……….. 222
Method 2 — Use the CWinApp functions to load the cursor……….. 222
Method 3 — the SetClassLong……….. 223
Controls and Dialog Boxes……….. 223
The Text Syntax of Dialogs and Controls……….. 228
General Design Guidelines for Dialogs……….. 228
Implementing Dialogs — a Myriad of Choices……….. 229
Using Class Wizard to Create and Maintain Our CDialog Classes……….. 234
Transferring Data from Dialog Data Members to the Caller’s Data Members………. 242
Pgm07a Dialogs to Control Window Actions……….. 245
Data Validation……….. 277
Writing Your Own Data Validator Functions……….. 278
Sub-classing Controls — Deriving your Own Control Classes……….. 281
Programming Problems……….. 282

 

Chapter 8 — Memory, Files, Common Dialog Boxes, Scroll Bars… 284

Introduction……….. 284
Windows and Memory Management……….. 284
Windows Global Memory API Functions……….. 285
Windows New Heap Memory Functions……….. 287
File Handling Under Windows — Long Filenames……….. 288
Which File Processing Functions Should Be Used?……….. 290
Working With the New Windows File Functions……….. 291
The MFC CFile……….. 295
Memory Mapped Files……….. 298
The MFC Container Classes……….. 299
The MFC Encapsulation of the Windows Common Dialogs……….. 300
The CFileDialog Class……….. 301
The CFontDialog……….. 303
Pgm08a — Handling All of the File Menu Choices……….. 307
Using MFC’s CScrollBar to Scroll a Text Window……….. 333
Some Additional Considerations About Pgm08a……….. 338
Scrolling Only a Portion of a Window and the RecalcLayout Function — Pgm08b……….. 339
A Console Debugging Window — Another Trick of the Masters……….. 343
Programming Problems……….. 364

 

Chapter 9 — Graphics — The GDI Package. 366

Introduction……….. 366
The Device Context 367
Obtaining the Device Capabilities……….. 369
Saving DCs……….. 369
Mapping Modes and Viewport Versus Window Coordinates……….. 370
GDI Objects Rules of Use……….. 372
Pens……….. 373
Brushes……….. 373
Drawing Graphical Images……….. 374
The Drawing Modes or ROPS and Clipping Regions……….. 375
The Mighty BitBlt……….. 377
Creating Memory DCs……….. 378
Pgm09a — Graphics Scrolling, Memory DCs and Handling Display Changes……….. 380
Setting Up an Application-wide Information Class……….. 381
Pgm09a Implementation……….. 384
DIBs and Color Palettes……….. 395
Handling Color — The Palettes……….. 406
Methods to Display the DIB Image……….. 412
The SetDIBitsToDevice Method……….. 412
Two Methods of Constructing a Memory DC……….. 413
Memory DC Method 1 For Converting DIBs into DDBs With Possible Color Loss Using SetDIBits……….. 413
Memory DC Method 2 For Converting DIBs into DDBs With No Color Loss Using CreateDIBitmap……….. 414
Method for Constructing Memory DCs for Game Animation — DIBSection………. 415
Bitmap Special Effects Displays……….. 415
Pgm09b — DIB (BMP) File Display with Fancy Effects……….. 417
Programming Problems……….. 444

 

Chapter 10 — Control Bars, Status Bars, Tool Boxes, and Child Client Windows 446

Introduction……….. 446
Division of Labors — Adding a Client Window Class……….. 448
The MFC Implementation of Decorations……….. 450
Using the Resource Editor to Add a New Tool Bar……….. 451
Implementing Decorations in the FrameWin Class……….. 458
Control Bar and Status Bar Construction……….. 460
The Tool Box Derived Class……….. 465
The MFC Message Map Entries for a Consecutive Range of Command IDs……….. 470
Displaying Information on the Status Bar……….. 471
Hiding and Showing Tool Boxes……….. 471
The DrawWin Client Window — Capturing the Mouse……….. 479
RecalcLayout — Painting in the Client Area of the FrameWin Itself……….. 485
Programming Problems……….. 486

 

Chapter 11 — The Multiple Document Interface. 488

Introduction 488
MDI Terminology……….. 490
Pgm11a — Overview……….. 492
The MFC Implementation of MDI — Pgm11a……….. 493
How to Have Multiple Resource Files and Read Only Headers……….. 493
Handling the “Windows” Pop-up Menu Items……….. 500
The Implementation of the MDI Frame Window Class……….. 500
Launching an MDI Child Window……….. 508
The Fast Close Operation……….. 509
Converting ScrollWin from Pgm09a into a CMDIChildWnd……….. 510
Converting Pgm10a’s DrawWin to a CMDIChildWnd……….. 520
Programming Problems……….. 533

 

Chapter 12 — A Text Editor, Fonts, and Clipboard Operations 534

Introduction……….. 534
The Use of The CEdit Control as a Main Window……….. 534
All About Fonts……….. 537
Font Details……….. 538
The LOGFONT and TEXTMETRIC Structures……….. 540
Pgm12a — A Text Editor and Graphics Clipboard Operations Program……….. 544
Clipboard Operations……….. 580
Handling Text with the Clipboard……….. 581
Handling Bitmaps on the Clipboard……….. 582
The VERIFY and ASSERT Macros……….. 587
Handling a Cut Operation……….. 587
Handling the Paste Operation……….. 588
Programming Problems……….. 590

 

Chapter 13 — Basic Printing Operations 591

Introduction……….. 591
The Design of Printing Operations……….. 591
Printing Method 1: Printing a Mixed Page of Text and Graphics from the Screen Paint Function………..592
Printing Method 2: Printing Multiple Page Documents or Printing Reports……….. 592
Scaling the Page……….. 592
Using Fonts……….. 593
The Print Spooling Process……….. 593
Pgm13a — Printing Method 1 — Using a Dual Purpose Render Function……….. 594
Modifying Data in the Print Dialog Box……….. 611
The Printing Sequence for the MFC……….. 612
Printing Directly Within the MFC’s PrintPage……….. 613
Text Output Functions for Variable Width Fonts……….. 613
Formatting Text……….. 615
Creating a Program Editor with Print Support — Pgm13b……….. 616
Programming Problems……….. 643

 

Chapter 14 — Sound, Splash Screens, Animation Effects and Animated Presentations… 644

Sound……….. 644
Pgm14a — Playing WAV Files — Using a Dialog Box as the Main Window………. 646
Splash Screens……….. 650
Animation……….. 654
XOR Images and Transparent Backgrounds……….. 656
Creating Faster Action — Beyond Windows Timers……….. 658
Pgm14b — Timer and Fast Animation……….. 660
Animated Presentations……….. 675
Pgm14d — Presentations……….. 681
The try-catch and TRY-CATCH Logic for the MFC……….. 702
Programming Problems……….. 704

 

Chapter 15 — The Document-View Architecture… 705

Introduction……….. 705
The Application Design……….. 706
The Document-View Implementation of Pgm15a……….. 711
Designing a Serializeable SalesData Class……….. 711
Other MFC Container Classes……….. 717
The MFC Document-View Implementation……….. 717
Creating the Document-View Shell Application……….. 721
The CDocument Derived Class for Pgm15a ……….. 724
The Resource File for Pgm15a……….. 733
The Application Class — Pgm15a……….. 738
The Frame Window Class — FrameWin……….. 741
The CView Classes AcmeView……….. 746
The Printing and Print Preview Process of AcmeView……….. 769
The AcmePlot View Class — Creating a Bar Chart……….. 777
Using the Multiple Document Interface (MDI) — Pgm15b……….. 790
Programming Problems……….. 798

Index……. 799

Back to previous book promo page

Share Button