李sir_Blog

博客园 首页 联系 订阅 管理
CreateIC()和CreateDC()都获取设备描述表句柄,但用CreateDC()获取的能够进行绘画,而用CreateIC()获取的设备描述表,你却不能用它往设备上写东西,只能查询获取你所要的信息。测试代码如下:

   #include <windows.h>

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, 
int iCmdShow)
{
     
static TCHAR szAppName[] = TEXT ("HelloWin") ;
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASS     wndclass ;

     wndclass.style         
= CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   
= WndProc ;
     wndclass.cbClsExtra    
= 0 ;
     wndclass.cbWndExtra    
= 0 ;
     wndclass.hInstance     
= hInstance ;
     wndclass.hIcon         
= LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor       
= LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground 
= (HBRUSH) GetStockObject (WHITE_BRUSH) ;
     wndclass.lpszMenuName  
= NULL ;
     wndclass.lpszClassName 
= szAppName ;

     
if (!RegisterClass (&wndclass))
     
{
          MessageBox (NULL, TEXT (
"This program requires Windows NT!"), 
                      szAppName, MB_ICONERROR) ;
          
return 0 ;
     }

     
     hwnd 
= CreateWindow (szAppName,                  // window class name
                          TEXT ("The Hello Program"), // window caption
                          WS_OVERLAPPEDWINDOW,        // window style
                          CW_USEDEFAULT,              // initial x position
                          CW_USEDEFAULT,              // initial y position
                          CW_USEDEFAULT,              // initial x size
                          CW_USEDEFAULT,              // initial y size
                          NULL,                       // parent window handle
                          NULL,                       // window menu handle
                          hInstance,                  // program instance handle
                          NULL) ;                     // creation parameters
     
     ShowWindow (hwnd, iCmdShow) ;
     UpdateWindow (hwnd) ;
     
     
while (GetMessage (&msg, NULL, 00))
     
{
          TranslateMessage (
&msg) ;
          DispatchMessage (
&msg) ;
     }

     
return msg.wParam ;
}


LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     
static HDC  hdcScreen ;
    

   

     
     
switch (message)
     
{
     
case WM_CREATE:
          hdcScreen 
= CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
          
//hdcScreen = CreateIC(TEXT("DISPLAY"), NULL, NULL, NULL);
         return 0 ;

      
         
     
case WM_PAINT:
          TextOut(hdcScreen, 
5050, TEXT("xiexiufeng"), 11);
          
return 0 ;
          
     
case WM_DESTROY:
          DeleteDC(hdcScreen);
          PostQuitMessage (
0) ;
          
return 0 ;
     }

     
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
   可是,为什么要用CreateIC()呢,CreateDC()已经可以满足我们所有的需要呢!查了下msdn:
   The CreateIC function creates an information context for the specified device. The information context provides a fast way to get information about the device without creating a device context. 
   从中可以看出CreateIC()函数要必CreateDC()快。至于为什么快,其原理说来起来容易。CreateDC()不仅要获取信息,还要使其能够被修改。而CreateIC()只需要其能获得信息就行了。但,真正理解其中的东西,还需要解读这两个函数的源码吧。(这好像看起来不现实)
posted on 2011-01-12 13:29  李sir  阅读(3115)  评论(0编辑  收藏  举报