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

  1. /*
  2.  *  ShowCaret
  3.  *  shwcaret.c
  4.  *
  5.  *  This program demonstrates the use of the function ShowCaret.
  6.  *  This function shows the system caret on the display at the
  7.  *  caret's current position.  Once shown, the caret begins flashing
  8.  *  automatically.
  9.  *
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. /* Procedure called when the application is loaded for the first time */
  15. BOOL WinInit( hInstance )
  16. HANDLE hInstance;
  17. {
  18.     PWNDCLASS   pClass;
  19.  
  20.     pClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS) );
  21.  
  22.     /* registering the parent window class */
  23.     pClass->hCursor        = LoadCursor( NULL, IDC_ARROW );
  24.     pClass->lpszMenuName   = (LPSTR)NULL;
  25.     pClass->lpszClassName  = (LPSTR)"Window";
  26.     pClass->hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  27.     pClass->hInstance      = hInstance;
  28.     pClass->style          = CS_HREDRAW | CS_VREDRAW;
  29.     pClass->lpfnWndProc    = DefWindowProc;
  30.  
  31.     if (!RegisterClass( (LPWNDCLASS)pClass ) )
  32.         /* Initialization failed.
  33.          * Windows will automatically deallocate all allocated memory.
  34.          */
  35.         return FALSE;
  36.  
  37.     LocalFree( (HANDLE) pClass );
  38.     return TRUE;        /* Initialization succeeded */
  39. }
  40.  
  41.  
  42. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  43. HANDLE hInstance, hPrevInstance;
  44. LPSTR lpszCmdLine;
  45. int cmdShow;
  46. {
  47.     HWND         hWnd;                /* Handle to the parent window    */
  48.  
  49.     WinInit (hInstance);
  50.  
  51.     hWnd = CreateWindow((LPSTR)"Window",
  52.             (LPSTR)"ShowCaret",
  53.                         WS_OVERLAPPEDWINDOW,
  54.                         CW_USEDEFAULT,     /* x         */
  55.                         CW_USEDEFAULT,     /* y         */
  56.                         CW_USEDEFAULT,     /* width     */
  57.                         CW_USEDEFAULT,     /* height    */
  58.                         (HWND)NULL,        /* no parent */
  59.                         (HMENU)NULL,       /* use class menu */
  60.                         (HANDLE)hInstance, /* handle to window instance */
  61.                         (LPSTR)NULL        /* no params to pass on */
  62.                        );
  63.  
  64.     /* Make window visible according to the way the app is activated */
  65.     ShowWindow( hWnd, cmdShow );
  66.     UpdateWindow( hWnd );
  67.  
  68. /*************************************************************************/
  69.  
  70.     CreateCaret (hWnd, NULL, 8, 12); /* Create a caret before showing */
  71.     SetCaretPos (50,50);    
  72.     ShowCaret (hWnd);             /* ShowCaret doesn't return a value */
  73.  
  74. /*************************************************************************/
  75.  
  76.     /* Message Box will make the parent window inactive */
  77.     MessageBox (hWnd, (LPSTR)"The flashing black box is the caret",
  78.         (LPSTR)"ShowCaret", MB_OK);
  79.  
  80.  
  81.     return 0;
  82. }
  83.