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

  1. /*
  2.  *  PtVisible
  3.  *
  4.  *  This function demonstrates the use of the PtVisible function.  It will
  5.  *  create a window using the CreateWindow function, and will display a
  6.  *  message box telling the user if the point (200,200) is inside the client
  7.  *  area of the window.
  8.  *
  9.  */
  10.  
  11. #include <windows.h>
  12.  
  13. BOOL FAR PASCAL InitPtVisible (HANDLE, HANDLE, int);
  14. long    FAR PASCAL PtVisibleWindowProc (HANDLE, unsigned, WORD, LONG);
  15. void FAR PASCAL CheckPoint (HWND);
  16.  
  17. int    PASCAL WinMain  (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  18.  
  19. HANDLE hInstance, hPrevInstance;
  20. LPSTR  lpszCmdLine;
  21. int    nCmdShow;
  22. {
  23.   MSG  msg;
  24.  
  25.   InitPtVisible (hInstance, hPrevInstance, nCmdShow);
  26.  
  27.   while (GetMessage((LPMSG) & msg, NULL, 0, 0))
  28.   {
  29.     TranslateMessage((LPMSG) & msg);
  30.     DispatchMessage((LPMSG) & msg);
  31.   }
  32.  
  33.   exit(msg.wParam);
  34. }
  35.  
  36.  
  37. BOOL FAR PASCAL InitPtVisible (hInstance, hPrevInstance, nCmdShow)
  38.  
  39. HANDLE hInstance;
  40. HANDLE hPrevInstance;
  41. int    nCmdShow;
  42.  
  43. {
  44.   WNDCLASS  wcPtVisibleClass;
  45.   HWND hWnd;
  46.  
  47.   wcPtVisibleClass.lpszClassName = (LPSTR) "PtVisible";
  48.   wcPtVisibleClass.hInstance  = hInstance;
  49.   wcPtVisibleClass.lpfnWndProc  = PtVisibleWindowProc;
  50.   wcPtVisibleClass.hCursor  = LoadCursor (NULL, IDC_ARROW);
  51.   wcPtVisibleClass.hIcon  = NULL;
  52.   wcPtVisibleClass.lpszMenuName  = (LPSTR) "PtVisibleMenu";
  53.   wcPtVisibleClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  54.   wcPtVisibleClass.style  = CS_HREDRAW | CS_VREDRAW;
  55.   wcPtVisibleClass.cbClsExtra  = 0;
  56.   wcPtVisibleClass.cbWndExtra  = 0;
  57.  
  58.   RegisterClass ((LPWNDCLASS) & wcPtVisibleClass);
  59.  
  60.   hWnd = CreateWindow((LPSTR) "PtVisible", (LPSTR) "PtVisible",
  61.       WS_OVERLAPPEDWINDOW,  
  62.       CW_USEDEFAULT,  0,
  63.       CW_USEDEFAULT,  0,
  64.       NULL,  NULL,  hInstance, NULL);
  65.  
  66.   LoadMenu(hInstance, (LPSTR) "PtVisibleMenu");
  67.  
  68.   ShowWindow (hWnd, nCmdShow);
  69.   UpdateWindow (hWnd);
  70.  
  71.   return TRUE;
  72. }
  73.  
  74.  
  75. long    FAR PASCAL PtVisibleWindowProc (hWnd, message, wParam, lParam)
  76.  
  77. HWND     hWnd;
  78. unsigned    message;
  79. WORD     wParam;
  80. LONG     lParam;
  81. {
  82.   switch (message)
  83.   {
  84.   case WM_COMMAND:
  85.     if (wParam == 1)
  86.       CheckPoint(hWnd);
  87.     break;
  88.  
  89.   case WM_PAINT:
  90.     PaintPtVisibleWindow (hWnd);
  91.     break;
  92.  
  93.   case WM_DESTROY:
  94.     PostQuitMessage(0);
  95.     break;
  96.  
  97.   default:
  98.     return(DefWindowProc(hWnd, message, wParam, lParam));
  99.     break;
  100.   }
  101.   return(0L);
  102. }
  103.  
  104.  
  105. PaintPtVisibleWindow (hWnd)
  106.  
  107. HWND hWnd;
  108. {
  109.   PAINTSTRUCT ps;
  110.   HDC  hDC;
  111.  
  112.   BeginPaint (hWnd, (LPPAINTSTRUCT) & ps);
  113.   hDC = ps.hdc;
  114.  
  115.   SetPixel (hDC, 200, 200, RGB(0, 0, 0));
  116. /*  Draw a black pixel  */
  117.  
  118.   ValidateRect (hWnd, (LPRECT) NULL);
  119.   EndPaint (hWnd, (LPPAINTSTRUCT) & ps);
  120.  
  121.   return TRUE;
  122. }
  123.  
  124.  
  125. /*  CheckPoint(hWnd) -  Check to see if (200, 200) is visible  */
  126.  
  127. void FAR PASCAL CheckPoint (hWnd)
  128.  
  129. HWND     hWnd;
  130. {
  131.   HDC  hDC;
  132.  
  133.   hDC = GetDC (hWnd);
  134.   if (PtVisible (hDC, 200, 200))
  135. /*  Find out if the point 200, 200 is in the current display
  136.      *  context
  137.      */
  138.  
  139.     MessageBox(hWnd, (LPSTR) "(200, 200) is Visible",
  140.         (LPSTR)"OK", MB_OK);
  141.   else
  142.     MessageBox(hWnd, (LPSTR) "(200, 200) is not Visible",
  143.         (LPSTR)"OK", MB_OK);
  144.  
  145.   ReleaseDC (hWnd, hDC);
  146. }
  147.  
  148.  
  149.