大龙的博客
C++博客 | 首页 | 发新随笔 | 发新文章 | 联系 | 聚合 | 管理

Don’t Use the Win32 API PostThreadMessage() to Post Messages to UI Threads(翻译)

Don’t Use the Win32 API PostThreadMessage() to Post Messages to UI Threads
  不要用Win32 API PostThreadMessage()向UI线程发送消息。
  
  PostThreadMessage is a Win32 API used to post messages to threads. Usually, the message posted is a standard windows message with the window handle set to NULL.
  PostThreadMessage是一个Win32 API常用于向线程发送消息。通常,这个被发送的消息是个窗口句柄被设为NULL的,标准的窗口消息。
  When PostThreadMessage is used to post messages to a thread that has created a window, it is very likely that the posted messages will be lost. This is because UI threads are not always run by the primary message loop. For example, when a thread is showing a message box, it is running on the message loop supplied by the message box. This secondary message loop does not know how to handle the thread message (since its window handle is NULL) and it will be dropped.
  当你将PostThreadMessage用于向一个创建窗口的线程发送消息,结果这个消息很可能会丢失。这是因为UI线程并非总是在一级消息循环中。例如,当一个线程正显示一个消息对话框,它就运行在这个消息对话框提供的(代理的)消息循环中。这个二级消息循环不知如何处理这个线程消息(因为其窗口句柄是NULL)所以它会被放弃。
  So when posting messages to a UI threads, use PostMessage() instead and post messages to a window owned by that thread. Then the messages won’t be lost, even if the thread is running a secondary message loop.
  因此,当要发送一个消息给UI线程,就用PostMessage()作替代并向线程自己的窗口发消息。这样消息就不会被丢失,即便这个消息是运行在二级消息循环中。
发表于 2009-04-22 11:37 大龙1 阅读(21) 评论(0)  编辑 收藏 引用

转载于:https://www.cnblogs.com/rickiedu/archive/2009/04/28/1445259.html

Don’t Use the Win32 API PostThreadMessage() to Post Messages to UI Threads(翻译)相关推荐

  1. WIN32 API串口通信编程

    WIN32 API串口通讯实例教程 第一节实现串口通讯的函数及串口编程简介 API函数不仅提供了打开和读写通讯端口的操作方法,还提供了名目繁多的函数以支持对串行通讯的各种操作.常用函数及作用下: 函数 ...

  2. 揭示Win32 API拦截细节/API hooking revealed (1)

    原文出处:http://www.codeproject.com/system/hooksys.asp 简要介绍 拦截win32 API 调用对于多数windows开发人员来说都一直是很有挑战性的课题, ...

  3. MSIL 教程(二):数组、分支、循环、使用不安全代码和如何调用Win32 API(转)...

    转自:http://www.cnblogs.com/Yahong111/archive/2007/08/16/857574.html 续上文[翻译]MSIL 教程(一) ,本文继续讲解数组.分支.循环 ...

  4. How to change windows applicatioin's position via Win32 API

    可以使用的Win32 API是: [DllImport("user32.dll")] private extern static bool SetWindowPos(IntPtr ...

  5. 直接用Win32 API创建对话框Demo

    Win32 API包含有对话框函数: Win10,CFree 5.0:新建一个窗口工程: 先看一下CFree自带对话框编辑器:其保存为.DRES:还不知道怎么加入工程:先不管: #include &l ...

  6. Win32 API 窗口版本转换度分秒为小数

    经纬度的度分秒和小数之间转换是做GIS时常用的:下面实现一个Win32 API 版本度分秒转换为小数: 与此网站对比: http://www.gzhatu.com/du2dfm.html 使用VC++ ...

  7. Win32 API、VC++、C# 文件操作函数的初步比较

    一 C# File.ReadAllText(FilePath) : 一次将文本内容全部读完, File.ReadAllLines: 该方法返回一个字符串数组.每一行都是一个数组元素. string[] ...

  8. 控制台调用win32 API 示例二则

    一 控制台显示消息框 #include <stdio.h> #include <windows.h>int main(int argc, char* argv[]) {int ...

  9. Win32 API 打开另一个进程

    Win32 API 打开另一个进程,这是一些黑客编程技术中的一个步骤,当然也可以用来做好事: 首先要包含Tlhelp32.h: 在OpenProcessByProcessNmae函数中通过快照枚举进程 ...

最新文章

  1. bower overrides 配置
  2. CONTINUE...? ZOJ - 4033
  3. HSF服务注册失败,项目启动后,EDAS列表无法发现注册的服务
  4. android listview countdowntimer,Android-ListView中的CountDownTimer随机闪烁
  5. 骗子收录网站源码PHP搭建
  6. java定义一个静态类_Java中的静态类
  7. TensorFlow tf.keras.callbacks.CSVLogger
  8. java tcp demo_详解Java使用TCP实现数据传输实例
  9. AI智能人脸识别很难?30行Python代码完美打造
  10. 3.卷2(进程间通信)---System V IPC
  11. C++迭代器(STL迭代器)
  12. 基于ARMA-偏tGARCH和DCC-GARCH模型测算CoVaR——R语言实现
  13. 北京 php 外包,=== | php外包与php技术服务商
  14. 小程序打包体积优化策略
  15. 通过集成腾讯 IM 来浅尝一下.net 6 的 MINI API
  16. java,mqtt-client开发创建客户端
  17. 保险入门,我不推荐买保险
  18. ltsc系统升级为服务器,微软宣布Windows Server 2022开始转向LTSC 不再发布半年频道更新...
  19. Unity3D——加入剑痕效果(PocketRPG Trail插件)
  20. 自然几何之分形(2)

热门文章

  1. linux 内核调试信息在哪里,Linux kernel debug技巧----开启DEBUG选项
  2. php增删改查前后端分离,前后端分离之前端增删改查
  3. illegalstateexception是什么异常_异常源码分析—告诉你学习“源码”究竟有什么用!...
  4. html后缀的网页怎么复制,如何将HTML格式的文本从Chrome浏览器扩展复制到剪贴板上?...
  5. 对象特性---->深拷贝与浅拷贝
  6. python 解决最佳方案_python使用列表的最佳方案
  7. Keras ImageDataGenerator用于数据扩充/增强的原理及方法
  8. 和12岁小同志搞创客开发:手撕代码,做一款遥控灯
  9. Python制作抽奖系统
  10. 使用govendor灵活管理Go程序中的依赖包