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

  1. /*
  2.  *  Function Name:   DestroyCaret
  3.  *  Program Name:    decaret.c
  4.  *  Special Notes:
  5.  *
  6.  *  SDK Version:         2.03
  7.  *  Runtime Version:     2.03
  8.  *  Microsoft C Version: 5.0
  9.  *
  10.  *  Description:
  11.  *   The program below will display a caret and then destroy it.
  12.  *
  13.  *   Microsoft Product Support Services
  14.  *   Windows Version 2.0 function demonstration application
  15.  *
  16.  */
  17.  
  18. #include <windows.h>
  19.  
  20. long    FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  21.  
  22. int    PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  23. HANDLE       hInstance, hPrevInstance;
  24. LPSTR       lpszCmdLine;
  25. int    cmdShow;
  26. {
  27.   MSG         msg;
  28.   HWND         hWnd;
  29.   HMENU      hMenu;
  30.   WNDCLASS   wcClass;
  31.  
  32.   if (!hPrevInstance)
  33.   {
  34.     wcClass.style       = CS_HREDRAW | CS_VREDRAW;
  35.     wcClass.lpfnWndProc    = WndProc;
  36.     wcClass.cbClsExtra       = 0;
  37.     wcClass.cbWndExtra       = 0;
  38.     wcClass.hInstance       = hInstance;
  39.     wcClass.hIcon       = LoadIcon(hInstance, NULL);
  40.     wcClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  41.     wcClass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
  42.     wcClass.lpszMenuName   = NULL;
  43.     wcClass.lpszClassName  = "DestroyCaret";
  44.  
  45.     if (!RegisterClass(&wcClass))
  46.       return FALSE;
  47.   }
  48.  
  49.   hWnd = CreateWindow("DestroyCaret",
  50.       "DestroyCaret()",
  51.       WS_OVERLAPPEDWINDOW,
  52.       CW_USEDEFAULT,
  53.       CW_USEDEFAULT,
  54.       CW_USEDEFAULT,
  55.       CW_USEDEFAULT,
  56.       NULL,
  57.       NULL,
  58.       hInstance,
  59.       NULL);
  60.  
  61.   ShowWindow(hWnd, cmdShow);
  62.   UpdateWindow(hWnd);
  63.  
  64.   while (GetMessage(&msg, NULL, 0, 0))
  65.   {
  66.     TranslateMessage(&msg);
  67.     DispatchMessage(&msg);
  68.   }
  69.   return msg.wParam;
  70. }
  71.  
  72.  
  73. long    FAR PASCAL WndProc(hWnd, message, wParam, lParam)
  74. HWND       hWnd;
  75. unsigned    message;
  76. WORD       wParam;
  77. LONG       lParam;
  78. {
  79.   PAINTSTRUCT ps;
  80.  
  81.   switch (message)
  82.   {
  83.   case WM_PAINT:
  84.     {
  85.       BeginPaint(hWnd, &ps);
  86.       if (!IsIconic (hWnd))
  87.       {
  88.     CreateCaret (hWnd, NULL, 10, 20);
  89.     SetCaretPos (40, 40);
  90.     ShowCaret (hWnd);
  91.     MessageBox(hWnd,
  92.         "Caret shown, press return to destroy",
  93.         "DestroyCaret", MB_OK);
  94.     DestroyCaret();
  95.       }
  96.       ValidateRect(hWnd, NULL);
  97.       EndPaint(hWnd, &ps);
  98.       break;
  99.     }
  100.   case WM_DESTROY:
  101.     {
  102.       PostQuitMessage(0);
  103.       break;
  104.     }
  105.   default:
  106.     return DefWindowProc(hWnd, message, wParam, lParam);
  107.   }
  108.   return(0L);
  109. }
  110.  
  111.  
  112.