home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
SOUR
/
CGAZ5N2.ZIP
/
DEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-09
|
14KB
|
306 lines
/********************************************************************
** File: DEMO.C
** Purpose: Dialog Box Demo
** Author: Michael Young
** Compiler: Microsoft C 6.0
** Environment: Windows 3.0
*********************************************************************/
#define _WINDOWS
#include <windows.h>
#include <string.h>
#include "demo.h"
#include "demodlg.h"
BOOL InitInstance (HANDLE hInstance, int nCmdShow);
BOOL InitProgram (HANDLE hInstance);
long FAR PASCAL MainWndProc (HWND hwnd, unsigned message, WORD wParam,
LONG lParam);
BOOL FAR PASCAL AboutDlgProc (HWND hDlg, unsigned message, WORD wParam,
LONG lParam);
BOOL FAR PASCAL SettingsDlgProc (HWND hDlg, unsigned message, WORD wParam,
LONG lParam);
HANDLE HInst; /* Handle to current program instance. */
struct { /* Holds current modem settings. */
char Port [5]; /* COMx */
char DialType; /* 'T' or 'P' */
char Prefix [7]; /* 0-6 numbers, or ',' for 2-sec. pause */
}
Header = { "COM1", 'T', "" }; /* default settings */
int PASCAL WinMain /* Program entry function. */
(HANDLE hInstance, /* Handle to current program instance. */
HANDLE hPrevInstance, /* Handle to previous program instance. */
LPSTR lpCmdLine, /* Pointer to command line. */
int nCmdShow) /* Indicates how to show window (open/icon). */
{
MSG Msg; /* Structure for holding messages. */
if (!hPrevInstance) /* Check for other program instances*/
if (!InitProgram (hInstance)) /* Initialize program. */
return (FALSE); /* Can't initialize; exit. */
if (!InitInstance (hInstance, nCmdShow)) /* Initialize instance. */
return (FALSE); /* Can't initialize; exit. */
while (GetMessage /* Get messages from the program queue */
/* until receiving WM_QUIT. */
(&Msg, /* Address of message structure. */
NULL, /* Window to receive messages: NULL = all. */
NULL, /* Lowest message value: none. */
NULL)) /* Highest message value: none. */
{
TranslateMessage (&Msg);
DispatchMessage (&Msg); /* Sends message to window procedure. */
}
return (Msg.wParam); /* Return value supplied by WM_QUIT. */
} /* end WinMain */
BOOL InitInstance /* Instance initialization function. */
(HANDLE hInstance, /* Current program instance. */
int hCmdShow) /* Indicates how to show window (open/icon). */
{
HWND HWindow; /* Handle for main program window. */
HInst = hInstance; /* Save instance handle in global variable. */
HWindow = CreateWindow /* Create the main program window. */
("DemoClass", /* Class name passed to RegisterClass. */
"Dialog Demo Program", /* Text for window title. */
/* Window style: */
WS_OVERLAPPEDWINDOW, /* Has title, system menu, & border. */
CW_USEDEFAULT, /* Horizontal position: use default. */
CW_USEDEFAULT, /* Vertical position: use default. */
CW_USEDEFAULT, /* Width: use default. */
CW_USEDEFAULT, /* Height: use default. */
NULL, /* Parent: none. */
NULL, /* Menu: use class menu. */
hInstance, /* Instance to be associated with window. */
NULL); /* Pointer value passed to window: none. */
if (!HWindow) /* 0 window handle = window could not be created. */
return (FALSE); /* FALSE indicates failure. */
ShowWindow /* Display the window. */
(HWindow, /* Window handle. */
hCmdShow); /* Display mode (open/icon). */
UpdateWindow (HWindow); /* Causes window proc. to update window. */
return (TRUE); /* TRUE indicates success. */
} /* end InitInstance */
BOOL InitProgram /* Program initialization function. */
(HANDLE hInstance) /* Current program instance. */
{
WNDCLASS WC; /* Structure for holding class information. */
WC.style = CS_DBLCLKS; /* Double-click processing. */
WC.lpfnWndProc = MainWndProc; /* Window function. */
WC.cbClsExtra = 0; /* No extra data for class. */
WC.cbWndExtra = 0; /* " " " " instance */
WC.hInstance = hInstance; /* Instance that owns class.*/
WC.hIcon = LoadIcon (NULL, IDI_APPLICATION);/* Load/assign class icon. */
WC.hCursor = LoadCursor (NULL, IDC_ARROW); /* Load/assign cl. cursor. */
WC.hbrBackground = GetStockObject (WHITE_BRUSH); /* Background brush. */
WC.lpszMenuName = "DemoMenu"; /* Name of class menu. */
WC.lpszClassName = "DemoClass"; /* Name of window class*/
return (RegisterClass (&WC)); /* Register window */
/* class/return code.*/
} /* end InitProgram */
long FAR PASCAL MainWndProc /* Window procedure for main window. */
(HWND hwnd, /* Window handle. */
unsigned message, /* Message type. */
WORD wParam, /* Message information. */
LONG lParam) /* More message information. */
{
HDC HDspCtx; /* Handle to display context. */
PAINTSTRUCT PS; /* Paint data structure. */
RECT Rect; /* Rectangle data structure. */
FARPROC ProcAddr; /* Holds procedure-instance address of dialog proc.*/
switch (message)
{ /* Branch according to message. */
case WM_COMMAND: /* Menu item chosen. */
switch (wParam) /* Branch on menu item identifier. */
{
case IDM_ABOUT: /* "About" menu item chosen. */
ProcAddr = MakeProcInstance (AboutDlgProc, HInst);
DialogBox /* Open "About" dialog box. */
(HInst, /* Current instance. */
"ABOUTDLG", /* Name of resource. */
hwnd, /* Handle of parent window. */
ProcAddr); /* Procedure instance address. */
FreeProcInstance (ProcAddr); /* Free address. */
return (NULL);
case IDM_SETTINGS: /* "Settings" menu item chosen. */
ProcAddr = MakeProcInstance (SettingsDlgProc, HInst);
DialogBox /* Open "Settings" dialog box. */
(HInst, /* Current instance. */
"SETTINGSDLG", /* Name of resource. */
hwnd, /* Handle of parent window. */
ProcAddr); /* Procedure instance address. */
FreeProcInstance (ProcAddr); /* Free address. */
return (NULL);
case IDM_EXIT: /* "Exit" menu item chosen. */
DestroyWindow (hwnd); /* Destroy main window. */
return (NULL);
default:
return (DefWindowProc (hwnd, message, wParam, lParam));
}
case WM_DESTROY: /* Window is being destroyed. */
PostQuitMessage (0); /* Posts a WM_QUIT message to */
/* program queue. */
return (NULL);
default: /* Have Windows do default processing on all */
/* other messages: */
return (DefWindowProc (hwnd, message, wParam, lParam));
} /* end switch */
} /* end MainWndProc */
BOOL FAR PASCAL AboutDlgProc /* "About" dialog procedure. */
(HWND hDlg, /* Window handle for dialog box. */
unsigned message, /* Message type. */
WORD wParam, /* Message information. */
LONG lParam) /* More message information. */
{
switch (message)
{
case WM_INITDIALOG: /* Dialog box is being initialized. */
return (TRUE); /* TRUE indicates message processed. */
case WM_COMMAND: /* Command sent from dialog box. */
/* User clicked OK, hit Esc,
or closed thru systm menu: */
if (wParam == IDOK || wParam == IDCANCEL)
{
EndDialog (hDlg, TRUE); /* Remove dialog box. */
return (TRUE);
}
else
return (FALSE); /* FALSE: message not processed. */
default:
return (FALSE);
} /* end switch */
} /* end AboutDlgProc */
BOOL FAR PASCAL SettingsDlgProc
(HWND hDlg,
unsigned message,
WORD wParam,
LONG lParam)
{
int ControlID;
switch (message)
{
case WM_INITDIALOG:
SendDlgItemMessage /* Limit number of characters that */
(hDlg, /* can be entered into edit control. */
IDC_EDIT,
EM_LIMITTEXT,
6,
NULL);
SendDlgItemMessage /* Assign current value of 'Prefix' */
(hDlg, /* to edit control. */
IDC_EDIT,
WM_SETTEXT,
NULL,
(DWORD)(char far *)Header.Prefix);
if (Header.DialType == 'T') /* Check radio button in 'Dial */
ControlID = IDC_TONE; /* Type' group corresponding to */
else /* current setting. */
ControlID = IDC_PULSE;
SendDlgItemMessage
(hDlg,
ControlID,
BM_SETCHECK,
1,
NULL);
if (strcmp (Header.Port, "COM1") == 0) /* Check button in */
ControlID = IDC_COM1; /* 'Port' group */
else if (strcmp (Header.Port, "COM2") == 0) /* for current */
ControlID = IDC_COM2; /* setting. */
else if (strcmp (Header.Port, "COM3") == 0)
ControlID = IDC_COM3;
else
ControlID = IDC_COM4;
SendDlgItemMessage
(hDlg,
ControlID,
BM_SETCHECK,
1,
NULL);
return (TRUE);
case WM_COMMAND:
switch (wParam)
{
case IDOK: /* User clicked OK button. */
SendDlgItemMessage /* Get selected 'Prefix' value. */
(hDlg,
IDC_EDIT,
WM_GETTEXT,
sizeof (Header.Prefix),
(DWORD)(char far *)Header.Prefix);
/* Get selected dial type value: */
if (SendDlgItemMessage (hDlg, IDC_TONE, BM_GETCHECK,
NULL, NULL))
Header.DialType = 'T';
else
Header.DialType = 'P';
/* Get selected port value: */
if (SendDlgItemMessage (hDlg, IDC_COM1, BM_GETCHECK,
NULL, NULL))
strcpy (Header.Port,"COM1");
else if (SendDlgItemMessage (hDlg, IDC_COM2, BM_GETCHECK,
NULL, NULL))
strcpy (Header.Port,"COM2");
else if (SendDlgItemMessage (hDlg, IDC_COM3, BM_GETCHECK,
NULL, NULL))
strcpy (Header.Port,"COM3");
else
strcpy (Header.Port,"COM4");
EndDialog (hDlg, TRUE); /* Remove dialog box. */
return (TRUE);
case IDCANCEL: /* User clicked 'Cancel' button */
/* or hit Escape. */
EndDialog (hDlg, TRUE); /* Remove dialog box. */
return (TRUE);
default:
return (FALSE); /* Dialog message NOT processed. */
}
default:
return (FALSE); /* Dialog message NOT processed. */
} /* end switch */
} /* end SettingsDlgProc */