home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
mag&info
/
msjv7_5.zip
/
WINCPP.ARJ
/
CPP2.ARJ
/
GENERIC.CPP
next >
Wrap
C/C++ Source or Header
|
1992-09-01
|
4KB
|
118 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:
// override virtual functions
BOOL InitInstance(void);
BOOL InitApplication(void);
};
myApp theApp; // create an instance of myApp
BOOL myApp::InitApplication(void)
{
mainWnd = new Window();
if(!mainWnd->RegisterClass(
NULL,
MainWndProc,
"GenericMenu",
"GenericWClass"))
return FALSE;
return TRUE;
}
BOOL myApp::InitInstance(void)
{
if(!mainWnd->CreateWindow(
"GenericWClass", // classname
"Generic Sample Application (C++ 2)", // text
WS_OVERLAPPEDWINDOW)) // style
return FALSE;
mainWnd->ShowWindow(); // Show the window
mainWnd->UpdateWindow(); // 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
}