OnPaint问题
各位英雄好汉,小弟我在编程时遇到这样难题:
我采用MFC 的MDI 结构,调用CFormView界面,其中CFormView中的Picture控件通过抓图:
CString wnd_name=_T("Figure 1");
hFig = ::FindWindow(NULL,wnd_name);
if (hFig==NULL)
{
hFig = ::FindWindow(NULL,wnd_name);
}
::ShowWindow(hFig, SW_HIDE);
CRect figure_rect;
CWnd *myfigure = GetDlgItem(IDC_STATIC);
myfigure->GetWindowRect(&figure_rect);
long fig_width = figure_rect.Width();
long fig_height = figure_rect.Height();
::SetParent(hFig,myfigure->GetSafeHwnd());
// 去掉MATLAB Figure窗口的标题栏和框架属性
long lStyle = ::GetWindowLong(hFig,GWL_STYLE);
::SetWindowLong(hFig,GWL_STYLE,lStyle );
::ShowWindow(hFig, SW_SHOW);
// 将MATLAB Figure窗口移动到空间位置
::SetWindowPos(hFig,NULL,0,0,fig_width+8,fig_height+33,SWP_NOZORDER | SWP_NOACTIVATE);
// 显示窗口
::ShowWindow(hFig, SW_SHOW);
// 激活主窗口
::SetForegroundWindow(this->m_hWnd);
以上也就是抓取MATLAB的仿真图像,使其显示在picture控件中。
接下来,我通过OnPaint绘图来画:
void CsubForm::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CFormView::OnPaint() for painting messages
::ShowWindow(hFig, SW_HIDE);
CRect figure_rect;
CWnd *myfigure = GetDlgItem(IDC_STATIC);
myfigure->GetWindowRect(&figure_rect);
long fig_width = figure_rect.Width();
long fig_height = figure_rect.Height();
::SetParent(hFig,myfigure->GetSafeHwnd());
// 去掉MATLAB Figure窗口的标题栏和框架属性
long lStyle = ::GetWindowLong(hFig,GWL_STYLE);
::SetWindowLong(hFig,GWL_STYLE,lStyle );
::ShowWindow(hFig, SW_SHOW);
// 将MATLAB Figure窗口移动到空间位置
::SetWindowPos(hFig,NULL,0,0,fig_width+8,fig_height+33,SWP_NOZORDER | SWP_NOACTIVATE);
// 显示窗口
::ShowWindow(hFig, SW_SHOW);
// 激活主窗口
::SetForegroundWindow(this->m_hWnd);
}
我采用类似的代码实现,但是问题来了,当我的子窗口CFormView移到父窗口里,即被父窗口重叠一部分时,我此时拖拽子窗口时,会很卡顿,跟踪的原因就是在OnPaint 中的这个::SetParent(hFig,myfigure->GetSafeHwnd());,我现在不知道该怎么处理了。请问大家这是什么原因,该怎么解决?谢谢。