获得一个私有的显示DC

 
  1. /*
  2.     1:获得一个私有的显示DC
  3.     程序想在其窗口的客房区进行各种描绘操作需要先获得一个私有的显示DC。为了获得这
  4.     种类型的DC,窗口类在注册的时候需要设置风格的成员变量设置成CS_OWNDC。注册之后
  5.     程序可以通过GetDC方法获取一个标识着私有DC的句柄。
  6. */
  7. #include <windows.h>    // required for all Windows-based applications 
  8. #include <stdio.h>      // C run-time header for i/o
  9. #include <string.h>     // C run-time header for strtok_s 
  10. #include "dc.h"         // specific to this program 
  11. // Function prototypes.
  12. BOOL InitApplication(HINSTANCE); 
  13. long FAR PASCAL MainWndProc(HWNDUINTUINTLONG); 
  14. // Global variables 
  15. HINSTANCE hinst;       // handle to current instance 
  16. HDC hdc;               // display device context handle 
  17. BOOL InitApplication(HINSTANCE hinstance) 
  18.     WNDCLASS  wc; 
  19.     // Fill in the window class structure with parameters 
  20.     // describing the main window. 
  21.     //指定风格为CS_OWNDC///////////////////////////////////////////
  22.     wc.style = CS_OWNDC;         // Private-DC constant 
  23.     //////////////////////////////////////////////////////////////
  24.     wc.lpfnWndProc = (WNDPROC) MainWndProc; 
  25.     wc.cbClsExtra = 0; 
  26.     wc.cbWndExtra = 0; 
  27.     wc.hInstance = hinstance; 
  28.     wc.hIcon = LoadIcon((HINSTANCE) NULL, 
  29.         MAKEINTRESOURCE(IDI_APPLICATION)); 
  30.     wc.hCursor = LoadCursor((HINSTANCE) NULL, 
  31.         MAKEINTRESOURCE(IDC_ARROW)); 
  32.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  33.     wc.lpszMenuName =  "GenericMenu"
  34.     wc.lpszClassName = "GenericWClass"
  35.     // Register the window class and return the resulting code. 
  36.     return RegisterClass(&wc); 
  37. LRESULT APIENTRY MainWndProc( 
  38.                              HWND hwnd,           // window handle 
  39.                              UINT message,        // type of message 
  40.                              WPARAM wParam,       // additional information 
  41.                              LPARAM lParam)       // additional information 
  42.     PAINTSTRUCT ps;              // paint structure 
  43.     // Retrieve a handle identifying the private DC. 
  44.     ///////////////////////////////////////////////////////////////////////
  45.     hdc = GetDC(hwnd); 
  46.     ///////////////////////////////////////////////////////////////////////
  47.     switch (message) 
  48.     { 
  49.     case WM_PAINT: 
  50.         BeginPaint(hwnd, &ps); 
  51.         // Draw and paint using private DC. 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章