home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 8 / 08.iso / d / d022 / 1.ddi / SAMPLES / CALC / CALC.C next >
Encoding:
C/C++ Source or Header  |  1990-07-09  |  5.5 KB  |  145 lines

  1. /*Filename: CALC.C                                          */
  2. /*"CALC" Generated by WindowsMAKER                          */
  3. /*Author: Bill G.                                           */
  4.  
  5. #include <WINDOWS.H>
  6. #include "CALC.H"
  7.  
  8.  
  9. HANDLE hInst;  /* Handle to instance.   */
  10. HWND MainhWnd; /* Handle to main window.*/
  11.  
  12. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  13. HANDLE hInstance;                 /* current instance                    */
  14. HANDLE hPrevInstance;             /* previous instance                   */
  15. LPSTR lpCmdLine;                  /* command line                        */
  16. int nCmdShow;                     /* show-window type (open/icon)        */
  17.     {
  18.     MSG msg;                      /* message                             */
  19.  
  20.     hInst = hInstance;            /* Saves the current instance               */
  21.  
  22.     
  23.     lpCmdLine; /* Long pointer to command line. */
  24.  
  25.     if (!hPrevInstance)           /* Is there an other instance of the task   */
  26.         {
  27.         if (!BLDInitClass(hInstance))
  28.             return FALSE;         /* Exits if unable to initialize            */
  29.         }
  30.  
  31.     MainhWnd = BLDInitMainWindow(hInstance);
  32.     if (!MainhWnd)                /* Check if the window is created           */
  33.         return FALSE;
  34.  
  35.     ShowWindow(MainhWnd, nCmdShow); /* Show the window                     */
  36.     UpdateWindow(MainhWnd);         /* Send WM_PAINT message to window     */
  37.  
  38.  
  39.  
  40.     while (GetMessage(&msg,     /* message structure                        */
  41.         0,                      /* handle of window receiving the message   */
  42.         0,                      /* lowest message to examine                */
  43.         0))                     /* highest message to examine               */
  44.         {
  45.         TranslateMessage(&msg);  /* Translates character keys                */
  46.         DispatchMessage(&msg);   /* Dispatches message to window             */
  47.         }
  48.     return(msg.wParam);          /* Returns the value from PostQuitMessage   */
  49.     }
  50.  
  51.  
  52.  
  53. long FAR PASCAL CALCWndProc(hWnd, message, wParam, lParam)
  54. HWND hWnd;                       /* window handle                            */
  55. unsigned message;                /* type of message                          */
  56. WORD wParam;                     /* additional information                   */
  57. LONG lParam;                     /* additional information                   */
  58.     {
  59.  
  60.     switch (message)
  61.         {
  62.  
  63.     case WM_COMMAND:             /* command from application menu     */
  64.         switch(wParam)
  65.             {
  66.         default:     
  67.             return BLD_WM_COMMANDMsg(hWnd,message,wParam,lParam);
  68.             }
  69.         break;
  70.     case WM_CHAR:
  71.         return BLD_WM_CHARMsg(hWnd,message,wParam,lParam);
  72.         break;
  73.     case WM_DESTROY:             /* window being destroyed                   */
  74.         PostQuitMessage(0);
  75.         break;
  76.     default:
  77.         /* Pass on message for default processing */
  78.         return(DefWindowProc(hWnd, message, wParam, lParam));
  79.         }
  80.     return FALSE;                /* Returns FALSE if processed by this WndProc*/
  81.     }
  82.      
  83.      
  84.      
  85. BOOL BLDInitClass(hInstance)
  86. HANDLE hInstance;
  87.     {
  88.     WNDCLASS WndClass;
  89.   
  90.     WndClass.style         = 0;
  91.     WndClass.lpfnWndProc   = CALCWndProc;
  92.     WndClass.cbClsExtra    = 0;
  93.     WndClass.cbWndExtra    = 0;
  94.     WndClass.hInstance     = hInstance;
  95.     WndClass.hIcon         = LoadIcon(hInstance,"CALC");
  96.     WndClass.hCursor       = LoadCursor(NULL,IDC_ARROW);
  97.     WndClass.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  98.     WndClass.lpszMenuName  = NULL;
  99.     WndClass.lpszClassName = "CALC";
  100.     
  101.     BLD_MainClassClsInit(&WndClass);
  102.  
  103.     return RegisterClass(&WndClass);
  104.     }
  105.     
  106.     
  107.     
  108. HWND BLDInitMainWindow(hInstance)
  109. HANDLE hInstance;
  110.     {
  111.     HWND hWnd;                  /* window handle                       */
  112.     int coordinate[4];          /* Coordinates of main window          */
  113.     DWORD WndStyle;             /* Style for main window               */
  114.     PSTR pInfo;                 /* Points to Info sent at WM_CREATE    */
  115.  
  116.     /* Initial value of main window parameters */
  117.     WndStyle    =WS_OVERLAPPED|WS_THICKFRAME|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX;
  118.     pInfo       =NULL;
  119.     coordinate[0]=CW_USEDEFAULT;
  120.     coordinate[1]=0;
  121.     coordinate[2]=CW_USEDEFAULT;
  122.     coordinate[3]=0;
  123.     
  124.     hWnd=BLD_MainWindowWndInit(&WndStyle,&coordinate[0],&pInfo);
  125.     if (hWnd)
  126.         return hWnd;
  127.  
  128.     hWnd = CreateWindow("CALC",  /* WndClass registered earlier  */
  129.            "All the Child Windows/Controls in CALCDLG.DLG will be put in this Window",          /* window title in title bar                  */
  130.            WndStyle,               /* window style                             */
  131.            coordinate[0],          /* x position                               */
  132.            coordinate[1],          /* y position                               */
  133.            coordinate[2],          /* width                                    */
  134.            coordinate[3],          /* height                                   */
  135.            0,                      /* parent handle                            */
  136.            0,                      /* menu or child ID                         */
  137.            hInstance,              /* instance                                 */
  138.            (LPSTR)pInfo);          /* additional info                          */
  139.  
  140.     return hWnd;
  141.     }
  142.     
  143.     
  144.     
  145.