CFormView control sizing
-
I have two views ( CMainView and CMembersView ) in my SDI application. The code below resizes my MFC GridCtrl according to size of app's window when the view is initialized. I get valid values for CRect grid_rect {top=0 bottom=952 left=0 right=1819} in CMainView. But in CMemberView I am having some undesired values.
void CMembersView::OnInitialUpdate()
{CFormView::OnInitialUpdate(); initialized = TRUE; CWnd \*pGridCtrl = this->GetDlgItem(IDC\_MEMBERSGRID); ASSERT(pGridCtrl); // Must exist CRect rect,grid\_rect; CWnd \*pWnd = this->GetOwner(); pWnd->GetClientRect(rect); **pGridCtrl->GetWindowRect(grid\_rect); // problem is here. no grid\_rect coordinates
// grid_rect {top=-32639 bottom=-32483 left=-32709 right=-31884} CRect**
// some adjustments
grid_rect = rect;
grid_rect.left += 16;
grid_rect.top += 150;
grid_rect.bottom -= 300;
grid_rect.right -= 16;pGridCtrl->MoveWindow(grid\_rect);
Where am I going wrong ?
Future Lies in Present. Manmohan Bishnoi
-
I have two views ( CMainView and CMembersView ) in my SDI application. The code below resizes my MFC GridCtrl according to size of app's window when the view is initialized. I get valid values for CRect grid_rect {top=0 bottom=952 left=0 right=1819} in CMainView. But in CMemberView I am having some undesired values.
void CMembersView::OnInitialUpdate()
{CFormView::OnInitialUpdate(); initialized = TRUE; CWnd \*pGridCtrl = this->GetDlgItem(IDC\_MEMBERSGRID); ASSERT(pGridCtrl); // Must exist CRect rect,grid\_rect; CWnd \*pWnd = this->GetOwner(); pWnd->GetClientRect(rect); **pGridCtrl->GetWindowRect(grid\_rect); // problem is here. no grid\_rect coordinates
// grid_rect {top=-32639 bottom=-32483 left=-32709 right=-31884} CRect**
// some adjustments
grid_rect = rect;
grid_rect.left += 16;
grid_rect.top += 150;
grid_rect.bottom -= 300;
grid_rect.right -= 16;pGridCtrl->MoveWindow(grid\_rect);
Where am I going wrong ?
Future Lies in Present. Manmohan Bishnoi
The window size is never specified when you first call pGridCtrl->GetWindowRect(grid_rect); in the OnInitialUpdate. Please write some codelike below in your CMembersView::OnSize
CWnd *pGridCtrl = this->GetDlgItem(IDC_MEMBERSGRID);
ASSERT(pGridCtrl); // Must exist
if ( ::IsWindow(pGridCtrl->GetSafeHwnd()) )
{
pGridCtrl->MoveWindow(..modified on Thursday, August 25, 2011 4:08 AM
-
I have two views ( CMainView and CMembersView ) in my SDI application. The code below resizes my MFC GridCtrl according to size of app's window when the view is initialized. I get valid values for CRect grid_rect {top=0 bottom=952 left=0 right=1819} in CMainView. But in CMemberView I am having some undesired values.
void CMembersView::OnInitialUpdate()
{CFormView::OnInitialUpdate(); initialized = TRUE; CWnd \*pGridCtrl = this->GetDlgItem(IDC\_MEMBERSGRID); ASSERT(pGridCtrl); // Must exist CRect rect,grid\_rect; CWnd \*pWnd = this->GetOwner(); pWnd->GetClientRect(rect); **pGridCtrl->GetWindowRect(grid\_rect); // problem is here. no grid\_rect coordinates
// grid_rect {top=-32639 bottom=-32483 left=-32709 right=-31884} CRect**
// some adjustments
grid_rect = rect;
grid_rect.left += 16;
grid_rect.top += 150;
grid_rect.bottom -= 300;
grid_rect.right -= 16;pGridCtrl->MoveWindow(grid\_rect);
Where am I going wrong ?
Future Lies in Present. Manmohan Bishnoi
-
IIRC GetXXXRect take pointers as parameters. Have you tried with
pGridCtrl->GetWindowRect(**&**grid_rect);
Same comment for the GetClientRect call a few line above.
This is working fine :-
void CMainView::OnInitialUpdate() // CMainView is my application's default view
{
CFormView::OnInitialUpdate();initialized = TRUE; CWnd \*pGridCtrl = GetDlgItem(IDC\_SALEPURCHASEGRIDCTRL); CRect rect,grid\_rect; CWnd \*pWnd = this->GetOwner(); pWnd->GetClientRect(rect); pGridCtrl->GetWindowRect(grid\_rect); // works fine here grid\_rect = rect; grid\_rect.left += 16; grid\_rect.top += 150; grid\_rect.bottom -= 300; grid\_rect.right -= 16; pGridCtrl->MoveWindow(grid\_rect); // GridCtrl is resized properly
.
.
.This is not working properly:-
void CMembersView::OnInitialUpdate()
{CFormView::OnInitialUpdate(); initialized = TRUE; CWnd \*pGridCtrl = this->GetDlgItem(IDC\_MEMBERSGRID); ASSERT(pGridCtrl); // Must exist CRect rect,grid\_rect; CWnd \*pWnd = this->GetOwner(); pWnd->GetClientRect(rect); // Also tried with &rect pGridCtrl->GetWindowRect(grid\_rect); // problem is here. no grid\_rect coordinates. Also tried with &grid\_rect grid\_rect = rect; grid\_rect.left += 16; grid\_rect.top += 150; grid\_rect.bottom -= 300; grid\_rect.right -= 16; pGridCtrl->MoveWindow(&grid\_rect);
.
.
.--------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi
-
The window size is never specified when you first call pGridCtrl->GetWindowRect(grid_rect); in the OnInitialUpdate. Please write some codelike below in your CMembersView::OnSize
CWnd *pGridCtrl = this->GetDlgItem(IDC_MEMBERSGRID);
ASSERT(pGridCtrl); // Must exist
if ( ::IsWindow(pGridCtrl->GetSafeHwnd()) )
{
pGridCtrl->MoveWindow(..modified on Thursday, August 25, 2011 4:08 AM
Doesn't help much.
--------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi
-
This is working fine :-
void CMainView::OnInitialUpdate() // CMainView is my application's default view
{
CFormView::OnInitialUpdate();initialized = TRUE; CWnd \*pGridCtrl = GetDlgItem(IDC\_SALEPURCHASEGRIDCTRL); CRect rect,grid\_rect; CWnd \*pWnd = this->GetOwner(); pWnd->GetClientRect(rect); pGridCtrl->GetWindowRect(grid\_rect); // works fine here grid\_rect = rect; grid\_rect.left += 16; grid\_rect.top += 150; grid\_rect.bottom -= 300; grid\_rect.right -= 16; pGridCtrl->MoveWindow(grid\_rect); // GridCtrl is resized properly
.
.
.This is not working properly:-
void CMembersView::OnInitialUpdate()
{CFormView::OnInitialUpdate(); initialized = TRUE; CWnd \*pGridCtrl = this->GetDlgItem(IDC\_MEMBERSGRID); ASSERT(pGridCtrl); // Must exist CRect rect,grid\_rect; CWnd \*pWnd = this->GetOwner(); pWnd->GetClientRect(rect); // Also tried with &rect pGridCtrl->GetWindowRect(grid\_rect); // problem is here. no grid\_rect coordinates. Also tried with &grid\_rect grid\_rect = rect; grid\_rect.left += 16; grid\_rect.top += 150; grid\_rect.bottom -= 300; grid\_rect.right -= 16; pGridCtrl->MoveWindow(&grid\_rect);
.
.
.--------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi
-
Are the coordinate that should be returned by
GetWindowRect
really null ? What does the debugger says (if you look into thepGridCtrl
structure) ? Have triedGetLastError
?In CMainView :- grid_rect {top=-0 bottom=912 left=0 right=1819} CRect In CMembersView :- grid_rect {top=-32639 bottom=-32483 left=-32709 right=-31884} CRect
--------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi
-
In CMainView :- grid_rect {top=-0 bottom=912 left=0 right=1819} CRect In CMembersView :- grid_rect {top=-32639 bottom=-32483 left=-32709 right=-31884} CRect
--------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi
-
Actually, you are overwriting grid_rect in the next part of the code with the content of rect, making the GetWindowRect call unnecessary. What if you comment out this line
pGridCtrl->GetWindowRect(grid_rect);
? ( just to test if the MoveWindow is accepted).I use it to just test whether grid_rect fetches some values or not. Ok. I comment it out. But still it doesn't help.
--------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi
-
I use it to just test whether grid_rect fetches some values or not. Ok. I comment it out. But still it doesn't help.
--------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi
-
Doesn't help much.
--------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi
I guess you do not catch all my meaning. If you just set the grid position in OnInitialUpdate, then even it works. There still some problem after you resize your application. To make sure it works in all case, you must do it inside OnSize
CMembersView::OnSize:
CWnd *pGridCtrl = this->GetDlgItem(IDC_MEMBERSGRID);
ASSERT(pGridCtrl); // Must exist
if ( ::IsWindow(pGridCtrl->GetSafeHwnd()) )
{
// assume you need to move the grid to the left half of CMembersView
CRect rctClient;
this->GetClientRect(&rctClient);
pGridCtrl->MoveWindow(0, 0, rctClient.Width()/2, rctClient.Height());
}modified on Thursday, August 25, 2011 10:19 AM
-
I guess you do not catch all my meaning. If you just set the grid position in OnInitialUpdate, then even it works. There still some problem after you resize your application. To make sure it works in all case, you must do it inside OnSize
CMembersView::OnSize:
CWnd *pGridCtrl = this->GetDlgItem(IDC_MEMBERSGRID);
ASSERT(pGridCtrl); // Must exist
if ( ::IsWindow(pGridCtrl->GetSafeHwnd()) )
{
// assume you need to move the grid to the left half of CMembersView
CRect rctClient;
this->GetClientRect(&rctClient);
pGridCtrl->MoveWindow(0, 0, rctClient.Width()/2, rctClient.Height());
}modified on Thursday, August 25, 2011 10:19 AM
yes you were right. now code is working. thanks. :thumbsup:
--------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi