控件中加载一个子窗体,窗体隐藏后CPU占用率奇高,请高手指教!
dlgPage.Create(IDD_DLGPAGE,this);
CRect rcDS;
dlgPage.GetWindowRect(&rcDS);
dlgPage.MoveWindow(0,
0,
rcDS.Width(),
rcDS.Height(),
FALSE);
dlgPage.parentHwnd=m_hWnd;
dlgPage.ShowWindow(SW_HIDE);
窗体代码:
#define WM_MYPAGE (WM_USER+103)
class CDlgPage : public CDialog
{
// Construction
public:
int i;
HWND hWnd;
HWND parentHwnd;
CDlgPage(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CDlgPage)
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDlgPage)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CDlgPage)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnBtnpre();
afx_msg void OnBtnnext();
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CDlgPage::CDlgPage(CWnd* pParent /*=NULL*/)
{
//{{AFX_DATA_INIT(CDlgPage)
//}}AFX_DATA_INIT
}
void CDlgPage::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgPage)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgPage, CDialog)
//{{AFX_MSG_MAP(CDlgPage)
ON_WM_ERASEBKGND()
ON_BN_CLICKED(IDC_BTNPRE, OnBtnpre)
ON_BN_CLICKED(IDC_BTNNEXT, OnBtnnext)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgPage message handlers
void CDlgPage::OnBtnpre()
{
GetDlgItem(IDC_BTNNEXT)->EnableWindow(TRUE);
i++;
::SendMessage(parentHwnd,WM_MYPAGE,(long)-1,0);
}
void CDlgPage::OnBtnnext()
{
::SendMessage(parentHwnd,WM_MYPAGE,(long)1,0);
i--;
if(i<=0)
{
GetDlgItem(IDC_BTNNEXT)->EnableWindow(FALSE);
i=0;
}
}
BOOL CDlgPage::OnEraseBkgnd(CDC* pDC)
{
//return CWnd::OnEraseBkgnd(pDC);
return TRUE;
}
BOOL CDlgPage::OnInitDialog()
{
CDialog::OnInitDialog();
i=0;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}