獲得一個私有的顯示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. 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章