home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / window / dewindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  2.3 KB  |  96 lines

  1. /*
  2.  *  Function Name:   DestroyWindow
  3.  *  Program Name:    dewindow.c
  4.  *  SDK Version:         2.03
  5.  *  Runtime Version:     2.03
  6.  *  Microsoft C Version: 5.0
  7.  *
  8.  *  Description:
  9.  *   This program will destroy the window, leaving just a message box.
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  15.  
  16. int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  17. HANDLE     hInstance, hPrevInstance;
  18. LPSTR     lpszCmdLine;
  19. int     cmdShow;
  20.   {
  21.   MSG         msg;
  22.   HWND         hWnd;
  23.   WNDCLASS   wcClass;
  24.  
  25.   if (!hPrevInstance)
  26.     {
  27.     wcClass.style       = CS_HREDRAW | CS_VREDRAW;
  28.     wcClass.lpfnWndProc    = WndProc;
  29.     wcClass.cbClsExtra       = 0;
  30.     wcClass.cbWndExtra       = 0;
  31.     wcClass.hInstance       = hInstance;
  32.     wcClass.hIcon       = LoadIcon(hInstance, NULL);
  33.     wcClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  34.     wcClass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
  35.     wcClass.lpszMenuName   = NULL;
  36.     wcClass.lpszClassName  = "DestroyWindow";
  37.  
  38.     if (!RegisterClass(&wcClass))
  39.       return FALSE;
  40.     }
  41.  
  42.   hWnd = CreateWindow("DestroyWindow",
  43.               "DestroyWindow()",
  44.               WS_OVERLAPPEDWINDOW,
  45.               CW_USEDEFAULT,
  46.               CW_USEDEFAULT,
  47.               CW_USEDEFAULT,
  48.               CW_USEDEFAULT,
  49.               NULL,
  50.               NULL,
  51.               hInstance,
  52.               NULL);
  53.  
  54.   ShowWindow(hWnd, cmdShow);
  55.   UpdateWindow(hWnd);
  56.   while (GetMessage(&msg, NULL, 0, 0))
  57.     {
  58.     TranslateMessage(&msg);
  59.     DispatchMessage(&msg);
  60.     }
  61.   return msg.wParam;
  62.   }
  63.  
  64. long FAR PASCAL WndProc(hWnd, message, wParam, lParam)
  65. HWND       hWnd;
  66. unsigned   message;
  67. WORD       wParam;
  68. LONG       lParam;
  69.   {
  70.   PAINTSTRUCT ps;
  71.   BOOL        bDestroyed;
  72.   HDC          hDC;
  73.  
  74.   switch (message)
  75.     {
  76.     case WM_PAINT:
  77.       BeginPaint(hWnd, &ps);
  78.       hDC=ps.hdc;
  79.       TextOut(hDC, 10, 10, "End program to demonstrate", 26);
  80.       ValidateRect(hWnd, NULL);
  81.       EndPaint(hWnd, &ps);
  82.       break;
  83.     case WM_CLOSE:
  84.       bDestroyed = DestroyWindow(hWnd);
  85.       MessageBox(hWnd, "Window was just destroyed", "DestroyWindow", MB_OK);
  86.       return DefWindowProc(hWnd, message, wParam, lParam);
  87.       break;
  88.     case WM_DESTROY:
  89.       PostQuitMessage(0);
  90.       break;
  91.     default:
  92.       return DefWindowProc(hWnd, message, wParam, lParam);
  93.     }
  94.   return(0L);
  95.   }
  96.