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

  1. /*
  2.  *  SetCursorPos
  3.  *  setcsrps.c
  4.  *
  5.  *  This program demonstrates the use of the function SetCursorPos.
  6.  *  It moves the system cursor to the coordinates specified by the
  7.  *  X and Y parameters.
  8.  *
  9.  */
  10.  
  11. #include "windows.h"
  12.  
  13. /*************************** GLOBAL VARIABLES *************************/
  14. static    HWND    hWnd;
  15. static    RECT    rect;
  16. /******************** WINMAIN -- Main Windows Procedure ***************/
  17. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  18. HANDLE        hInstance;
  19. HANDLE        hPrevInstance;
  20. LPSTR        lpszCmdLine;
  21. int        cmdShow;
  22. {
  23.         MSG    msg;
  24.         int    xCoord;
  25.         int    yCoord;
  26.  
  27.     if (!hPrevInstance) {
  28.         /* ensure that windows know where to find parts of this
  29.          * task on disk by Registering a window class.  Registering
  30.          * a class binds an executable name to an internal name,
  31.          * known to Windows. */
  32.         WNDCLASS    rClass;
  33.  
  34.         rClass.lpszClassName    = (LPSTR)"SetCursorPos";
  35.         rClass.hInstance    = hInstance;
  36.         rClass.lpfnWndProc    = DefWindowProc;
  37.         rClass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  38.         rClass.hIcon        = LoadIcon (hInstance, (LPSTR)"SetCursorPos");
  39.         rClass.lpszMenuName    = (LPSTR) NULL;
  40.         rClass.hbrBackground    = GetStockObject (WHITE_BRUSH);
  41.         rClass.style        = CS_HREDRAW | CS_VREDRAW;
  42.         rClass.cbClsExtra    = 0;
  43.         rClass.cbWndExtra    = 0;
  44.  
  45.         RegisterClass ((LPWNDCLASS) &rClass);
  46.         } /* end if this is the 1st task/instance of this program */
  47.  
  48.     hWnd = CreateWindow (    (LPSTR) "SetCursorPos", /* Window class name */
  49.                 (LPSTR) "SetCursorPos", /* Window title */
  50.                 WS_OVERLAPPEDWINDOW,
  51.                     /* stlye -- WIN 2.x or later */
  52.                 CW_USEDEFAULT,    /* x -  WIN 2.x or later */
  53.                 CW_USEDEFAULT,    /* y -  WIN 2.x or later */
  54.                 CW_USEDEFAULT,    /* cx - WIN 2.x or later */
  55.                 CW_USEDEFAULT,    /* cy - WIN 2.x or later */
  56.                 (HWND)NULL,    /* No parent */
  57.                 (HMENU)NULL,    /* Use the class menu */
  58.                 (HANDLE)hInstance, /* .EXE file for Class */
  59.                 (LPSTR)NULL    /* No Params */
  60.                  );
  61.     ShowWindow (hWnd, cmdShow);     /* Allocate room for window     */
  62.     UpdateWindow (hWnd);            /* Paint the client area        */
  63.  
  64.     MessageBox (hWnd, (LPSTR) "Moving the Cursor to the Top-Left Corner", (LPSTR) " ",MB_OK);
  65.     GetClientRect (hWnd, (LPRECT)&rect);
  66.     xCoord = rect.left;
  67.     yCoord = rect.top;
  68.  
  69.     /* SetCursorPos is used here to move the cursor to the top-left
  70.      * corner of the screen.    */
  71.     SetCursorPos (xCoord, yCoord);
  72.  
  73.     MessageBox (hWnd, (LPSTR) "Demonstration Finished", (LPSTR) " ",MB_OK);
  74.     exit (0);
  75. } /* WINMAIN */
  76.