moving controls on a dialog dynamically
-
Hi, I have a dialog based application on which I have a tab control made of dialogs. On the tab pages I have some controls. I want to move some of these controls dynamically. The control's start coordinates seen from the resource view are (7,3), which should be seen as left:7,top:3 from a CRect type. I see some strange behaviour with the below codes (called from CTab1Dlg class member functions): Test 1:
CRect rect; GetDlgItem(IDC_STAT1)->GetClientRect(&rect); // start point is (0,0) here GetDlgItem(IDC_STAT1)->MoveWindow(&rect); UpdateData(false);
afterwards the control moves to the left and upwards. Test 2: If I put this line before MoveWindow() line above, then the control still moves to left and upwards, but this time a little.rect.OffsetRect(7,3);
Test 3: If I change the inputs to (11,5), then the position does not change:rect.OffsetRect(11,5);
Test 4: If I try to get the coordinates of the tab's dialog then I get an access violation when i try to reach its members:GetDlgItem(IDD_TAB1)->GetClientRect(&rect);
I want to shift the controls upwards and downwards dynamically. How can I get the correct initial coordinates? thanks in advance -
Hi, I have a dialog based application on which I have a tab control made of dialogs. On the tab pages I have some controls. I want to move some of these controls dynamically. The control's start coordinates seen from the resource view are (7,3), which should be seen as left:7,top:3 from a CRect type. I see some strange behaviour with the below codes (called from CTab1Dlg class member functions): Test 1:
CRect rect; GetDlgItem(IDC_STAT1)->GetClientRect(&rect); // start point is (0,0) here GetDlgItem(IDC_STAT1)->MoveWindow(&rect); UpdateData(false);
afterwards the control moves to the left and upwards. Test 2: If I put this line before MoveWindow() line above, then the control still moves to left and upwards, but this time a little.rect.OffsetRect(7,3);
Test 3: If I change the inputs to (11,5), then the position does not change:rect.OffsetRect(11,5);
Test 4: If I try to get the coordinates of the tab's dialog then I get an access violation when i try to reach its members:GetDlgItem(IDD_TAB1)->GetClientRect(&rect);
I want to shift the controls upwards and downwards dynamically. How can I get the correct initial coordinates? thanks in advanceThere is some mixing of terminology going on here. The resource view coords (7,3) are in dialog coordinates. The relationship between these and pixel coords varies depending on DPI. This the big / small fonts in the display control panel. Taking Test1:
GetDlgItem(IDC_STAT1)->GetClientRect(&rect);
This returns the client coordinates which *always* starts at (0,0) for its top left. These are relative to IDC_STAT1. You want:
GetDlgItem(IDC_STAT1)->GetWindowRect(&rect);
ScreenToClient (&rect);instead. Test2: This shows that dialog and screen coords are not the same thing. Test3: You've experimentally found the result of
MapDialogRect
function. But be careful. The results will change on a high resolution screen, where someone has chosen larger fonts. This used to be rare, but these days you can get very high res laptop displays. Test4: You haven't provided enough information for this. Again, you are using GetClientRect instead of GetWindowRect / ScreenToClient. Dies GetDlgItem (IDD_TAB1) work? Or does it return NULL? I hope this puts you on the right path, Iain. -
There is some mixing of terminology going on here. The resource view coords (7,3) are in dialog coordinates. The relationship between these and pixel coords varies depending on DPI. This the big / small fonts in the display control panel. Taking Test1:
GetDlgItem(IDC_STAT1)->GetClientRect(&rect);
This returns the client coordinates which *always* starts at (0,0) for its top left. These are relative to IDC_STAT1. You want:
GetDlgItem(IDC_STAT1)->GetWindowRect(&rect);
ScreenToClient (&rect);instead. Test2: This shows that dialog and screen coords are not the same thing. Test3: You've experimentally found the result of
MapDialogRect
function. But be careful. The results will change on a high resolution screen, where someone has chosen larger fonts. This used to be rare, but these days you can get very high res laptop displays. Test4: You haven't provided enough information for this. Again, you are using GetClientRect instead of GetWindowRect / ScreenToClient. Dies GetDlgItem (IDD_TAB1) work? Or does it return NULL? I hope this puts you on the right path, Iain. -
Hi, I have a dialog based application on which I have a tab control made of dialogs. On the tab pages I have some controls. I want to move some of these controls dynamically. The control's start coordinates seen from the resource view are (7,3), which should be seen as left:7,top:3 from a CRect type. I see some strange behaviour with the below codes (called from CTab1Dlg class member functions): Test 1:
CRect rect; GetDlgItem(IDC_STAT1)->GetClientRect(&rect); // start point is (0,0) here GetDlgItem(IDC_STAT1)->MoveWindow(&rect); UpdateData(false);
afterwards the control moves to the left and upwards. Test 2: If I put this line before MoveWindow() line above, then the control still moves to left and upwards, but this time a little.rect.OffsetRect(7,3);
Test 3: If I change the inputs to (11,5), then the position does not change:rect.OffsetRect(11,5);
Test 4: If I try to get the coordinates of the tab's dialog then I get an access violation when i try to reach its members:GetDlgItem(IDD_TAB1)->GetClientRect(&rect);
I want to shift the controls upwards and downwards dynamically. How can I get the correct initial coordinates? thanks in advanceSee the "Extras" section of this article.
"Take only what you need and leave the land as you found it." - Native American Proverb
-
See the "Extras" section of this article.
"Take only what you need and leave the land as you found it." - Native American Proverb