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

  1. /*
  2.  *  MoveWindow
  3.  *
  4.  *  This function demonstrates the use of the MoveWindow function.  It will
  5.  *  create a window, draw a pie slice in it, display a message box, and then
  6.  *  move the window.
  7.  */
  8.  
  9. #include <windows.h>
  10.  
  11. /* Forward Declarations  */
  12.  
  13. BOOL FAR PASCAL InitPie ( HANDLE , HANDLE , int );
  14. long    FAR PASCAL PieWindowProc ( HANDLE , unsigned , WORD , LONG );
  15.  
  16. /*
  17.  *  MAIN PROCEDURE
  18.  */
  19.  
  20. int    PASCAL WinMain  (hInstance , hPrevInstance , lpszCmdLine , cmdShow )
  21.  
  22. HANDLE hInstance , hPrevInstance;
  23. LPSTR  lpszCmdLine;
  24. int    cmdShow;
  25. {
  26.   MSG  msg;
  27.  
  28.   InitPie (hInstance, hPrevInstance, cmdShow );  /*  Init Routine  */
  29.  
  30.   while ( GetMessage((LPMSG) & msg, NULL, 0 , 0 ))
  31.   {
  32.     TranslateMessage((LPMSG) & msg);
  33.     DispatchMessage((LPMSG) & msg);
  34.   }
  35.  
  36.   exit(msg.wParam);
  37. }
  38.  
  39.  
  40. BOOL FAR PASCAL InitPie (hInstance , hPrevInstance , cmdShow)
  41.  
  42. HANDLE hInstance;
  43. HANDLE hPrevInstance;
  44. int    cmdShow;
  45.  
  46. {
  47.   WNDCLASS  wcPieClass;
  48.   HWND    hWnd;
  49.  
  50.   wcPieClass.lpszClassName = (LPSTR) "Pie";
  51.   wcPieClass.hInstance       = hInstance;
  52.   wcPieClass.lpfnWndProc   = PieWindowProc;
  53.   wcPieClass.hCursor       = LoadCursor ( NULL , IDC_ARROW );
  54.   wcPieClass.hIcon       = NULL;
  55.   wcPieClass.lpszMenuName  = (LPSTR) NULL;
  56.   wcPieClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  57.   wcPieClass.style       = CS_HREDRAW | CS_VREDRAW;
  58.   wcPieClass.cbClsExtra    = 0;
  59.   wcPieClass.cbWndExtra    = 0;
  60.  
  61.   RegisterClass ((LPWNDCLASS) & wcPieClass);
  62.  
  63.   hWnd = CreateWindow((LPSTR) "Pie", (LPSTR) "MoveWindow",
  64.       WS_OVERLAPPEDWINDOW,  
  65.       CW_USEDEFAULT,     0,    
  66.       CW_USEDEFAULT,     0,    
  67.       NULL,     NULL,     hInstance, NULL);
  68.  
  69.   ShowWindow (hWnd , cmdShow);
  70.   UpdateWindow (hWnd);
  71.  
  72.   return TRUE;
  73. }
  74.  
  75.  
  76. /*
  77.  *  THE WINDOW PROCEDURE - Process messages
  78.  */
  79.  
  80. long    FAR PASCAL PieWindowProc (hWnd , message , wParam , lParam)
  81.  
  82. HWND        hWnd;
  83. unsigned    message;
  84. WORD        wParam;
  85. LONG        lParam;
  86. {
  87.   static BOOL bFlag = FALSE;        /*    Tell us whether or not    */
  88. /*    we have moved the    */
  89. /*    Window            */
  90.  
  91.   switch (message)
  92.   {
  93.   case WM_PAINT:
  94.     PaintPieWindow (hWnd);
  95.     if ( bFlag == FALSE )
  96.     {
  97.       bFlag = TRUE;
  98.       MessageBox( GetFocus() , (LPSTR)"Press the OK Button to move the window",
  99.           (LPSTR)"MOVE", MB_OK );
  100.  
  101.       MoveWindow( hWnd , 0 , 0 , 400 , 300 , TRUE );
  102. /*  Change the size as well as the position using the
  103.            *  MoveWindow function.    We also tell the Window to
  104.            *  re-paint the client area.  We use the bFlag variable
  105.            *  to make sure we only call MoveWindow once.
  106.            */
  107.     }
  108.     break;
  109.  
  110.   case WM_DESTROY:            /*    If close requested    */
  111.     PostQuitMessage(0);        /*      send yourself a quit    */
  112.     break;                /*      message        */
  113.  
  114.   default:
  115.     return( DefWindowProc( hWnd , message , wParam , lParam ) );
  116.     break;
  117.   }
  118.   return( 0L );
  119. }
  120.  
  121.  
  122. /*
  123.  *  THE PAINT PROCEDURE
  124.  */
  125.  
  126. PaintPieWindow (hWnd)
  127.  
  128. HWND    hWnd;                /*    Handle of the window  */
  129. {
  130.   PAINTSTRUCT    ps;
  131.   HDC        hDC;
  132.  
  133.   BeginPaint (hWnd , (LPPAINTSTRUCT) & ps);  /*    Prepare the client area */
  134.   hDC = ps.hdc;                /*  Get the Display Context  */
  135.  
  136.   Pie ( hDC , 100 , 100 , 300 , 300 , 300 , 200 , 200 , 100 );
  137. /*  Draw the Pie
  138.      *  Upper Left of box holding pie slice  = 100 , 100
  139.      *  Lower Right of box holding pie slice = 300 , 300
  140.      *  Start the arc at 300 , 300
  141.      *  End the arc at 200 , 100
  142.      *  The arc will be drawn in a counter clockwise direction
  143.      */
  144.  
  145.   ValidateRect (hWnd , (LPRECT) NULL);     /*  Disable any more paint messages  */
  146.   EndPaint (hWnd, (LPPAINTSTRUCT) & ps );
  147.  
  148.   return TRUE;
  149. }
  150.