Using ClassWizard to add a CButton variable

This should be easy, but I'm having problems with it. I have used the ClassWizard to create a CButton variable (namely m_button) in my FormView Class, but I get assertion failure whenever I call any functions of it, coz the m_hwnd variable is always null. Do I need to call the Create function in the constructor of my FormView, but then will I lose the dimensions which I set using the resource editor?
vintsangAsked:
Who is Participating?
 
DanRollinsConnect With a Mentor Commented:
I'm glad I was able to solve your problem for you.

-- Dan
0
 
DanRollinsCommented:
It does work.  But you must only call CButton member variables after all of the controls have been created.  Which means:  wait until OnInitialUpdate() to start doing stuff.

-- Dan
0
 
vintsangAuthor Commented:
Thanks Dan, but actually I'm doing everything in OnInitialUpdate(). I used ClassWizard to create a CButton variable (m_button) in my FormView class, then in the OnInitialUpdate() function I called:

HICON hIcon = LoadIcon(::AfxGetInstanceHandle(),        MAKEINTRESOURCE(IDI_STOP));
    m_button.SetIcon(hIcon);

to set the icon of the button, but I got assertion failure in the second statement because at that time m_button.m_hWnd is still null. Did I miss anything important?
0
 
vintsangAuthor Commented:
Oh, I have solved the problem already. Just forgot to call CFormView::OnInitialUpdate() first... :>
0
 
DanRollinsCommented:
vintsang:
Why have you insulted me with a C?

You offer only 5 points for a question -- when 50 points is the level that means 'easy'.  Nobody else would even look at a 5-pt question, but out of the kindness of my heart, I helped you find the solution.  Then you slap me in the face.  Why?

-- Dan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.