home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
mag&info
/
msjv7_5.zip
/
WINCPP.ARJ
/
CPP1.ARJ
/
GENERIC.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-01
|
6KB
|
144 lines
// generic.cpp RHS 4/15/92
#include"WinApp.h"
#include"generic.h" // specific to this program
class myApp : public WinApp // derive new class from WinApp
{
public:
BOOL InitApplication(void);
BOOL InitInstance(void);
};
myApp theApp; // create an instance of myApp
BOOL myApp::InitApplication(void) // current instance
{
// Fill in window class structure with parameters that describe the
// main window.
WNDCLASS wc;
wc.style = NULL; // Class style(s).
wc.lpfnWndProc = MainWndProc; // Function to retrieve messages for
// windows of this class.
wc.cbClsExtra = 0; // No per-class extra data.
wc.cbWndExtra = 0; // No per-window extra data.
wc.hInstance = Instance(); // WinApp that owns the class.
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = "GenericMenu"; // Name of menu resource in .RC file.
wc.lpszClassName = "GenericWClass"; // Name used in call to CreateWindow.
// Register the window class and return success/failure code.
return RegisterClass(&wc);
}
BOOL myApp::InitInstance(void)
{
// Create a main window for this application instance.
// Main window handle.
HWND hWnd = CreateWindow(
"GenericWClass", // See RegisterClass() call.
"Generic Sample Application (C++ 1)", // Text for window title bar.
WS_OVERLAPPEDWINDOW, // Window style.
CW_USEDEFAULT, // Default horizontal position.
CW_USEDEFAULT, // Default vertical position.
CW_USEDEFAULT, // Default width.
CW_USEDEFAULT, // Default height.
NULL, // Overlapped windows have no parent.
NULL, // Use the window class menu.
Instance(), // This instance owns this window.
NULL // Pointer not needed.
);
// If window could not be created, return "failure"
if(!hWnd)
return FALSE;
// Make the window visible; update its client area; and return "success"
ShowWindow(hWnd, CmdShow()); // Show the window
UpdateWindow(hWnd); // Sends WM_PAINT message
return TRUE; // Returns the value from PostQuitMessage
}
long FAR PASCAL MainWndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND: // message: command from application menu
if(wParam == IDM_ABOUT)
{
DialogBox(theApp.Instance(), // current instance
"AboutBox", // resource to use
hWnd, // parent handle
(DLGPROC)About); // About() instance address
break;
}
else // Lets Windows process it
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_DESTROY: // message: window being destroyed
PostQuitMessage(0);
break;
default: // Passes it on if unproccessed
return DefWindowProc(hWnd, message, wParam, lParam);
}
return NULL;
}
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
// initialize the myApp object, theApp
theApp.Init(hInstance,hPrevInstance,lpCmdLine,nCmdShow);
// the following is the same logic as GENERIC.C
if(!theApp.PrevInstance())
if(!theApp.InitApplication())
return FALSE;
// Perform initializations that apply to a specific instance
if(!theApp.InitInstance())
return FALSE;
// Acquire and dispatch messages until a WM_QUIT message is received.
MSG msg; // message
while(GetMessage(&msg, // message structure
NULL, // handle of window receiving the message
NULL, // lowest message to examine
NULL)) // highest message to examine
{
TranslateMessage(&msg); // Translates virtual key codes
DispatchMessage(&msg); // Dispatches message to window
}
return(int)msg.wParam; // Returns the value from PostQuitMessage
}
BOOL FAR PASCAL About(HWND hDlg, UINT message, WPARAM wParam, LPARAM)
{
switch (message)
{
case WM_INITDIALOG: // message: initialize dialog box
return TRUE;
case WM_COMMAND: // message: received a command
if(wParam == IDOK // "OK" box selected?
|| wParam == IDCANCEL)
{ // System menu close command?
EndDialog(hDlg, TRUE); // Exits the dialog box
return TRUE;
}
break;
}
return FALSE; // Didn't process a message
}