home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / qexit.zip / QEXIT.C < prev    next >
Text File  |  1990-11-25  |  5KB  |  173 lines

  1. /****************************************************************************
  2.  
  3.       Qexit
  4.       Copyright (c) 1990, Greg Leman
  5.       4600 University Drive #212
  6.       Durham, NC  27707
  7.  
  8.     PROGRAM: qexit.c
  9.  
  10.     PURPOSE: qexit template for Windows applications
  11.  
  12.     FUNCTIONS:
  13.  
  14.     WinMain() - calls initialization function, processes message loop
  15.     qexitInit() - initializes window data and registers window
  16.     qexitWndProc() - processes messages
  17.     About() - processes messages for "About" dialog box
  18.  
  19. ****************************************************************************/
  20.  
  21. #include "windows.h"            /* required for all Windows applications */
  22. #include "qexit.h"            /* specific to this program             */
  23.  
  24. HANDLE hInst;                /* current instance                 */
  25. HANDLE hMenu;             /* Handle to my new menu                        */
  26.  
  27. /****************************************************************************
  28.  
  29.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  30.  
  31.     PURPOSE: calls initialization function, processes message loop
  32.  
  33.     COMMENTS:
  34.  
  35.     This will initialize the window class if it is the first time this
  36.     application is run.  It then creates the window, and processes the
  37.     message loop until a PostQuitMessage is received.  It exits the
  38.     application by returning the value passed by the PostQuitMessage.
  39.  
  40. ****************************************************************************/
  41.  
  42. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  43. HANDLE hInstance;                 /* current instance         */
  44. HANDLE hPrevInstance;                 /* previous instance         */
  45. LPSTR lpCmdLine;                 /* command line             */
  46. int nCmdShow;                     /* show-window type (open/icon) */
  47. {
  48.     HWND hWnd;                     /* window handle             */
  49.     MSG msg;                     /* message                 */
  50.  
  51.  
  52.    if (!hPrevInstance)            /* Has application been initialized? */
  53.     if (!qexitInit(hInstance))
  54.         return (NULL);           /* Exits if unable to initialize     */
  55.  
  56.    hInst = hInstance;            /* Saves the current instance         */
  57.  
  58.    hMenu = LoadMenu(hInstance, "qexitMenu");
  59.    hWnd = CreateWindow("qexit",  /* window class         */
  60.      "Quick Exit",  /* window name         */
  61.     WS_OVERLAPPEDWINDOW,              /* window style         */
  62.     CW_USEDEFAULT,                  /* x position             */
  63.     CW_USEDEFAULT,                  /* y position             */
  64.     CW_USEDEFAULT,                  /* width             */
  65.     CW_USEDEFAULT,                  /* height             */
  66.     NULL,                      /* parent handle         */
  67.     hMenu,                      /* menu or child ID         */
  68.     hInstance,                  /* instance             */
  69.     NULL);                      /* additional info         */
  70.  
  71.     if (!hWnd)                      /* Was the window created? */
  72.     return (NULL);
  73.  
  74.     ShowWindow(hWnd, 0xFF8F);              /* Shows the window         */
  75.  
  76.     while (GetMessage(&msg,       /* message structure                 */
  77.         NULL,           /* handle of window receiving the message */
  78.         NULL,           /* lowest message to examine             */
  79.         NULL))           /* highest message to examine         */
  80.     {
  81.     TranslateMessage(&msg);       /* Translates virtual key codes         */
  82.     DispatchMessage(&msg);       /* Dispatches message to window         */
  83.     }
  84.     return (msg.wParam);       /* Returns the value from PostQuitMessage */
  85. }
  86.  
  87.  
  88. /****************************************************************************
  89.  
  90.     FUNCTION: qexitInit(HANDLE)
  91.  
  92.     PURPOSE: Initializes window data and registers window class
  93.  
  94. ****************************************************************************/
  95.  
  96. BOOL qexitInit(hInstance)
  97. HANDLE hInstance;                   /* current instance         */
  98. {
  99.     HANDLE hMemory;                   /* handle to allocated memory */
  100.     PWNDCLASS pWndClass;               /* structure pointer         */
  101.     BOOL bSuccess;                   /* RegisterClass() result     */
  102.  
  103.     hMemory = LocalAlloc(LPTR, sizeof(WNDCLASS));
  104.     pWndClass = (PWNDCLASS) LocalLock(hMemory);
  105.  
  106.     pWndClass->style = NULL;
  107.     pWndClass->lpfnWndProc = qexitWndProc;
  108.     pWndClass->hInstance = hInstance;
  109.     pWndClass->hIcon = LoadIcon(hInstance, "qexit");
  110.     pWndClass->hCursor = LoadCursor(NULL, IDC_ARROW);
  111.     pWndClass->hbrBackground = GetStockObject(WHITE_BRUSH);
  112.     pWndClass->lpszMenuName = "qexitMenu";
  113.     pWndClass->lpszClassName = (LPSTR) "qexit";
  114.  
  115.     bSuccess = RegisterClass(pWndClass);
  116.  
  117.     LocalUnlock(hMemory);                /* Unlocks the memory    */
  118.     LocalFree(hMemory);                    /* Returns it to Windows */
  119.  
  120.     return (bSuccess);         /* Returns result of registering the window */
  121. }
  122.  
  123. /****************************************************************************
  124.  
  125.     FUNCTION: qexitWndProc(HWND, unsigned, WORD, LONG)
  126.  
  127.     PURPOSE:  Processes messages
  128.  
  129.     MESSAGES:
  130.  
  131.     WM_CREATE    - create window
  132.     WM_DESTROY    - destroy window
  133.     WM_COMMAND    - menu selections and others
  134.  
  135.     COMMENTS:
  136.  
  137.  
  138. ****************************************************************************/
  139.  
  140. long FAR PASCAL qexitWndProc(hWnd, message, wParam, lParam)
  141. HWND hWnd;                  /* window handle             */
  142. unsigned message;              /* type of message             */
  143. WORD wParam;                  /* additional information         */
  144. LONG lParam;                  /* additional information         */
  145. {
  146.     HMENU hMenu;              /* handle to the System menu         */
  147.  
  148.     switch (message) {
  149.  
  150.     case WM_CREATE:                /* message: window being created */
  151.         break;
  152.  
  153.     case WM_DESTROY:          /* message: window being destroyed */
  154.         PostQuitMessage(0);
  155.         break;
  156.  
  157.    case WM_QUERYOPEN:
  158.          if( MessageBox(hWnd,"Are you Very Sure?",
  159.                   (LPSTR) "Exiting Windows", MB_OKCANCEL|MB_ICONEXCLAMATION)
  160.            == IDOK)
  161.              {     
  162.                      DestroyWindow(hWnd);
  163.                   ExitWindows( (DWORD)NULL, 1);
  164.              }
  165.       break;
  166.  
  167.     default:              /* Passes it on if unproccessed    */
  168.         return (DefWindowProc(hWnd, message, wParam, lParam));
  169.     }
  170.     return (NULL);
  171. }
  172.  
  173.