I’m currently developing a custom control that derives from CStatic MFC class (Smart Device C++ project).
I have created the control class using VC++ MFC class wizard, selecting CStatic class as its base class. I have used Class View to add OnSize event handler for my control class (I have selected WM_SIZE message from messages list), and new OnSize method has been created by Visual Studio along with ON_WM_SIZE() statement between BEGIN_MESSAGE_MAP(…) and END_MESSAGE_MAP().
The problem is that my control does not receive WM_SIZE thus OnSize method is never called – I used MoveWindow to change size of my control – its size changes as I have seen on dialog window but WM_SIZE message is never being sent. When I send WM_SIZE through SendMessage or PostMessage function – the control OnSize method is called normally. What do I wrong? I’ve read MSDN docs about CStatic control and there is no information that WM_SIZE message is never sent to a static control window.
Sorry for my bad English.
For a Windows dialog based project I’ve tested what you describe. I receive WM_SIZE messages in the custom control after a call of MoveWindow. Can you post a few pieces of your source code, especially for the dialog class where you use your custom Static control for your test?
Update after you posted your code
Did you run this in a debugger? I’m wondering why you don’t get immediately an exception when the dialog is opened because CThreatSelection::OnSize is fired as one of the first events, even before the window handle
threatGrid.m_hWndof your control exists at all. So callingthreatGrid.MoveWindowin your OnSize dialog event should cause an exception when the dialog opens.I’m not sure what you are trying to achieve but it looks that you want to resize your custom Static according to the dialog size as soon as the dialog opens:
For this a possible alternative could be: Remove
CThreatSelection::OnSizeand place inCThreatSelection::OnInitDialoginstead:Here you can call threatGrid.MoveWindow because the Window Handle
threatGrid.m_hWndis already created inOnInitDialog.