CreatDC()和CreateIC()

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

   #include  < windows.h >
None.gif
None.gifLRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
None.gif
None.gif
int  WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
None.gif                    PSTR szCmdLine, 
int  iCmdShow)
ExpandedBlockStart.gifContractedBlock.gif
{
InBlock.gif     
static TCHAR szAppName[] = TEXT ("HelloWin") ;
InBlock.gif     HWND         hwnd ;
InBlock.gif     MSG          msg ;
InBlock.gif     WNDCLASS     wndclass ;
InBlock.gif
InBlock.gif     wndclass.style         
= CS_HREDRAW | CS_VREDRAW ;
InBlock.gif     wndclass.lpfnWndProc   
= WndProc ;
InBlock.gif     wndclass.cbClsExtra    
= 0 ;
InBlock.gif     wndclass.cbWndExtra    
= 0 ;
InBlock.gif     wndclass.hInstance     
= hInstance ;
InBlock.gif     wndclass.hIcon         
= LoadIcon (NULL, IDI_APPLICATION) ;
InBlock.gif     wndclass.hCursor       
= LoadCursor (NULL, IDC_ARROW) ;
InBlock.gif     wndclass.hbrBackground 
= (HBRUSH) GetStockObject (WHITE_BRUSH) ;
InBlock.gif     wndclass.lpszMenuName  
= NULL ;
InBlock.gif     wndclass.lpszClassName 
= szAppName ;
InBlock.gif
InBlock.gif     
if (!RegisterClass (&wndclass))
ExpandedSubBlockStart.gif     
{
InBlock.gif          MessageBox (NULL, TEXT (
"This program requires Windows NT!"), 
InBlock.gif                      szAppName, MB_ICONERROR) ;
InBlock.gif          
return 0 ;
ExpandedSubBlockEnd.gif     }

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

InBlock.gif     
return msg.wParam ;
ExpandedBlockEnd.gif}

None.gif
None.gifLRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
ExpandedBlockStart.gifContractedBlock.gif
{
InBlock.gif     
static HDC  hdcScreen ;
InBlock.gif    

InBlock.gif   

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

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

InBlock.gif     
return DefWindowProc (hwnd, message, wParam, lParam) ;
ExpandedBlockEnd.gif}
   可是,为什么要用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()只需要其能获得信息就行了。但,真正理解其中的东西,还需要解读这两个函数的源码吧。(这好像看起来不现实)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值