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 >
C/C++ Source or Header  |  1992-09-01  |  6KB  |  144 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.     BOOL InitApplication(void);
  10.     BOOL InitInstance(void);        
  11.     };
  12.  
  13. myApp theApp;                       // create an instance of myApp
  14.  
  15. BOOL myApp::InitApplication(void)           // current instance         
  16.     {
  17.     // Fill in window class structure with parameters that describe the       
  18.     // main window.                                                           
  19.     WNDCLASS  wc;
  20.  
  21.     wc.style = NULL;                    // Class style(s).                    
  22.     wc.lpfnWndProc = MainWndProc;       // Function to retrieve messages for  
  23.                                         // windows of this class.             
  24.     wc.cbClsExtra = 0;                  // No per-class extra data.           
  25.     wc.cbWndExtra = 0;                  // No per-window extra data.          
  26.     wc.hInstance = Instance();          // WinApp that owns the class.   
  27.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  28.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  29.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  30.     wc.lpszMenuName =  "GenericMenu";   // Name of menu resource in .RC file. 
  31.     wc.lpszClassName = "GenericWClass"; // Name used in call to CreateWindow. 
  32.  
  33.     // Register the window class and return success/failure code. 
  34.     return RegisterClass(&wc);
  35.     }
  36.  
  37. BOOL myApp::InitInstance(void)
  38.     {
  39.     // Create a main window for this application instance.  
  40.  
  41.     // Main window handle.                
  42.     HWND hWnd = CreateWindow(
  43.         "GenericWClass",                // See RegisterClass() call.          
  44.         "Generic Sample Application (C++ 1)",   // Text for window title bar.         
  45.         WS_OVERLAPPEDWINDOW,            // Window style.                      
  46.         CW_USEDEFAULT,                  // Default horizontal position.       
  47.         CW_USEDEFAULT,                  // Default vertical position.         
  48.         CW_USEDEFAULT,                  // Default width.                     
  49.         CW_USEDEFAULT,                  // Default height.                    
  50.         NULL,                           // Overlapped windows have no parent. 
  51.         NULL,                           // Use the window class menu.         
  52.         Instance(),                     // This instance owns this window.    
  53.         NULL                            // Pointer not needed.                
  54.     );
  55.  
  56.     // If window could not be created, return "failure" 
  57.  
  58.     if(!hWnd)
  59.         return FALSE;
  60.  
  61.     // Make the window visible; update its client area; and return "success" 
  62.  
  63.     ShowWindow(hWnd, CmdShow());  // Show the window                        
  64.     UpdateWindow(hWnd);          // Sends WM_PAINT message                 
  65.     return TRUE;               // Returns the value from PostQuitMessage 
  66.     }
  67.  
  68. long FAR PASCAL MainWndProc(HWND hWnd, UINT message, 
  69.     WPARAM wParam, LPARAM lParam)
  70.     {
  71.     switch (message) 
  72.         {
  73.         case WM_COMMAND:       // message: command from application menu 
  74.             if(wParam == IDM_ABOUT) 
  75.                 {
  76.                 DialogBox(theApp.Instance(),    // current instance         
  77.                     "AboutBox",            // resource to use         
  78.                     hWnd,                // parent handle         
  79.                     (DLGPROC)About);        // About() instance address 
  80.                 break;
  81.                 }
  82.             else                // Lets Windows process it         
  83.                 return DefWindowProc(hWnd, message, wParam, lParam);
  84.  
  85.         case WM_DESTROY:          // message: window being destroyed 
  86.             PostQuitMessage(0);
  87.             break;
  88.  
  89.         default:              // Passes it on if unproccessed    
  90.             return DefWindowProc(hWnd, message, wParam, lParam);
  91.         }
  92.     return NULL;
  93.     }
  94.  
  95. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, 
  96.     LPSTR lpCmdLine, int nCmdShow)
  97.     {
  98.         // initialize the myApp object, theApp
  99.     theApp.Init(hInstance,hPrevInstance,lpCmdLine,nCmdShow);
  100.  
  101.         // the following is the same logic as GENERIC.C
  102.     if(!theApp.PrevInstance())
  103.         if(!theApp.InitApplication())
  104.             return FALSE;
  105.  
  106.     // Perform initializations that apply to a specific instance 
  107.     if(!theApp.InitInstance())
  108.         return FALSE;
  109.  
  110.     // Acquire and dispatch messages until a WM_QUIT message is received. 
  111.     MSG msg;            // message                 
  112.  
  113.     while(GetMessage(&msg,       // message structure                 
  114.         NULL,           // handle of window receiving the message 
  115.         NULL,           // lowest message to examine             
  116.         NULL))           // highest message to examine         
  117.         {
  118.         TranslateMessage(&msg);       // Translates virtual key codes         
  119.         DispatchMessage(&msg);       // Dispatches message to window         
  120.         }
  121.     return(int)msg.wParam;       // Returns the value from PostQuitMessage 
  122.     }
  123.  
  124.  
  125. BOOL FAR PASCAL About(HWND hDlg, UINT message, WPARAM wParam, LPARAM)
  126.     {
  127.     switch (message) 
  128.         {
  129.         case WM_INITDIALOG:           // message: initialize dialog box 
  130.             return TRUE;
  131.  
  132.         case WM_COMMAND:              // message: received a command 
  133.             if(wParam == IDOK                // "OK" box selected?         
  134.                     || wParam == IDCANCEL) 
  135.                 {      // System menu close command? 
  136.                 EndDialog(hDlg, TRUE);          // Exits the dialog box         
  137.                 return TRUE;
  138.                 }
  139.             break;
  140.         }
  141.     return FALSE;                  // Didn't process a message    
  142.     }
  143.     
  144.