ÕâÁ½¸öº¯ÊýÖеijߴç´óС°´Âß¼µ¥Î»¼ÆËã¡£
SetScaleToFitSizeÉèÖÃÊӿڳߴçΪµ±Ç°µÄ´°¿Ú³ß´ç£¬ÕâÑù£¬ÔÚûÓйö¶¯Ìõʱ£¬Âß¼ÊÓµÄÄÚÈݱ»·Å´ó»òÕßËõСµ½ÕýºÃ´°¿Ú´óС¡£
SetScrollSizesÉèÖô°¿ÚµÄÓ³Éäģʽ£¬´°¿Ú³ß´ç£¬Ò³ºÍÐгߴ硣sizeDefualt±»¶¨ÒåΪ£¨0£¬0£©¡£
?
ÏÂÃæ¼¸¸öº¯ÊýÓÃÀ´ÊµÏÖ¹ö¶¯»òÕߵõ½¹ö¶¯ÌõÏà¹ØµÄÐÅÏ¢
void ScrollToPosition(POINT pt); // set upper left position void FillOutsideRect(CDC* pDC, CBrush* pBrush); void ResizeParentToFit(BOOL bShrinkOnly = TRUE);
CPoint GetScrollPosition() const; // upper corner of scrolling CSize GetTotalSize() const; // logical size
?
ÏÂÃæÁ½¸öº¯ÊýʹÓÃÁËÉè±¸×ø±êµ¥Î»
CPoint GetDeviceScrollPosition() const;
void GetDeviceScrollSizes(int& nMapMode, SIZE& sizeTotal, SIZE& sizePage, SIZE& sizeLine) const;
?
¸²¸ÇµÄÏûÏ¢´¦Àíº¯Êý
´¦ÀíWM_SIZEµÄOnSize£» ´¦ÀíWM_HSCROLLµÄOnHScroll£» ´¦ÀíWM_VSCROLLµÄOnVScroll£»
?
¸²¸ÇµÄÐéÄ⺯Êý
CWndµÄCalcWindowRect
CViewµÄOnPrepareDC¡¢OnScroll¡¢OnScrollBy
?
ÓÃÓÚDEBUGµÄDumpºÍAssertValid
ÕâÀ¸²¸ÇµÄÏûÏ¢´¦Àíº¯ÊýºÍÐéÄ⺯Êý¹²Í¬Íê³É¶Ô¹ö¶¯Ìõ¡¢¹ö¶¯ÏûÏ¢µÄ´¦Àí¡£
ÔÚCSrcollViewµÄʵÏÖÉæ¼°µ½Ðí¶àºÍWindowsÓ³Éäģʽ¡¢×ø±êת»»µÈÏà¹ØµÄº¯ÊýµÄʹÓá£ÕâÀ²»×÷¾ßÌåÌÖÂÛ¡£
1. CFormView
CFormViewÅÉÉúÓÚCSrcollView£¬±¾ÉíûÓÐÔö¼Óеĺ¯Êý£¬µ«¸²¸ÇÁËһЩ»ùÀàµÄÐéÄ⺯Êý£¬Ôö¼ÓÁ˼¸¸ö³ÉÔ±±äÁ¿£¨ÒÔÏÂÁгöµÄ²»°üº¬OLE´¦Àí£©¡£ 1. Ôö¼ÓµÄ³ÉÔ±±äÁ¿
LPCTSTR m_lpszTemplateName; CCreateContext* m_pCreateContext;
HWND m_hWndFocus; // last window to have focus
m_lpszTemplateNameÓÃÀ´±£´æ´´½¨ÊÓͼµÄ¶Ô»°¿òÄ£°åµÄÃû³Æ£¬
_pCreateContextÓÃÀ´±£´æ´´½¨ÉÏÏÂÎÄ£¬m_hWndFocusÓÃÀ´±£´æ×î½üÒ»´ÎÓµÓн¹µãµÄ¿ØÖÆ´°¿Ú¡£ÔÚ¹¹ÔìCFormView¶ÔÏóʱ£¬¹¹Ô캯Êý°ÑÓйØÐÅÏ¢±£´æµ½³ÉÔ±±äÁ¿ÖУ¬ÈçÏÂËùʾ£º
CFormView::CFormView(LPCTSTR lpszTemplateName) {
m_lpszTemplateName = lpszTemplateName; m_pCreateContext = NULL;
m_hWndFocus = NULL; // focus window is font }
2. ¸²¸ÇµÄÐéÄ⺯Êý
virtual void OnDraw(CDC* pDC); // MFCȱʡ´¦Àí¿Õ virtual BOOL Create(LPCTSTR, LPCTSTR, DWORD, const RECT&, CWnd*, UINT, CCreateContext*); virtual BOOL PreTranslateMessage(MSG* pMsg); virtual void OnActivateView(BOOL, CView*, CView*); virtual void OnActivateFrame(UINT, CFrameWnd*);
´´½¨»ùÓÚ¶Ô»°¿òµÄÊÓ´°¿Ú£¬²»Í¬ÓÚ´´½¨ÆÕͨÊÓ´°¿Ú£¨Ç°Õßµ÷ÓÃ
CWnd::CreateEx£¬ºóÕßµ÷ÓÃCWnd::CreateDlg£©£¬¹ÊÐèÒª¸²¸ÇCreateÐéÄ⺯Êý¡£
¸²¸ÇPreTranslateMessageÊÇΪÁ˹ýÂ˶Ի°¿òÏûÏ¢£¬°ÑһЩÏûÏ¢ÈÃCFormView¶ÔÏóÀ´´¦Àí¡£ 3. ¸²¸ÇÁËÁ½¸öÏûÏ¢´¦Àíº¯Êý£º
afx_msg int OnCreate(LPCREATESTRUCT lpcs); afx_msg void OnSetFocus(CWnd* pOldWnd);
ÏÂÃæ£¬·ÖÎö¼¸¸öº¯Êý×÷¡£Createº¯Êý½âÊÍÁËMFCÈçºÎʹÓÃÒ»¸ö¶Ô»°¿ò×÷ΪÊӵķ½·¨£¬PreTranslateMessageÏÔʾÁËCFormView²»Í¬ÓÚCDialogµÄʵÏÖ¡£
1. CFormViewµÄ´´½¨
Éè¼ÆCFormViewµÄ´´½¨º¯Êý£¬±ØÐ뿼ÂÇÁ½¸öÎÊÌ⣺ Ê×ÏÈ£¬CFormViewÊÇÒ»¸öÊÓ£¬Æä´´½¨º¯Êý±ØÐëÊÇÒ»¸öÐéÄ⺯Êý£¬ÔÐͱØÐëºÍ
CWnd::Create(LPSTR?pContext)º¯ÊýÒ»Ö£¬¼ûͼ5-13ÊӵĴ´½¨¡£Æä´Î£¬CFormViewʹÓÃÁ˶Ի°¿ò´´½¨º¯ÊýºÍ¶Ô»°¿ò¡°´°¿ÚÀࡱÀ´´´½¨ÊÓ£¬µ«±ØÐë×÷һЩ´¦ÀíʹµÃ¸Ã´°¿Ú¾ß±¸ÊÓµÄÌØÕ÷¡£ CreateµÄʵÏÖÈçÏ£º
BOOL CFormView::Create(LPCTSTR /*lpszClassName*/,
LPCTSTR /*lpszWindowName*/,
DWORD dwRequestedStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) {
ASSERT(pParentWnd != NULL);
ASSERT(m_lpszTemplateName != NULL);
m_pCreateContext = pContext; // save state for later OnCreate #ifdef _DEBUG
// dialog template must exist and be invisible with WS_CHILD set
if
(!_AfxCheckDialogTemplate(m_lpszTemplateName, TRUE)) {
ASSERT(FALSE); // invalid dialog template name PostNcDestroy(); // cleanup if Create fails too soon
return FALSE; }
#endif //_DEBUG
//Èôcommon control windowÀ໹ûÓÐ×¢²á£¬Ôò×¢²á VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTLS_REG));
// call PreCreateWindow to get prefered extended style
CREATESTRUCT cs; memset(&cs, 0, sizeof(CREATESTRUCT)); if (dwRequestedStyle == 0)
dwRequestedStyle = AFX_WS_DEFAULT_VIEW; cs.style = dwRequestedStyle; if (!PreCreateWindow(cs)) return FALSE;
//::CreateDialogIndirect¼ä½Ó±»µ÷ÓÃÀ´´´½¨Ò»¸öÎÞģʽ¶Ô»°¿ò
if (!CreateDlg(m_lpszTemplateName, pParentWnd)) return FALSE;
//´´½¨¶Ô»°¿òʱ£¬OnCreate±»µ÷Óã¬m_pCreateContextµÄ×÷ÓýáÊøÁË m_pCreateContext = NULL;
// we use the style from the template - but make sure that
// the WS_BORDER bit is correct
// the WS_BORDER bit will be whatever is in dwRequestedStyle
ModifyStyle(WS_BORDER|WS_CAPTION, cs.style & (WS_BORDER|WS_CAPTION));
ModifyStyleEx(WS_EX_CLIENTEDGE, cs.dwExStyle & WS_EX_CLIENTEDGE); SetDlgCtrlID(nID); CRect rectTemplate;
GetWindowRect(rectTemplate);
SetScrollSizes(MM_TEXT, rectTemplate.Size()); // initialize controls etc
if (!ExecuteDlgInit(m_lpszTemplateName)) return FALSE;
// force the size requested
SetWindowPos(NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,