龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

vc++技术内幕(第四版)笔记(第4章)(3)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
10,CScrollView支持滚动条的滚动,但不支持键盘的滚动。通过使用CWnd的ScrollWindow和SetViewportOrg函数,CScrollView类允许将视口原点移到窗口中的任何一个位置,

10,CScrollView支持滚动条的滚动,但不支持键盘的滚动。通过使用CWnd的ScrollWindow和SetViewportOrg函数,CScrollView类允许将视口原点移到窗口中的任何一个位置,甚至包括窗口区域的上部或窗口的原点的左边。

键盘输入是分两步处理的。OS向窗口发送类如WM_KEYDOWN和WM_KEYUP消息时用的是虚拟键盘码,在消息到达窗口之前,被翻译成WM_CHAR消息,该消息带着正常的键码。

利用对WM_KEYDOWN消息进行响应,对按键分别调用OnVScroll就可以使应用程序支持键盘的滚动。

CWnd::OnVScroll 
afx_msg void OnVScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar );
////
nSBCode:
SB_BOTTOM   Scroll to bottom.
SB_ENDSCROLL   End scroll.
SB_LINEDOWN   Scroll one line down.
SB_LINEUP   Scroll one line up.
SB_PAGEDOWN   Scroll one page down.
SB_PAGEUP   Scroll one page up.
SB_THUMBPOSITION   Scroll to the absolute position. The current position is provided in nPos.
SB_THUMBTRACK   Drag scroll box to specified position. The current position is provided in nPos.
SB_TOP   Scroll to top.
////
The framework calls this member function(OnVScroll) when the user clicks the window’s vertical scroll bar.

11,CView::OnInitialUpdate

virtual void OnInitialUpdate( );

说明:

OnInitialUpdate是视图窗口完全建立后框架调用的第一个函数。框架在第一次调用OnDraw前会调用OnInitialUpdate。

具体参见下:

Called by the framework after the view is first attached to the document, but before the view is initially displayed. The default implementation of this function calls the OnUpdate member function with no hint information .

12,MFC对140种Windows消息直接直接提供了相应的消息控制函数,当然,我们还可以定义自己的消息和相应的消息控制函数。
五种特殊Windows消息:WM_CREATE,WM_CLOSE,WM_QUERYENDSESSION,WM_DESTROY,WM_NCDESTROY.(具体参见 p62-63页。这两页强烈建议看看,这里简要笔记三个最常用最重要的)

1)WM_CREATE消息:

The WM_CREATE message is sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function. The window procedure of the new window receives this message after the window is created, but before the window becomes visible. The message is sent before the CreateWindowEx or CreateWindow function returns.

2)WM_CLOSE消息:

当关闭窗口或父窗口被关闭时,Windows都会发送WM_CLOSE消息。可以重新定义该消息响应函数OnClose来完全控制关闭过程。

3)WM_DESTROY消息:

Windows在发送WM_CLOSE消息之后,紧接着就会发送WM_DESTROY消息(响应这个消息的时候,窗口已经消失但还没有销毁)。

(可以响应这个消息来做一些销毁当前窗口后的一些事情,例如再弹出其它对话框发送其他的消息)

精彩图集

赞助商链接