Re: deriving helper class from CWnd
"Scott McPhillips [MVP]" wrote:
Yes, it is necessary to call Create to give the CWnd an m_hWnd. If that is
not working then show your code. In fact, the help page for CWnd::Create
shows this example: Is your's this simple?
void CMyDlg::OnCreateStatic()
{
CWnd* pWnd = new CWnd;
pWnd->Create(_T("STATIC"), "Hi", WS_CHILD | WS_VISIBLE,
CRect(0, 0, 20, 20), this, 1234);
}
Immediately after the Create call you should be able to add a SetTimer call.
Here is what I have tried:
BOOL CersatzbdsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// ...
// TODO: Add extra initialization here
MsgSendListInit();
// trying to stop an assert failure on ASSERT(::IsWindow(m_hWnd) within
m_engine.SetTimer()
m_engine.Create("BdsEngine", "engine", WS_CHILD, CRect(0, 0, 20, 20), this,
1234);
//...
}
The timer is later set from the UI CDialog by clicking a check control:
void CersatzbdsDlg::OnBnClickedCheckSendStatus()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(BST_CHECKED == m_ckSendStatusReq.GetCheck())
m_engine.SendStatusStart();
else m_engine.SendStatusStop();
}
and in the engine class:
void CBdsEngine::SendStatusStart()
{
m_timerIdStatusRequest = SetTimer(4 /*TIMER_ID_STATUS_REQ*/, // timer ID
m_StatusReqInterval, // Timeout
0); // No callback
}
void CBdsEngine::SendStatusStop()
{
KillTimer(m_timerIdStatusRequest);
}
void CBdsEngine::OnTimer(UINT_PTR nIDEvent)
{
// See which timer event brought us here
switch(nIDEvent)
{
case TIMER_ID_STATUS_REQ: //
-------------------------------------------------
SendFdlStatusRequest();
break;
default:
MessageBox("Unknown timer fired");
break;
}
}