Question

I have an MFC Visual C++ application which seems to not be able to work within the Class Wizard, nevertheless, I have a view (CServerView) which I would like to add a WM_TIMER event handler to.

I have figured out how to call CWnd::SetTimer and CWnd::KillTimer but what I haven't done in over a decade is modify the message map. I'm not sure if the map I should modify for my CView subclass is this part of the ServerView.cpp file, or something in ServerView.h:

BEGIN_MESSAGE_MAP(CServerView, CListView)
    //{{AFX_MSG_MAP(CServerView)
    ON_COMMAND(ID_DRIVER_START, OnDriverStart)
    ON_UPDATE_COMMAND_UI(ID_DRIVER_START, OnUpdateDriverStart)
        ...
    // Standard printing commands
END_MESSAGE_MAP()

This is probably a trivial thing, but the two complex issues I'm facing are that the documentation online on this is all for recent Visual Studio versions, and I'm stuck doing this in Visual C++ 6.0

Was it helpful?

Solution

In your header file:

afx_msg void OnTimer(UINT_PTR nIDEvent);

In your cpp file:

BEGIN_MESSAGE_MAP(CMyView, CView)
    ON_WM_TIMER()
END_MESSAGE_MAP()

void CMyView::StartTimer
{
    m_nTimerID = SetTimer(2348,100,0);
}

void CMyView::OnTimer(UINT_PTR nIDEvent)
{
    if(nIDEvent==m_nTimerID)
    {
    }
    CView::OnTimer(nIDEvent);
}

OTHER TIPS

I think it's called ON_TIMER or ON_WM_TIMER. Check the installed includes for the place where ON_COMMAND&Co are defined, there you'll find it. Alternatively, search the MSDN online at MS'. The name of this thing didn't change btw, so recent versions' docs are okay. And I would strongly suggest upgrading, VC6, aka VS98 is turning 15 years this year and MS have long since ceased any support for it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top