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 >
C/C++ Source or Header  |  1992-09-01  |  4KB  |  118 lines

  1. // generic.cpp RHS 4/15/92
  2.  
  3. #include"WinApp.h"
  4. #include"generic.h"        // specific to this program
  5.  
  6. class myApp : public WinApp    // derive new class from WinApp
  7.     {
  8. public:
  9.     // override virtual functions
  10.     BOOL InitInstance(void);        
  11.     BOOL InitApplication(void);        
  12.     };
  13.  
  14. myApp theApp;                       // create an instance of myApp
  15.  
  16. BOOL myApp::InitApplication(void)
  17.     {
  18.     mainWnd = new Window();
  19.  
  20.     if(!mainWnd->RegisterClass(
  21.             NULL,
  22.             MainWndProc,
  23.             "GenericMenu",
  24.             "GenericWClass"))
  25.         return FALSE;
  26.     return TRUE;
  27.     }
  28.  
  29. BOOL myApp::InitInstance(void)
  30.     {
  31.     if(!mainWnd->CreateWindow(
  32.             "GenericWClass",            // classname
  33.             "Generic Sample Application (C++ 2)", // text
  34.             WS_OVERLAPPEDWINDOW))       // style
  35.         return FALSE;
  36.  
  37.     mainWnd->ShowWindow();              // Show the window                        
  38.     mainWnd->UpdateWindow();            // Sends WM_PAINT message                 
  39.     return TRUE;                        // Returns the value from PostQuitMessage 
  40.     }
  41.  
  42. long FAR PASCAL MainWndProc(HWND hWnd, UINT message, 
  43.     WPARAM wParam, LPARAM lParam)
  44.     {
  45.     switch (message) 
  46.         {
  47.         case WM_COMMAND:       // message: command from application menu 
  48.             if(wParam == IDM_ABOUT) 
  49.                 {
  50.                 DialogBox(theApp.Instance(),    // current instance         
  51.                     "AboutBox",            // resource to use         
  52.                     hWnd,                // parent handle         
  53.                     (DLGPROC)About);    // About() instance address 
  54.                 break;
  55.                 }
  56.             else                // Lets Windows process it         
  57.                 return DefWindowProc(hWnd, message, wParam, lParam);
  58.  
  59.         case WM_DESTROY:          // message: window being destroyed 
  60.             PostQuitMessage(0);
  61.             break;
  62.  
  63.         default:              // Passes it on if unproccessed    
  64.             return DefWindowProc(hWnd, message, wParam, lParam);
  65.         }
  66.     return NULL;
  67.     }
  68.  
  69. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, 
  70.     LPSTR lpCmdLine, int nCmdShow)
  71.     {
  72.         // initialize the myApp object, theApp
  73.     theApp.Init(hInstance,hPrevInstance,lpCmdLine,nCmdShow);
  74.  
  75.         // the following is the same logic as GENERIC.C
  76.     if(!theApp.PrevInstance())
  77.         if(!theApp.InitApplication())
  78.             return FALSE;
  79.  
  80.     // Perform initializations that apply to a specific instance 
  81.  
  82.     if(!theApp.InitInstance())
  83.         return FALSE;
  84.  
  85.     // Acquire and dispatch messages until a WM_QUIT message is received. 
  86.     MSG msg;            // message                 
  87.  
  88.     while(GetMessage(&msg,       // message structure                 
  89.         NULL,           // handle of window receiving the message 
  90.         NULL,           // lowest message to examine             
  91.         NULL))           // highest message to examine         
  92.         {
  93.         TranslateMessage(&msg);       // Translates virtual key codes         
  94.         DispatchMessage(&msg);       // Dispatches message to window         
  95.         }
  96.     return(int)msg.wParam;       // Returns the value from PostQuitMessage 
  97.     }
  98.  
  99. BOOL FAR PASCAL About(HWND hDlg, UINT message, WPARAM wParam, LPARAM)
  100.     {
  101.     switch (message) 
  102.         {
  103.         case WM_INITDIALOG:           // message: initialize dialog box 
  104.             return TRUE;
  105.  
  106.         case WM_COMMAND:              // message: received a command 
  107.             if(wParam == IDOK                // "OK" box selected?         
  108.                     || wParam == IDCANCEL) 
  109.                 {      // System menu close command? 
  110.                 EndDialog(hDlg, TRUE);          // Exits the dialog box         
  111.                 return TRUE;
  112.                 }
  113.             break;
  114.         }
  115.     return FALSE;                  // Didn't process a message    
  116.     }
  117.     
  118.