我刚开始学习MFC的基础知识,因此我写了一个小练习程序,它只跟踪相对于窗口和每次移动屏幕的坐标并调整大小,一切正常除了这一点:MFC OnSize()问题无效
我怎样才能得到它,以便有留下当我调整窗口的大小没有结尾的油漆?
这里是我的筛上部分()代码:
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
// Get the window
CDC* dc;
dc = GetDC();
CRect rect;
GetWindowRect(rect);
InvalidateRect(rect);
// This if statement just makes sure new red text coordinates are not printed immediately upon starting the program
if (numSizeCalls > 1){
// Set up the font for future text output
CFont myfont;
VERIFY(myfont.CreateFont(
20, // nHeight in points
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
TRUE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("Arial"))); // lpszFacename
dc->SetTextColor(RGB(255, 0, 0));
dc->SelectObject(myfont);
DeleteObject(myfont);
// Set window coordinates relative to client area
ScreenToClient(&rect);
// Format them for TextOut
CString tl;
tl.Format(L"%d %d ; ", rect.top, rect.left);
CString tr;
tr.Format(L"%d %d ; ", rect.top, rect.right);
CString bl;
bl.Format(L"%d %d ; ", rect.bottom, rect.left);
CString br;
br.Format(L"%d %d", rect.bottom, rect.right);
// Get position for TextOut
TextOutYPosition += 20;
// Print them
dc->TextOut(5, TextOutYPosition, tl + tr + bl + br, _tcslen(tl) + _tcslen(tr) + _tcslen(bl) + _tcslen(br));
// Set coords relative to the screen
GetWindowRect(&rect);
// Format them for TextOut
tl.Format(L"%d %d ; ", rect.top, rect.left);
tr.Format(L"%d %d ; ", rect.top, rect.right);
bl.Format(L"%d %d ; ", rect.bottom, rect.left);
br.Format(L"%d %d", rect.bottom, rect.right);
// Get position for TextOut
TextOutYPosition += 20;
// Print them
dc->TextOut(5, TextOutYPosition, tl + tr + bl + br, _tcslen(tl) + _tcslen(tr) + _tcslen(bl) + _tcslen(br));
}
numSizeCalls++;
}
你的OnSize代码是什么样的? – 2014-10-30 19:12:42
@MarkRansom我已更新我的问题,代码为 – Riptyde4 2014-10-30 19:14:19