Problem using then event of OnSize
-
I built a demo project that using OLE-DB,I add two controls on my form (Single Document),one is DataGrid,the other is ADODC,What my purpose is that I want to resize the size of the two controls when the form shows,the variables that connect to the two controls are m_DataGrid and m_AdoDC; the code is as followed: void CADO2View::OnSize(UINT nType, int cx, int cy) { int iHeight; int iWidth; CRect oRect; COleDBRecordView::OnSize(nType, cx, cy); if (m_AdoDC.m_hWnd==NULL||m_DataGrid.m_hWnd==NULL) { return; } else { m_AdoDC.GetClientRect(oRect); iHeight=oRect.Height(); iWidth=oRect.Width(); m_AdoDC.MoveWindow(0,0,iWidth,iHeight,TRUE); m_DataGrid.MoveWindow(0,iHeight,cx,xy,TRUE); } } But the code doesn't work,so how to resize the controls when the form shows? Nothend -- modified at 19:51 Monday 8th January, 2007
Well, I didn't look at all the details of your code for my previous answer (your explanation was a bit vague). But I think the problem is here:
Nothend wrote:
m_AdoDC.GetClientRect(oRect); iHeight=oRect.Height(); iWidth=oRect.Width(); m_AdoDC.MoveWindow(0,0,iWidth,iHeight,TRUE); m_DataGrid.MoveWindow(0,iHeight,cx,xy,TRUE);
You said that m_AdoDC is a member of your class, so it will never resize. The only thing that is resizing is your view. So what you need to do is retrieve the new size of your view (using GetClientRect) and then calculate the new sizes of the two other controls.
Cédric Moonen Software developer
Charting control [v1.1] -
Nothend wrote:
But the code doesn't work,so how to resize the controls when the form shows?
What happens exaclty ? What does 'not working' mean ? Also, use the pre or code tag when you post code (it will make it more readable)
Cédric Moonen Software developer
Charting control [v1.1]I am sorry about that,because I am a student from China,my English is poor. What I want is that when the view shows,the DataGrid and the ADODC will position the right place on the form(view),not the place I put when using the control bar. As the code shows that,the event of OnSize takes place first than that of DoDataExchange,so the two variables(m_AdoDC and m_DataGrid) are null when OnSize takes place. I use PostMessage(WM_SIZE) in the event of OnInitialUpdate,and then it happpens,but the control ADODC doesn't move when I pull the form ,and the DataGrid does. So how can I do ? Thanks a lot! Nothend
-
Well, I didn't look at all the details of your code for my previous answer (your explanation was a bit vague). But I think the problem is here:
Nothend wrote:
m_AdoDC.GetClientRect(oRect); iHeight=oRect.Height(); iWidth=oRect.Width(); m_AdoDC.MoveWindow(0,0,iWidth,iHeight,TRUE); m_DataGrid.MoveWindow(0,iHeight,cx,xy,TRUE);
You said that m_AdoDC is a member of your class, so it will never resize. The only thing that is resizing is your view. So what you need to do is retrieve the new size of your view (using GetClientRect) and then calculate the new sizes of the two other controls.
Cédric Moonen Software developer
Charting control [v1.1]I am sorry about that,because I am a student from China,my English is poor. What I want is that when the view shows,the DataGrid and the ADODC will position the right place on the form(view),not the place I put when using the control bar. As the code shows that,the event of OnSize takes place first than that of DoDataExchange,so the two variables(m_AdoDC and m_DataGrid) are null when OnSize takes place. I use PostMessage(WM_SIZE) in the event of OnInitialUpdate,and then it happpens,but the control ADODC doesn't move when I pull the form ,and the DataGrid does. So how can I do ? Thanks a lot!
-
I built a demo project that using OLE-DB,I add two controls on my form (Single Document),one is DataGrid,the other is ADODC,What my purpose is that I want to resize the size of the two controls when the form shows,the variables that connect to the two controls are m_DataGrid and m_AdoDC; the code is as followed: void CADO2View::OnSize(UINT nType, int cx, int cy) { int iHeight; int iWidth; CRect oRect; COleDBRecordView::OnSize(nType, cx, cy); if (m_AdoDC.m_hWnd==NULL||m_DataGrid.m_hWnd==NULL) { return; } else { m_AdoDC.GetClientRect(oRect); iHeight=oRect.Height(); iWidth=oRect.Width(); m_AdoDC.MoveWindow(0,0,iWidth,iHeight,TRUE); m_DataGrid.MoveWindow(0,iHeight,cx,xy,TRUE); } } But the code doesn't work,so how to resize the controls when the form shows? Nothend -- modified at 19:51 Monday 8th January, 2007
Why it dosent work?
WhiteSky
-
I am sorry about that,because I am a student from China,my English is poor. What I want is that when the view shows,the DataGrid and the ADODC will position the right place on the form(view),not the place I put when using the control bar. As the code shows that,the event of OnSize takes place first than that of DoDataExchange,so the two variables(m_AdoDC and m_DataGrid) are null when OnSize takes place. I use PostMessage(WM_SIZE) in the event of OnInitialUpdate,and then it happpens,but the control ADODC doesn't move when I pull the form ,and the DataGrid does. So how can I do ? Thanks a lot!
You can use of
SendMessage(WM_SIZE)
WhiteSky
-
Why it dosent work?
WhiteSky
-
Because the event of OnSize takes place first than that of DoDataExchange,so the controls' m_hWnds are null. I have used the PostMessage(WM_SIZE),it works,but the ADODC control can't move,I don't know why. Thanks Nothend
What happens if you insert
ScreenToClient/*for converts coordinates */
afterm_AdoDC.GetClientRect(oRect);
m_AdoDC.GetClientRect(oRect);
m_AdoDC.ScreenToClient(oRect);
WhiteSky
-
Because the event of OnSize takes place first than that of DoDataExchange,so the controls' m_hWnds are null. I have used the PostMessage(WM_SIZE),it works,but the ADODC control can't move,I don't know why. Thanks Nothend
Nothend wrote:
Because the event of OnSize takes place first than that of DoDataExchange,so the controls' m_hWnds are null.
Call
UpdateData
as first statement inOnSize
, which eventually callsDoDataExchange
.Prasad Notifier using ATL | Operator new[],delete[][^]
-
What happens if you insert
ScreenToClient/*for converts coordinates */
afterm_AdoDC.GetClientRect(oRect);
m_AdoDC.GetClientRect(oRect);
m_AdoDC.ScreenToClient(oRect);
WhiteSky
-
What happens if you insert
ScreenToClient/*for converts coordinates */
afterm_AdoDC.GetClientRect(oRect);
m_AdoDC.GetClientRect(oRect);
m_AdoDC.ScreenToClient(oRect);
WhiteSky
-
Nothend wrote:
Because the event of OnSize takes place first than that of DoDataExchange,so the controls' m_hWnds are null.
Call
UpdateData
as first statement inOnSize
, which eventually callsDoDataExchange
.Prasad Notifier using ATL | Operator new[],delete[][^]