resizing problem in a selfmade MDIChildFrame
-
Hi all, I've written an MFC MDI application where I need an additional child frame to show other aspects of my data. So I derived a class from CMDIChildWnd and created the Icon, Accelerator and Menu. My view for this child frame is derived from CFormView and has a chart control an a button control. I call/create the child frame by choosing a menu entry as follows:
void CmyApp::OnAnsichtnewView() { // TODO: Fügen Sie hier Ihren Befehlsbehandlungscode ein. CMainFrame *pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd); pFrame->CreateNewChild(RUNTIME_CLASS(CmyChildFrm), IDR_myTYPE); CRect cr; pFrame->GetActiveFrame()->GetClientRect(cr); CDocument *pDoc = pFrame->GetActiveDocument(); CRuntimeClass *pRTC = RUNTIME_CLASS(CmyFromView); CCreateContext context; context.m_pCurrentDoc = pDoc; context.m_pNewViewClass = pRTC; context.m_pLastView = NULL; pFrame->GetActiveFrame()->CreateView(&context); }
In my view class I've overwritten the OnSize method as follows:void CmyFormView::OnSize(UINT nType, int cx, int cy) { CFormView::OnSize(nType, cx, cy); // TODO: Fügen Sie hier Ihren Meldungsbehandlungscode ein. if(m_Chart.GetSafeHwnd() != NULL) { m_Chart.MoveWindow(0, 0, cx-30, cy); AfxMessageBox("Chart resized"); } if(m_Button.GetSafeHwnd()) { m_Button.MoveWindow(cx-30, 0, 30, 30); AfxMessageBox("Button resized"); } AfxMessageBox("Form resized"); }
When I run my programm and do a resize on my new child, I only get a "Form resized" MessageBox. So, obviously m_Chart and m_Button don't get a Hwnd but I don't know why. Can anybody give me a hint on this? Thanks, Frank. -
Hi all, I've written an MFC MDI application where I need an additional child frame to show other aspects of my data. So I derived a class from CMDIChildWnd and created the Icon, Accelerator and Menu. My view for this child frame is derived from CFormView and has a chart control an a button control. I call/create the child frame by choosing a menu entry as follows:
void CmyApp::OnAnsichtnewView() { // TODO: Fügen Sie hier Ihren Befehlsbehandlungscode ein. CMainFrame *pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd); pFrame->CreateNewChild(RUNTIME_CLASS(CmyChildFrm), IDR_myTYPE); CRect cr; pFrame->GetActiveFrame()->GetClientRect(cr); CDocument *pDoc = pFrame->GetActiveDocument(); CRuntimeClass *pRTC = RUNTIME_CLASS(CmyFromView); CCreateContext context; context.m_pCurrentDoc = pDoc; context.m_pNewViewClass = pRTC; context.m_pLastView = NULL; pFrame->GetActiveFrame()->CreateView(&context); }
In my view class I've overwritten the OnSize method as follows:void CmyFormView::OnSize(UINT nType, int cx, int cy) { CFormView::OnSize(nType, cx, cy); // TODO: Fügen Sie hier Ihren Meldungsbehandlungscode ein. if(m_Chart.GetSafeHwnd() != NULL) { m_Chart.MoveWindow(0, 0, cx-30, cy); AfxMessageBox("Chart resized"); } if(m_Button.GetSafeHwnd()) { m_Button.MoveWindow(cx-30, 0, 30, 30); AfxMessageBox("Button resized"); } AfxMessageBox("Form resized"); }
When I run my programm and do a resize on my new child, I only get a "Form resized" MessageBox. So, obviously m_Chart and m_Button don't get a Hwnd but I don't know why. Can anybody give me a hint on this? Thanks, Frank. -
Hi all, I've written an MFC MDI application where I need an additional child frame to show other aspects of my data. So I derived a class from CMDIChildWnd and created the Icon, Accelerator and Menu. My view for this child frame is derived from CFormView and has a chart control an a button control. I call/create the child frame by choosing a menu entry as follows:
void CmyApp::OnAnsichtnewView() { // TODO: Fügen Sie hier Ihren Befehlsbehandlungscode ein. CMainFrame *pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd); pFrame->CreateNewChild(RUNTIME_CLASS(CmyChildFrm), IDR_myTYPE); CRect cr; pFrame->GetActiveFrame()->GetClientRect(cr); CDocument *pDoc = pFrame->GetActiveDocument(); CRuntimeClass *pRTC = RUNTIME_CLASS(CmyFromView); CCreateContext context; context.m_pCurrentDoc = pDoc; context.m_pNewViewClass = pRTC; context.m_pLastView = NULL; pFrame->GetActiveFrame()->CreateView(&context); }
In my view class I've overwritten the OnSize method as follows:void CmyFormView::OnSize(UINT nType, int cx, int cy) { CFormView::OnSize(nType, cx, cy); // TODO: Fügen Sie hier Ihren Meldungsbehandlungscode ein. if(m_Chart.GetSafeHwnd() != NULL) { m_Chart.MoveWindow(0, 0, cx-30, cy); AfxMessageBox("Chart resized"); } if(m_Button.GetSafeHwnd()) { m_Button.MoveWindow(cx-30, 0, 30, 30); AfxMessageBox("Button resized"); } AfxMessageBox("Form resized"); }
When I run my programm and do a resize on my new child, I only get a "Form resized" MessageBox. So, obviously m_Chart and m_Button don't get a Hwnd but I don't know why. Can anybody give me a hint on this? Thanks, Frank. -
It seems your
m_Button
and m_Chart
variables were not associated with child controls. Did you create your child controls withCreate
member, likem_Button.Create(. . .)
, or in a different way? Maybe you should show us more details.I used the dialog editor to create the controls. The chart control is an ActiveX control and the button is actually a checkbox control, which behaves like a button. In this editor I also assigned the member variables by a right click on the control and let the framework do the job. So the framework also created the DataExchange
void CmyFormView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
DDX_Control(pDX, IDC_TCHART_Chart, m_Chart);
DDX_Control(pDX, IDC_CHECK_Button, m_Button);
}I created also another child frame in the same way but assigned it to a DocTemplate so that it starts when the programm start. Here I don't have resizing problems. So maybe I did something wrong in my OnAnsichtnewView part when the user creates the child frame. Maybe I have to pass a handle? Thanks, Frank. -- modified at 7:32 Saturday 25th November, 2006