home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_05 / WindowDC / WindowDC.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-20  |  2.8 KB  |  94 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : windowdc.cpp                                                         //
  10. //  Description: Window/Client DC Demo, Chapter 5                                     //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #define WIN32_LEAN_AND_MEAN
  16.  
  17. #include <windows.h>
  18. #include <tchar.h>
  19.  
  20. #include "resource.h"
  21.  
  22. int MyMessageBox(HWND hWnd, const TCHAR * text, const TCHAR * caption, DWORD style)
  23. {
  24.     MSGBOXPARAMS param;
  25.  
  26.     memset(& param, 0, sizeof(param));
  27.     param.cbSize      = sizeof(param);
  28.     param.hwndOwner   = hWnd;
  29.     param.hInstance   = GetModuleHandle(NULL);
  30.     param.lpszText    = text;
  31.     param.lpszCaption = caption;
  32.     param.dwStyle     = style | MB_USERICON;
  33.     param.lpszIcon    = MAKEINTRESOURCE(IDI_GRAPH);
  34.  
  35.     return MessageBoxIndirect(¶m);
  36. }
  37.  
  38.  
  39. void Test(HWND hWnd, const TCHAR * mess)
  40. {
  41.     SetWindowText(hWnd, mess);
  42.     
  43.     HDC hDC1 = GetWindowDC(hWnd);
  44.     HDC hDC2 = GetDC(hWnd);
  45.  
  46.     TCHAR temp[MAX_PATH];
  47.  
  48.     wsprintf(temp, "%s GetWindowDC=%x, GetDC=%x", mess, hDC1, hDC2);
  49.  
  50.     MyMessageBox(NULL, temp, _T("Window Region"), MB_OK);
  51.  
  52.     ReleaseDC(hWnd, hDC1);
  53.     ReleaseDC(hWnd, hDC2);
  54. }
  55.  
  56.  
  57. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
  58. {
  59.     HDC hDC1 = CreateIC(_T("DISPLAY"), NULL, NULL, NULL);
  60.     HDC hDC2 = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
  61.  
  62.     BOOL r = Rectangle(hDC1, 10, 10, 20, 200);
  63.  
  64.     int rs = GetLastError();
  65.  
  66.     r = Rectangle(hDC2, 10, 10, 20, 200);
  67.  
  68.     rs = GetLastError();
  69.  
  70.     HWND hWnd = CreateWindow(_T("EDIT"), NULL, 
  71.                     WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, 
  72.                     10, 10, 200, 100, GetDesktopWindow(), 
  73.                     NULL, hInstance, NULL);
  74.     
  75.     HWND hWnd1 = CreateWindow(_T("EDIT"), NULL, WS_VISIBLE | WS_CHILD | WS_BORDER,
  76.                     5, 5, 20, 20, hWnd, NULL, hInstance, NULL);
  77.  
  78.     ShowWindow(hWnd, SW_SHOW);
  79.     
  80.     Test(hWnd, _T("Rectangular Window"));
  81.  
  82.     HRGN hRgn = CreateEllipticRgn(0, 0, 300, 300);
  83.  
  84.     SetWindowRgn(hWnd, hRgn, TRUE);
  85.  
  86.     Test(hWnd, _T("Elliptic Window"));
  87.     
  88.     DestroyWindow(hWnd);
  89.  
  90.     DeleteDC(hDC1);
  91.     DeleteDC(hDC2);
  92.     
  93.     return 0;
  94. }