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表示释放
那请问此刻释放的是哪个窗口?你能说清楚吗?
因此肯定莫一时刻只能锁住一个窗口。
最后给出一个测试代码吧:

  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. ReleaseDC(hwnd,hdc);
  14. LockWindowUpdate(hwnd);
  15. }

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

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

最新文章

  1. 通过LoadRunner - Analyze详细分析页面元素请求
  2. HTML5基础之textarea 和lable
  3. Java中request请求之 - 带文件上传的form表单
  4. golang flag包简单例子
  5. Codeforces Round #150 (Div. 2)
  6. WingIde的快捷键
  7. cf581A Vasya the Hipster
  8. 生成bundle和移除bundle
  9. phpStorm注册马码
  10. C++中内存泄露的检测
  11. Push or Pull?
  12. detach() 与remove()
  13. OC语言编写:为视图添加丝滑的水波纹
  14. SignalR学习笔记(三)Self-Host
  15. 洛谷P4482 [BJWC2018]Border 的四种求法 字符串,SAM,线段树合并,线段树,树链剖分,DSU on Tree
  16. linux 定时任务到秒级
  17. Linux中程序开机自启
  18. Win一键查看用户密码
  19. 03_ExeZZ.cpp
  20. 自己写的 Readini 类

热门文章

  1. umlの用例图
  2. OpenStack Cinder源代码流程简析
  3. STL——前闭后开区间表示法和function call 操作符
  4. MaxReceivedMessageSize :已超过传入消息(65536)的最大消息大小配额
  5. css之选择器
  6. [转] Boost智能指针——scoped_ptr
  7. python面对对象编程-------5:获取属性的四种办法:@property, __setattr__(__getattr__) ,descriptor
  8. 5事件DOM零级事件跟DOM二级事件
  9. Asp.Net操作WebServices
  10. XML 标记使用的特殊字符对应内置实体