home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windoware
/
WINDOWARE_1_6.iso
/
source
/
adg_4-6
/
custcntl.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-21
|
8KB
|
265 lines
/****************************************************************************
Module name: CustCntl.C
Programmer : Jeffrey M. Richter.
*****************************************************************************/
#include "..\nowindws.h"
#undef NOCOLOR
#undef NOCTLMGR
#undef NOGDI
#undef NOKERNEL
#undef NOLSTRING
#undef NOMB
#undef NOMENUS
#undef NOMINMAX
#undef NOMSG
#undef NORASTEROPS
#undef NOSHOWWINDOW
#undef NOSYSMETRICS
#undef NOUSER
#undef NOWINOFFSETS
#undef NOWINMESSAGES
#undef NOWINSTYLES
#include <windows.h>
#include "custcntl.h"
char _szAppName[] = "CustCntl";
HANDLE _hInstance = NULL; // Our instance handle
#define IDM_DEMO (0x0110) // Must be < 0xF000 (GetSystemMenu)
#define IDM_ABOUT (0x0120) // Must be < 0xF000
BOOL NEAR PASCAL RegisterAppWndClass (HANDLE hInstance);
BOOL FAR PASCAL AboutProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam);
BOOL FAR PASCAL CustCntlDlgProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam);
LONG FAR PASCAL AppWndProc (HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
// ***************************************************************************
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) {
MSG msg;
HWND hWnd;
HMENU hMenu;
HANDLE hLibMeter, hLibSpin;
_hInstance = hInstance;
if (hPrevInstance == NULL)
if (!RegisterAppWndClass(hInstance))
return(0);
hWnd = CreateWindow(_szAppName, _szAppName,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, nCmdShow, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, 0);
if (hWnd == NULL) return(0);
// Get handle to application's System Menu.
hMenu = GetSystemMenu(hWnd, 0);
// Append separator bar & two options.
AppendMenu(hMenu, MF_SEPARATOR, 0, 0);
AppendMenu(hMenu, MF_STRING,
IDM_DEMO, "&Custom control demo...");
AppendMenu(hMenu, MF_STRING, IDM_ABOUT, "A&bout...");
DrawMenuBar(hWnd);
hLibMeter = LoadLibrary("METER.DLL");
if (hLibMeter < 32) return(0);
hLibSpin = LoadLibrary("SPIN.DLL");
if (hLibSpin < 32) {
FreeLibrary(hLibMeter);
return(0);
}
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
FreeLibrary(hLibMeter);
FreeLibrary(hLibSpin);
return(0);
}
// ***************************************************************************
// This function registers the application's main window.
BOOL NEAR PASCAL RegisterAppWndClass (HANDLE hInstance) {
WNDCLASS WndClass;
WndClass.style = 0;
WndClass.lpfnWndProc = AppWndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(hInstance, _szAppName);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = COLOR_WINDOW + 1;
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = _szAppName;
return(RegisterClass(&WndClass));
}
// ***************************************************************************
// This function processes all messages sent to the modeless dialog box.
BOOL FAR PASCAL CustCntlDlgProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam) {
BOOL fProcessed = TRUE;
int x;
switch (wMsg) {
case WM_INITDIALOG:
// Tell Meter control that the job consists of 25 parts.
SendDlgItemMessage(hDlg, ID_METER, MM_SETPARTSINJOB, 25, 0);
// Tell Meter control that the zero parts of the job are complete.
SendDlgItemMessage(hDlg, ID_METER, MM_SETPARTSCOMPLETE, 0, 0);
// Tell Spin Button that the valid range is 0 to 25.
SendDlgItemMessage(hDlg, ID_SPIN, SPNM_SETRANGE, 0,
MAKELONG(0, 25));
// Tell Spin Button that the current value is 0.
SendDlgItemMessage(hDlg, ID_SPIN, SPNM_SETCRNTVALUE, 0, 0);
break;
case WM_COMMAND:
switch (wParam) {
case ID_SPIN:
switch (HIWORD(lParam)) {
case SPNN_VALUECHANGE:
// User has changed the current value of the Spin Button.
// Request the current value from the Spin Button.
x = (int) SendMessage(LOWORD(lParam), SPNM_GETCRNTVALUE, 0, 0);
// Tells the Meter control the new number of parts that
// are complete. This is an example of the Meter control
// allows for the "parts-complete" value to go both
// up and down.
SendDlgItemMessage(hDlg, ID_METER, MM_SETPARTSCOMPLETE,
x, 0);
// Update the static window to reflect the current value
// in the Spin Button.
SetDlgItemInt(hDlg, ID_SPINVALUE, x, FALSE);
break;
}
break;
case IDOK:
case IDCANCEL:
EndDialog(hDlg, wParam);
break;
default: break;
}
break;
default:
fProcessed = FALSE;
break;
}
return(fProcessed);
}
// ***************************************************************************
// This function processes all messages sent to the app's main window.
LONG FAR PASCAL AppWndProc (HWND hWnd, WORD wMsg, WORD wParam, LONG lParam) {
BOOL fCallDefProc = FALSE;
LONG lResult = 0;
FARPROC fpProc;
switch (wMsg) {
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_SYSCOMMAND:
// Any menu option selected from CustCntl's System Menu.
// Any option's that we appended to System menu should be
// processed by CustCntl and NOT passed to DefWindowProc.
switch (wParam & 0xfff0) {
case IDM_ABOUT:
// Display about box
fpProc = MakeProcInstance(AboutProc, _hInstance);
DialogBox(_hInstance, "About", hWnd, fpProc);
FreeProcInstance(fpProc);
break;
case IDM_DEMO:
// Display about box
fpProc = MakeProcInstance(CustCntlDlgProc, _hInstance);
DialogBox(_hInstance, "CustCntl", hWnd, fpProc);
FreeProcInstance(fpProc);
break;
default:
// Any option's that we do not process should be
// passed to DefWindowProc.
fCallDefProc = TRUE;
break;
}
break;
default:
fCallDefProc = TRUE; break;
}
if (fCallDefProc)
lResult = DefWindowProc(hWnd, wMsg, wParam, lParam);
return(lResult);
}
// ***************************************************************************
// This function processess all messages sent to the About dialog box.
BOOL FAR PASCAL AboutProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam) {
char szBuffer[100];
BOOL fProcessed = TRUE;
switch (wMsg) {
case WM_INITDIALOG:
// Set version static window to have date and time of compilation.
wsprintf(szBuffer, "%s at %s", (LPSTR) __DATE__, (LPSTR) __TIME__);
SetWindowText(GetDlgItem(hDlg, ID_VERSION), szBuffer);
break;
case WM_COMMAND:
switch (wParam) {
case IDOK:
case IDCANCEL:
if (HIWORD(lParam) == BN_CLICKED)
EndDialog(hDlg, wParam);
break;
default:
break;
}
break;
default:
fProcessed = FALSE; break;
}
return(fProcessed);
}