TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: NEIL HELLER
from: JERRY COFFIN
date: 1997-09-09 23:55:00
subject: WHY THE BRACES?

On (08 Sep 97) Neil Heller wrote to Roger Scudder...
 NH> It seems as though all the programs I am asked to modify are vintage
 NH> Windows code containing at least one 10+ page switch statement.  Yet
 NH> I've never heard about "message crackers".  Can these be applied
 NH> retroactively without all the hassle necessary if the code were to be
 NH> rewritten using a framework like MSF or OWL?
Converting a program to use Message Crackers is definitely simpler than
converting it to OWL or MFC, and it doesn't generally make the final
product noticeably larger or slower like they tend to.
You start with a switch statement, but the message cracker decodes
wParam and lparam for you, and passes the correct bits to your function.
The prototypes you need to user for most functions are given in
windowsx.h as well as MS' documentation for it (which is unfortunately
usually provided only on disk, and often the fact that it's there at all
isn't even mentioned elsewhere in the documentation.)
Basically though, you'll typically end up with something like this:
#define WINDOWPROC LRESULT CALLBACK _export
void doPaint(hWnd window) {
// ...
}
void doCreate(hWnd, CREATESTRUCT FAR *lpCS) {
// ...
}
WINDPROC WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
    switch(msg) {
        HANDLE_MSG(hWnd, WM_PAINT, doPaint);
        HANDLE_MSG(hWnd, WM_CREATE, doCreate);
        // ...
    }
}
For these to work, you have to use the names "wParam" and "lParam" for
those parameters in your window procedure.  Considering the difficulty
you're likely to run into in finding official documentation on
windowsx.h, the easiest way to find the prototypes for the functions you
write is probably by simply extracting the comments from windowsx.h
itself.  It precedes each message cracker macro with the prototype of
the function that macro is intended to call.
    Later,
    Jerry.
--- PPoint 1.90
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.