我对无模式对话框窗口(它是CDialogEx窗口的子窗口)的OnTimer()函数有问题,它拒绝触发。
当我使用CDialog :: DoModal()函数使对话框Modal正常工作时。 但是我想要无模式对话框。
您能解释一下这里发生什么吗?
我努力做到准确。 ClogoDlg对话框是应用程序的SPLASH窗口。它显示3分钟,中间是运行Longy Operation的程序。 SPLASH窗口显示持续时间。因此,我需要OnTimer()函数。
谢谢。
我的代码是:
BOOL Clotto2Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
ClogoDlg* pdlg=new ClogoDlg();
pdlg->Create(GetDesktopWindow());
//pdlg->DoModal();
pdlg->ShowWindow(SW_SHOW);
}
我的ClogoDlg.cpp
#include "stdafx.h"
#include "ClogoDlg.h"
IMPLEMENT_DYNAMIC(ClogoDlg, CDialog)
ClogoDlg::ClogoDlg(CWnd* pParent ) : CDialog(ClogoDlg::IDD, pParent)
{
}
ClogoDlg::~ClogoDlg()
{
KillTimer(m_nTimer);
}
BOOL ClogoDlg::Create(CWnd* pParentWnd)
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::Create(ClogoDlg::IDD,pParentWnd);
}
BEGIN_MESSAGE_MAP(ClogoDlg, CDialog)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_WM_PAINT()
ON_WM_TIMER()
END_MESSAGE_MAP()
void ClogoDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
Invalidate();
CDialog::OnLButtonDown(nFlags, point);
}
void ClogoDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDblClk(nFlags, point);
}
BOOL ClogoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_nTimer = SetTimer(2, 1000, NULL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL ClogoDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::PreTranslateMessage(pMsg);
}
void ClogoDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
CTime timeNow;
timeNow = CTime::GetCurrentTime();
CString str;
str.Format(L"%3d:%2d:%2d", timeNow.GetHour(), timeNow.GetMinute(), timeNow.GetSecond());
dc.TextOut(10,10, str);
}
void ClogoDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
Invalidate();
CDialog::OnTimer(nIDEvent);
}
还有我的ClogoDlg.h
#pragma once
#include "resource.h"
class ClogoDlg:public CDialog
{
DECLARE_DYNAMIC(ClogoDlg)
public:
enum{IDD=IDD_LOGO};
ClogoDlg();
~ClogoDlg();
BOOL Create(CWnd * pParent = NULL);
CTime timer;
int m_nTimer;
DECLARE_MESSAGE_MAP()
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
virtual BOOL OnInitDialog();
virtual BOOL PreTranslateMessage(MSG* pMsg);
afx_msg void OnPaint();
afx_msg void OnTimer(UINT_PTR nIDEvent);
};