教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 学前教育 >

VC++技术内幕(windows编程篇)(15)

来源:网络收集 时间:2026-07-12
导读: AutoLoad函数把每个按钮和两个匹配的位图资源连接起来。如:VERIFY(CWnd::EnableWindow.AutoLoad(IDC_BUTTON1,this)); 说明一: CBitmapButton::AutoLoad BOOL AutoLoad( UINT nID, CWnd* pParent ); //nID:The bu

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字,全部文档内容请下载后查看。喜欢就下载吧 ……
VC++技术内幕(windows编程篇)(15).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/592946.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)