Control to Fill Dialog?
-
Hi, I am moving from C# to VC++ to test to see if it will meet my timing requirements. I am not familiar with VC++. I want to add an ActiveX control that fills a dialog box. So the size of the control will always match the size of the dialog when it is resized. This is easily done in C# .NET using the Anchor property. How can I do this in VC++? Can it be done by setting properties or do I have to create extra code to achive this? By the way I am using Visual Studio 2003 to create my code for an MFC application. Thanks, Liam
-
Hi, I am moving from C# to VC++ to test to see if it will meet my timing requirements. I am not familiar with VC++. I want to add an ActiveX control that fills a dialog box. So the size of the control will always match the size of the dialog when it is resized. This is easily done in C# .NET using the Anchor property. How can I do this in VC++? Can it be done by setting properties or do I have to create extra code to achive this? By the way I am using Visual Studio 2003 to create my code for an MFC application. Thanks, Liam
-
I think you will need to handle the
WM_SIZE
message:void CTheDialog::OnSize(...) { CRect rect; GetClientRect(&rect); m_Control.MoveWindow(&rect); }
Now the control will completely occupy the client area of the dialog. this is this.Khan++, thanks for the reply this worked for a while now it is failing an assertion: C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\src\mfc\winocc.cpp void CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint) { ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL)); ... Can you explain why this is? Also I would like to be able to have a fixed offset from a border. Can this be done easily. Thanks
-
Khan++, thanks for the reply this worked for a while now it is failing an assertion: C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\src\mfc\winocc.cpp void CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint) { ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL)); ... Can you explain why this is? Also I would like to be able to have a fixed offset from a border. Can this be done easily. Thanks
You will need to set a boolean variable at class level:
BOOL m_bInitialized;
And initialize it to FALSE in the constructor.m_bInitialized = FALSE;
And set it toTRUE
in theOnInitDialog()
function.m_bInitialized = TRUE;
Also send a resize message explicitly after setting itTRUE
:SendMessage(WM_SIZE,0,0);
Now modify OnSize() like this:OnSize() { CDialog::OnSize().....//whatever. if (m_bInitialized == TRUE) { Resize the client control here. } }
To set an offset you could:CRect rect; ... rect.DeflateRect(10,10,10,10);//This will reduce all the sides of the rect by 10 pixels.
this is this.