MFC中触发OnSize讯息后Picture Control上画的图不见了。不知道覆盖了还是压根就整个控件丢失了
MFC中触发OnSize消息后Picture Control上画的图不见了。不知道覆盖了还是压根就整个控件丢失了。
初始状态

调用OnSize后调试明明还调用了OnPaint重绘Picture Control(关联的控件变量m_Chart)

求大神帮忙看看哪里出了问题感激不尽
贴上OnSize和OnPaint的代码
OnSize()
OnPaint()
------解决思路----------------------
把 CDialog::OnPaint()放在前面试试
------解决思路----------------------
没发现你的OnSize里面调用了OnPaint。
------解决思路----------------------
SetWidth(m_Chart, iWinWidth-120/kTP);
SetHeight(m_Chart, iWinHeight-1770/kTP);
后加
CRect rect;
m_Chart.GetWindowRect(&rect);
看 对不对
初始状态
调用OnSize后调试明明还调用了OnPaint重绘Picture Control(关联的控件变量m_Chart)
求大神帮忙看看哪里出了问题感激不尽
贴上OnSize和OnPaint的代码
OnSize()
void CChartForm::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// When creating dialog box, the control has not been created, so you can't change the size(must add these two lines of code)
if(!IsWindowVisible())
return;
// Resizing the form
// Hide buttons while we reposition them
m_OK.ShowWindow(SW_HIDE);
m_CancelButton.ShowWindow(SW_HIDE);
m_Options.ShowWindow(SW_HIDE);
m_ClearButton.ShowWindow(SW_HIDE);
m_HelpButton.ShowWindow(SW_HIDE);
int iWinWidth = GetWidth(this);
int iWinHeight = GetHeight(this);
// Check that the form's new height and width meet minimum requirements
if (iWinHeight<OrigHeight) {
SetHeight(this, OrigHeight);
}
if (iWinWidth<OrigWidth) {
SetWidth(this, OrigWidth);
}
iWinWidth = GetWidth(this);
iWinHeight = GetHeight(this);
// Re-dimension chart picture box accordingly
SetWidth(m_Chart, iWinWidth-120/kTP);
SetHeight(m_Chart, iWinHeight-1770/kTP);
// Re-Position OK and CANCEL buttons on toolbar
SetLeft(m_OK, iWinWidth-4230/kTP);
SetLeft(m_CancelButton, iWinWidth-2910/kTP);
SetLeft(m_HelpButton, iWinWidth-1590/kTP);
SetLeft(m_Options, 120/kTP);
SetLeft(m_ClearButton, 1440/kTP);
SetTop(m_OK, iWinHeight-1305/kTP);
SetTop(m_CancelButton, iWinHeight-1305/kTP);
SetTop(m_Options, iWinHeight-1305/kTP);
SetTop(m_ClearButton, iWinHeight-1305/kTP);
SetTop(m_HelpButton, iWinHeight-1305/kTP);
// Redisplay buttons
m_OK.ShowWindow(SW_SHOW);
m_CancelButton.ShowWindow(SW_SHOW);
m_Options.ShowWindow(SW_SHOW);
m_ClearButton.ShowWindow(SW_SHOW);
m_HelpButton.ShowWindow(SW_SHOW);
// Re-dimension toolbar and statusbar accordingly
m_Toolbar1.SetWindowPos( NULL,0,0,iWinWidth,28,SWP_NOZORDER | SWP_NOMOVE );
m_TimeStatusBar.SetWindowPos( NULL,0,iWinHeight-25,iWinWidth,25,SWP_NOZORDER );
}
OnPaint()
void CChartForm::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this); // device context for painting
// Set back color for Chart control
CRect rect;
CDC * pDC = m_Chart.GetDC();
m_Chart.GetClientRect(&rect);
pDC->FillRect(rect,&CBrush(RGB(255,255,255)));
m_Chart.ReleaseDC(pDC);
DrawChart(this->m_Chart, TheChartData, Maximum, Minimum, fSnapSpacing, SnapSpacingFormat, FirstSlot, LastSlot, HoursPerDay, SlotsPerHour, ScheduleType, VerticalLines, bClearWindow, Major, Minor);
bClearWindow = false;
CDialog::OnPaint();
}
}
------解决思路----------------------
把 CDialog::OnPaint()放在前面试试
------解决思路----------------------
没发现你的OnSize里面调用了OnPaint。
------解决思路----------------------
SetWidth(m_Chart, iWinWidth-120/kTP);
SetHeight(m_Chart, iWinHeight-1770/kTP);
后加
CRect rect;
m_Chart.GetWindowRect(&rect);
看 对不对