VC++技术内幕(windows编程篇)(15)
AutoLoad函数把每个按钮和两个匹配的位图资源连接起来。如:VERIFY(CWnd::EnableWindow.AutoLoad(IDC_BUTTON1,this));
说明一:
CBitmapButton::AutoLoad
BOOL AutoLoad( UINT nID, CWnd* pParent ); //nID:The button‘s control ID.
//pParent:Pointer to the object that owns the button.
//AutoLoad Associates a button in a dialog box with an object of the CBitmapButton class, loads the bitmap(s) by name, and sizes the button to fit the bitmap.(注意哦,这里的loads the bitmap by name。)
//Use the AutoLoad function to initialize an owner-draw button in a dialog box as a bitmap button.
说明二: VERIFY
VERIFY( booleanExpression )
//VERIFY是MFC诊断宏,当参数booleanExpression 为 0 的时候,停止程序并显示一个对话框;当booleanExpression 不为零,则什么也不做。
说明三:
在为按钮设置的位图加名字标识的时候: \按钮Caption+U\表示按钮凸起状态的位图 \按钮Caption+D\ 表示按钮凹起状态的位图 \按钮Caption+F\表示按钮有焦点状态的位图 \按钮Caption+X\表示按钮无效状态的位图
9,CWnd::EnableWindow函数可以是一个窗口有效或无效,可以调用它来使按钮等控件(窗口)无效或恢复有效。
CWnd::EnableWindow
BOOL EnableWindow( BOOL bEnable = TRUE );
//If this parameter is TRUE, the window will be enabled. If this parameter is FALSE, the window will be disabled.
//EnableWindow Enables or disables mouse and keyboard input. When input is disabled, input such as mouse clicks and keystrokes is ignored. When input is enabled, the window processes all input.
//An application can use this function to enable or disable a control in a dialog box. A disabled control cannot receive the input focus, nor can a user access it. 十、
Winsows消息处理和多线程编程 一)Winsows消息处理
1,单线程:程序代码只有一条执行路径。 2,单线程程序消息处理过程: MSG message;
while(::GetMessage(&message,NULL,0,0)) {
::TranslateMessage(&message);//翻译如wm_char消息
::DispatchMessage(&message);//把消息分发给指定窗口的回调函数 }
说明:
1)os决定哪个消息属于我们的程序,当一个消息要处理的时候,用GetMessage函数返回该消息。
2)如果没有属于我们程序的消息发出,则我们的程序被挂起,而其它的程序可以运行;当属于我们程序的消息到达,我们的程序被唤醒
3,改造2中的单线程消息处理过程:
问题一:某个消息控制函数很―笨重‖,消耗CPU时间过久。
问题二:DispatchMessage函数要等到该笨重消息控制函数返回后才能返回。在该笨重消息控制函数返回之前DispatchMessage不处理(分发)任何消息。 解决方法:使用PeekMessage函数使占用CPU时间过久的消息控制函数每隔一段时间交出控制一次。(在占CPU时间过久的控制函数中利用PostMessage发送
代码如下: MSG message;
while(::PeekMessage(&message,NULL,0,0,PM_REMOVE)) {
::TranslateMessage(&message);//翻译如wm_char消息
::DispatchMessage(&message);//把消息分发给指定窗口的回调函数 } 说明:
//The PeekMessage function checks a thread message queue for a message and places the message (if any) in the specified structure.
简要说明:
1)BOOL PeekMessage(
LPMSG lpMsg, // pointer to structure for message HWND hWnd, // handle to window UINT wMsgFilterMin, // first message UINT wMsgFilterMax, // last message
UINT wRemoveMsg // removal flags );
//If a message is available, return nonzero,otherwise return 0;
//Unlike the GetMessage function, the PeekMessage function does not wait for a message to be placed in the queue before returning.
//PeekMessage retrieves only messages associated with the window identified by the hWnd parameter or any of its children as specified by the IsChild function, and within the range of message values given by the wMsgFilterMin and wMsgFilterMax parameters. //If hWnd is NULL, PeekMessage retrieves messages for any window that belongs to the current thread making the call.
//If hWnd is –1, PeekMessage only returns messages with a hWnd value of NULL, as posted by the PostThreadMessage function.
//If wMsgFilterMin and wMsgFilterMax are both zero, PeekMessage returns all available messages (that is, no range filtering is performed).
//PeekMessage does not retrieve messages for windows that belong to other threads. 2)BOOL GetMessage(
LPMSG lpMsg, // address of structure with message HWND hWnd, // handle of window UINT wMsgFilterMin, // first message UINT wMsgFilterMax // last message );
//GetMessage does not retrieve messages for windows that belong to other threads or applications.
//
4,计时器独立于CPU时钟速度。
1)计时器的使用:用一个时间间隔参数调用CWnd::SetTimer函数,然后再用ClassWizard为WM_TIMER添加消息控制函数。
…… 此处隐藏:1673字,全部文档内容请下载后查看。喜欢就下载吧 ……相关推荐:
- [学前教育]MC9S12XS256RMV1 xs128芯片手册4
- [学前教育]安东尼语录经典语录
- [学前教育]e级gps控制测量技术设计书
- [学前教育]苏教版2022-2022学年八年级下学期期末
- [学前教育]装修公司推广 营销
- [学前教育]家政服务合同(完整版)
- [学前教育]湖北省2016届高三联考语文试题
- [学前教育]爱立信无涯学习系统LTE题库1-LTE基础知
- [学前教育]揭秘大众柴油车作弊软件原理
- [学前教育]人才流失原因及对策分析
- [学前教育]房屋建筑施工工程劳务分包合同
- [学前教育]国际贸易实务试卷A卷09.6
- [学前教育]校园废品回收活动计划方案书范文格
- [学前教育]电大成本会计试题及答案
- [学前教育]大学物理实验 华南理工出版社 绪论答案
- [学前教育]爱丁堡产后抑郁量表
- [学前教育]液压冲击的危害、产生原因与防止方法(
- [学前教育]学生工作总结高一学生期中考试总结_020
- [学前教育]人民医院医疗废物管理规章制度大全
- [学前教育]阳光维生素的巨大抗癌潜能阅读题答案.d
- 马云在云锋基金江苏论坛闭幕式的发言
- 试论小学体育教育中的心理健康教育-教
- 语文A版一年级下册《语文乐园一》教学
- 2021四川大学物理化学考研真题经验参考
- [人教A版]2015-2016学年高中数学 第二
- 终端网点销售返利协议书
- 江苏省2015年眼科学主治医师青光眼考试
- 2017年部编人教版八年级语文上册教案
- 十一中学七年级英语上册Unit7Howmuchar
- 以赛促教的创新性实验教学机制建设实践
- 平凉市崆峒区2015七年级下生物期末试题
- 琶洲(地块五)A、B塔楼1、2#塔吊基础
- 一级医院工作制度与人员岗位职责
- 2018北京西城区高三二模理科数学试题及
- 炒股密码线技术 - 图文
- 职高学生生涯发展辅导教案
- 语文人教版四年级上册8 世界地图引出的
- 最新最新人教版二年级上册全册数学教案
- 2017高考英语全国2卷精彩试题(有问题
- 普通心理学笔记




