zoukankan      html  css  js  c++  java
  • 对LockWindowUpdate与GetDCEx的理解(以前不知道还可以锁住刷新)

    MSDN如是说:
    The LockWindowUpdate function disables or enables drawing in the specified window. Only one window can be locked at a time. 

    BOOL LockWindowUpdate(
      HWND hWndLock   // handle to window
    );

    Parameters
    hWndLock 
    [in] Specifies the window in which drawing will be disabled. If this parameter is NULL, drawing in the locked window is enabled. 
    Return Values
    If the function succeeds, the return value is nonzero.

    If the function fails, the return value is zero, indicating that an error occurred or another window was already locked. 


    通俗的说,就是这个函数把参数---句柄--所关联的窗口锁住了,不再让他继续更新了。
    GetDCEx
    The GetDCEx function retrieves a handle to a display device context (DC) for the client area of a specified window or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. 

    This function is an extension to the GetDC function, which gives an application more control over how and whether clipping occurs in the client area. 

    HDC GetDCEx(
      HWND hWnd,      // handle to window
      HRGN hrgnClip,  // handle to clipping region
      DWORD flags     // creation options
    );
    此函数参数怪多的,这里就不贴了,参考 MSDN吧

    关键在于第三个参数:标志位的设置
    前面我们已经知道了,LockWindowUpdate可以锁住某个窗口,如果我们锁住的话,那将不能在这个窗口中进行一切绘制操作(用GetDC,BeginPaint,CreateIC,CreateDC这些API创建的DC都被禁止),比如TextOut也将失效,因为第一个参数是hdc,如果是前面括号中的方式得到的DC,那就失去作用。
    然而,GetDCEx却十分例外,如果我们把第三个参数设置成DCX_LOCKWINDOWUPDATE,那即使你把窗口锁住,用此API得到的DC,依然可以对此窗口进行绘制,十分特殊。
    最后提醒一点:同一时刻,只能有一个窗口被锁住。
    利用反证法比较容易证明此观点:
    比如LockWindowUpdate(A);
    LockWindowUpdate(B);
    那我释放的时候只能用LockWindowUpdate(NULL);//看函数参数介绍,NULL表示释放
    那请问此刻释放的是哪个窗口?你能说清楚吗?
    因此肯定莫一时刻只能锁住一个窗口。
    最后给出一个测试代码吧:

    [cpp] view plain copy
     
    1. #include<iostream>  
    2. #include<windows.h>  
    3. using namespace std;  
    4. void main()  
    5. {  
    6.   TCHAR szAppName[]=TEXT("I love you!!!");  
    7.   HWND hwnd=FindWindow(NULL,TEXT("伊锐锐"));  
    8.   //HDC hdc=GetDC(hwnd);  
    9.   HDC hdc=GetDCEx(hwnd,NULL,DCX_LOCKWINDOWUPDATE);  
    10.   LockWindowUpdate(hwnd);  
    11.     SetBkMode(hdc,TRANSPARENT);  
    12.   TextOut(hdc,0,50,szAppName,lstrlen(szAppName));  
    13.   
    14.   ReleaseDC(hwnd,hdc);  
    15.   LockWindowUpdate(hwnd);  
    16. }  


    代码通俗易懂,这里其实我用的就是往QQ聊天窗口中输入I LOVE YOU罢了,测试起来效果还行。

    http://blog.csdn.net/yiruirui0507/article/details/6332118

  • 相关阅读:
    数据库设计优化(一)--基础
    数据库设计--范式原则
    迭代器 与 foreach 的区别
    DBeaver中如何调整SQL编辑器的字体大小
    腾讯课堂下载回放视频
    超级美味的大盘鸡做法
    关闭或开启Win10系统的自动更新
    geoserver发布地图瓦片影像数据
    使用GeoServer发布Shapfile数据
    GeoServer下载与安装(Windows版)
  • 原文地址:https://www.cnblogs.com/findumars/p/5811334.html
Copyright © 2011-2022 走看看