Category : C Source Code
Archive   : DOS2WIN.ZIP
Filename : WMHANDLR.C

 
Output of file : WMHANDLR.C contained in archive : DOS2WIN.ZIP
/*
WMHANDLR.C
Event (WM_ message) handlers - implementation
Dave Maxey and Andrew Schulman - 1991
originally published in Microsoft Systems Journal, July 1991
*/

#include
#include "wmhandlr.h"

long defwmhandler(HWND, unsigned, WORD, LONG);

WMHANDLER wmhandler[WM_USER];

/* ----------------------------------------------------------------------- */
/* This is our event processor. It is the dispatcher for the handlers set */
/* using SetHandler. An Application plugs this function into its */
/* window, sets handlers for messages, and WndProc handles the rest. */
/* This window procecedure should never need to be changed! */
/* ----------------------------------------------------------------------- */
long FAR PASCAL _export WndProc(HWND hWnd, WORD message,
WORD wParam, LONG lParam)
{
if (message < WM_USER)
return (*wmhandler[message])(hWnd, message, wParam, lParam);
else
return DefWindowProc(hWnd, message, wParam, lParam);
}

/* ---------------------------------------------------------------- */
/* Routines to get and set the message handlers. Setting to NULL */
/* uninstalls a handler, by setting the handler to the default */
/* which calls Windows own DefWndProc. */
/* ---------------------------------------------------------------- */
WMHANDLER wmhandler_get(unsigned message)
{
return (message < WM_USER) ? wmhandler[message] : 0;
}

WMHANDLER wmhandler_set(unsigned message, WMHANDLER f)
{
WMHANDLER oldf;
if (message < WM_USER)
{
oldf = wmhandler[message];
wmhandler[message] = f ? f : defwmhandler;
return (oldf ? oldf : defwmhandler);
}
else
return 0;
}

/* ----------------------------------------------------------------------- */
/* This is a default handler so that an application chain on to a previous */
/* handler from their current one without having to worry what was there */
/* before. All this default handler does is to call DefWindowProc. */
/* ----------------------------------------------------------------------- */
long defwmhandler(HWND hwnd, unsigned message, WORD wParam, LONG lParam)
{
return DefWindowProc(hwnd, message, wParam, lParam);
}

/* ------------------------------------------------------------------- */
/* MUST BE CALLED BEFORE THE APPLICATION WINDOW IS CREATED - */
/* Just inits the array of handlers to the default.. */
/* ------------------------------------------------------------------- */
void wmhandler_init(void)
{
WMHANDLER *pwm;
int i;
for (i=0, pwm=wmhandler; i < WM_USER; i++, pwm++)
*pwm = defwmhandler;
}


  3 Responses to “Category : C Source Code
Archive   : DOS2WIN.ZIP
Filename : WMHANDLR.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/