Category : Files from Magazines
Archive   : CGAZV5N1.ZIP
Filename : MSGDEMOP.C

 
Output of file : MSGDEMOP.C contained in archive : CGAZV5N1.ZIP
/****************************** MSGDEMOP.C *******************************
* File: msgdemop.c
* Author: Michael J. Young
* Purpose: Basic PM program: echo messages, ]aints screen
* Compiler: Microsoft C 6.0
* Compile time switches: none
* Associated files: msgdemop.h -> header file, provides links to resources
* msgdemop.m -> make file
* msgdemop.def -> linker definition file
* msgdemop.rc -> resource file: defines menu items
*
* Compile with:
* cl -c -W2 -AS -G2sw -Oas -Zpe msgdemop.c
* rc -r msgdemop.rc
* link /NOD msgdemop.obj,, nul.map, os2.lib slibcep.lib, msgdemop.def
* rc msgdemop.res
* (c) 1990 C Gazette. Use freely as long as authorship is acknowledged
***************************************************************************/

#define INCL_WININPUT
#include "os2.h"
#include "msgdemop.h"
#include

void InitProgram (void);
MRESULT EXPENTRY MainWndProc (HWND hwnd, USHORT message, MPARAM mp1,
MPARAM mp2);

HAB HAncBlk; /* Anchor block handle. */
HWND HFrame; /* Frame window handle. */
HMQ HMesQue; /* Message queue handle. */
char MsgLine1 [30]; /* Buffers for strings displayed in window. */
char MsgLine2 [80];

void main (void) /* Program entry function. */
{
QMSG QueMsg; /* Structure for holding messages. */

InitProgram (); /* Initialize program. */

while (WinGetMsg /* Get messages from the program queue until */
/* receiving WM_QUIT. */
(HAncBlk, /* Anchor block handle. */
&QueMsg, /* Address of structure to receive message. */
0, /* Window to receive messages: 0 means all. */
0, /* Lowest message value: none. */
0)) /* Highest message value: none. */

WinDispatchMsg /* Sends message to window procedure. */
(HAncBlk, /* Anchor block handle. */
&QueMsg); /* Address of structure holding message. */

WinDestroyWindow (HFrame); /* Eliminate the window. */
WinDestroyMsgQueue (HMesQue); /* Eliminate the message queue. */
WinTerminate (HAncBlk); /* Sever ties with PM. */

} /* end main */


void InitProgram (void)
{
ULONG CtlData = /* Specifies control windows to include. */
FCF_HORZSCROLL | /* Horizontal scroll bar. */
FCF_MENU | /* Menu bar. */
FCF_MINMAX | /* Minimize/maximize box. */
FCF_SHELLPOSITION | /* Make window visible on screen. */
FCF_SIZEBORDER | /* Wide sizing border. */
FCF_SYSMENU | /* System menu. */
FCF_TASKLIST | /* Include program in Task Manager list. */
FCF_TITLEBAR | /* Title bar. */
FCF_VERTSCROLL; /* Vertical scroll bar. */
HWND HClient; /* Handle to client window. */

HAncBlk = WinInitialize /* Initialize PM / get anchor block hand. */
(0); /* Options: must be 0. */

HMesQue = WinCreateMsgQueue /* Create a message queue. */
(HAncBlk, /* Anchor block handle. */
0); /* Queue size: 0 means use default. */

WinRegisterClass /* Register window class. */
(HAncBlk, /* Anchor block handle. */
"MsgDemoClass", /* Window class name. */
MainWndProc, /* Window procedure to handle messages. */
0L, /* Class style: none specified. */
0); /* Bytes of data storage per window: none */

HFrame = WinCreateStdWindow /* Create main window. */
(HWND_DESKTOP, /* Parent window handle: desktop. */
WS_VISIBLE, /* Frame window style: visible. */
&CtlData, /* List of control windows to include*/
/* other features. */
"MsgDemoClass", /* Client window class name. */
"", /* Text for title bar: none yet. */
0L, /* Client window style: none specified. */
0, /* Resource module handle: in .EXE file.*/
ID_MENU, /* ID of resources to include */
&HClient); /* Address to receive client window hand*/

WinSetWindowText /* Display text in window title bar. */
(HFrame, /* Handle of frame window. */
"Message Demo Program"); /* Text for title. */

return;

} /* end InitProgram */


MRESULT EXPENTRY MainWndProc /* Window procedure for main window. */
(HWND hwnd, /* Window handle. */
USHORT msg, /* Message type. */
MPARAM mp1, /* Message information. */
MPARAM mp2) /* More message information. */
{
switch (msg) /* Branch according to message. */
{
case WM_CHAR: /* User pressed character key. */
sprintf (MsgLine1,"Message: WM_CHAR");
sprintf (MsgLine2,
"low mp1 = %04x hi mp1 = %04x "
"low mp2 = %04x hi mp2 = %04x",
SHORT1FROMMP (mp1), SHORT2FROMMP (mp1),
SHORT1FROMMP (mp2), SHORT2FROMMP (mp2));
WinInvalidateRect /* Mark window for repainting. */
(hwnd, /* Handle of client window. */
NULL, /* Area to paint: NULL means entire */
/* client window. */
TRUE); /* Include child windows. */
WinUpdateWindow (hwnd); /* Force immediate repainting. */
return ((MRESULT)TRUE);

case WM_COMMAND: /* Menu item chosen. */
switch (SHORT1FROMMP (mp1)) /* Branch on menu item ID. */
{
case IDM_ABOUT: /* "About" menu item chosen. */
WinMessageBox
(HWND_DESKTOP,
hwnd,
"Presentation Manager\nMessage Demo Program",
"MsgDemo",
0,
MB_ICONASTERISK | MB_OK);
break;

case IDM_EXIT: /* "Exit" menu item chosen. */
WinSendMsg /* Send a message. */
(hwnd, /* Handle of recepient window. */
WM_CLOSE, /* Message ID: close window. */
0L, /* Message parameters: no data sent.*/
0L);
break;
}
return (0);

case WM_HSCROLL: /* Horizontal scroll bar clicked. */
sprintf(MsgLine1,"Message: WM_HSCROLL");
sprintf (MsgLine2,
"low mp1 = %04x hi mp1 = %04x "
"low mp2 = %04x hi mp2 = %04x",
SHORT1FROMMP (mp1), SHORT2FROMMP (mp1),
SHORT1FROMMP (mp2), SHORT2FROMMP (mp2));
WinInvalidateRect (hwnd, NULL, TRUE);
WinUpdateWindow (hwnd);
return (0);

case WM_BUTTON1DBLCLK: /* Left mouse button double clicked. */
sprintf(MsgLine1,"Message: WM_BUTTON1DBLCLK");
sprintf (MsgLine2,
"low mp1 = %04x hi mp1 = %04x "
"low mp2 = %04x hi mp2 = %04x",
SHORT1FROMMP (mp1), SHORT2FROMMP (mp1),
SHORT1FROMMP (mp2), SHORT2FROMMP (mp2));
WinInvalidateRect (hwnd, NULL, TRUE);
WinUpdateWindow (hwnd);
return ((MRESULT)TRUE);

case WM_BUTTON1DOWN: /* Left mouse button pressed. */
sprintf(MsgLine1,"Message: WM_BUTTON1DOWN");
sprintf (MsgLine2,
"low mp1 = %04x hi mp1 = %04x "
"low mp2 = %04x hi mp2 = %04x",
SHORT1FROMMP (mp1), SHORT2FROMMP (mp1),
SHORT1FROMMP (mp2), SHORT2FROMMP (mp2));
WinInvalidateRect (hwnd, NULL, TRUE);
WinUpdateWindow (hwnd);
return ((MRESULT)TRUE);

case WM_BUTTON1UP: /* Left mouse button released. */
sprintf(MsgLine1,"Message: WM_BUTTON1UP");
sprintf (MsgLine2,
"low mp1 = %04x hi mp1 = %04x "
"low mp2 = %04x hi mp2 = %04x",
SHORT1FROMMP (mp1), SHORT2FROMMP (mp1),
SHORT1FROMMP (mp2), SHORT2FROMMP (mp2));
WinInvalidateRect (hwnd, NULL, TRUE);
WinUpdateWindow (hwnd);
return ((MRESULT)TRUE);

case WM_MOUSEMOVE: /* Mouse cursor moved in client window. */
sprintf(MsgLine1,"Message: WM_MOUSEMOVE");
sprintf (MsgLine2,
"low mp1 = %04x hi mp1 = %04x "
"low mp2 = %04x hi mp2 = %04x",
SHORT1FROMMP (mp1), SHORT2FROMMP (mp1),
SHORT1FROMMP (mp2), SHORT2FROMMP (mp2));
WinInvalidateRect (hwnd, NULL, TRUE);
WinUpdateWindow (hwnd);
return (WinDefWindowProc (hwnd, msg, mp1, mp2));

case WM_PAINT: /* Client window needs repainting. */
{
HPS HPresSpace; /* Presentation space handle. */
RECTL Rect; /* Rectangle data. */

HPresSpace = WinBeginPaint /* Get handle to PS. */
(hwnd, /* Client window handle. */
0, /* Use a "cache" PS */
0); /* Don't supply invalid region */

WinQueryWindowRect /* Get coordinates of client window. */
(hwnd, /* Client window handle. */
&Rect); /* Structure to receive coordinates */

WinDrawText /* Display first string */
(HPresSpace, /* Presentation space handle. */
0xffff, /* String length: 0xffff means 0 term. */
MsgLine1, /* String to display. */
&Rect, /* Rectangle in which to display string.*/
0L, /* Foregraound color: use default. */
0L, /* Background color: use default. */
DT_ERASERECT | /* Erase area before displaying string. */
DT_TEXTATTRS | /* Use default colors. */
DT_TOP | /* Print at top of window, */
DT_CENTER); /* in center. */

WinDrawText /* Display second string. */
(HPresSpace,
0xffff,
MsgLine2,
&Rect,
0L,
0L,
DT_TEXTATTRS |
DT_VCENTER | /* Position vertically in center. */
DT_CENTER);

WinEndPaint (HPresSpace); /* Tell PM that window is */
/* repainted. */
return (0);

} /* end WM_PAINT scope */

case WM_SIZE: /* Window size has changed. */
sprintf(MsgLine1,"Message: WM_SIZE");
sprintf (MsgLine2,
"low mp1 = %04x hi mp1 = %04x "
"low mp2 = %04x hi mp2 = %04x",
SHORT1FROMMP (mp1), SHORT2FROMMP (mp1),
SHORT1FROMMP (mp2), SHORT2FROMMP (mp2));
WinInvalidateRect (hwnd, NULL, TRUE);
WinUpdateWindow (hwnd);
return (0);

case WM_VSCROLL: /* Mouse clicked on vertical scroll bar. */
sprintf(MsgLine1,"Message: WM_VSCROLL");
sprintf (MsgLine2,
"low mp1 = %04x hi mp1 = %04x "
"low mp2 = %04x hi mp2 = %04x",
SHORT1FROMMP (mp1), SHORT2FROMMP (mp1),
SHORT1FROMMP (mp2), SHORT2FROMMP (mp2));
WinInvalidateRect (hwnd, NULL, TRUE);
WinUpdateWindow (hwnd);
return (0);

default: /*Have PM do default processing on all other */
/* messages. */
return (WinDefWindowProc (hwnd, msg, mp1, mp2));

} /* end switch */

} /* end MainWndProc */

  3 Responses to “Category : Files from Magazines
Archive   : CGAZV5N1.ZIP
Filename : MSGDEMOP.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/