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

  1. /*
  2.  *  SetCaretPos
  3.  *  setcapos.c
  4.  *
  5.  *  This program demonstrates the use of the function SetCaretPos.
  6.  *  It moves the caret to the position specified by the parameters. The
  7.  *  movement applies to the caret whether it is visible or hidden.
  8.  *
  9.  */
  10.  
  11. #include "windows.h"
  12.  
  13. /* Procedure called when the application is loaded for the first time */
  14. BOOL WinInit( hInstance )
  15. HANDLE hInstance;
  16. {
  17.     WNDCLASS   wcClass;
  18.  
  19.     /* registering the parent window class */
  20.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  21.     wcClass.hIcon          = LoadIcon (hInstance, (LPSTR)"WindowIcon");
  22.     wcClass.lpszMenuName   = (LPSTR)NULL;
  23.     wcClass.lpszClassName  = (LPSTR)"Setcapos";
  24.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  25.     wcClass.hInstance      = hInstance;
  26.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  27.     wcClass.lpfnWndProc    = DefWindowProc;
  28.     wcClass.cbClsExtra     = 0;
  29.     wcClass.cbWndExtra     = 0;
  30.  
  31.     RegisterClass( (LPWNDCLASS)&wcClass );
  32.     return TRUE;        /* Initialization succeeded */
  33. }
  34.  
  35.  
  36. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  37. HANDLE hInstance, hPrevInstance;
  38. LPSTR lpszCmdLine;
  39. int cmdShow;
  40. {
  41.     HWND         hWnd;                /* Handle to the parent window    */
  42.  
  43.     WinInit (hInstance);
  44.  
  45.     hWnd = CreateWindow((LPSTR)"Setcapos",
  46.                         (LPSTR)"Setting Caret Position",
  47.                         WS_OVERLAPPEDWINDOW,
  48.                         50,                /* x         */
  49.                         50,                /* y         */
  50.                         600,               /* width     */
  51.                         250,               /* height    */
  52.                         (HWND)NULL,        /* no parent */
  53.                         (HMENU)NULL,       /* use class menu */
  54.                         (HANDLE)hInstance, /* handle to window instance */
  55.                         (LPSTR)NULL        /* no params to pass on */
  56.                        );
  57.  
  58.     /* Make window visible according to the way the app is activated */
  59.     ShowWindow( hWnd, cmdShow );
  60.     UpdateWindow( hWnd );
  61.    
  62.     /* Create a caret before showing */
  63.     CreateCaret (hWnd, NULL, 8, 12);
  64.     SetCaretPos (50,50);    
  65.     ShowCaret (hWnd);
  66.     /* Message Box will make the parent window inactive */
  67.     MessageBox (hWnd, (LPSTR)"This is the current caret position", 
  68.                 (LPSTR)"Before", MB_OK);
  69.  
  70.     /* move the caret to a new location */
  71.     SetCaretPos (50,125);    
  72.     MessageBox (hWnd, (LPSTR)"Now the caret is moved to a new position", 
  73.                 (LPSTR)"After", MB_OK);
  74.  
  75.     return 0;
  76. }
  77.