prob with coordinates
-
I'm coding with VC++2008. When designing the layout of the controls in the .rc file, we can see their coordinates in the bottomright of the screen. And now I have a control with (4,30) shown there and another one with (5,156). Then I wanna draw a line between these 2 controls using the coordinates by GDI.
pDC->MoveTo(4,30); pDC->LineTo(5,156);
But at runtime, the line doesn't correspond to those coordinates. I mean there is a big offset from the expected position. What's wrong? Thx in advance.
-
I'm coding with VC++2008. When designing the layout of the controls in the .rc file, we can see their coordinates in the bottomright of the screen. And now I have a control with (4,30) shown there and another one with (5,156). Then I wanna draw a line between these 2 controls using the coordinates by GDI.
pDC->MoveTo(4,30); pDC->LineTo(5,156);
But at runtime, the line doesn't correspond to those coordinates. I mean there is a big offset from the expected position. What's wrong? Thx in advance.
Units in the resource editor are in DLU ( Dialog (il)Logical Unit); they are used to handle the large font/small font display settings. from msdn : dialog unit A unit of horizontal or vertical distance within a dialog box. A horizontal DLU is the average width of the current dialog-box font divided by 4. A vertical DLU is the average height of the current dialog-box font divided by M.
Watched code never compiles.
-
Units in the resource editor are in DLU ( Dialog (il)Logical Unit); they are used to handle the large font/small font display settings. from msdn : dialog unit A unit of horizontal or vertical distance within a dialog box. A horizontal DLU is the average width of the current dialog-box font divided by 4. A vertical DLU is the average height of the current dialog-box font divided by M.
Watched code never compiles.
-
I'm coding with VC++2008. When designing the layout of the controls in the .rc file, we can see their coordinates in the bottomright of the screen. And now I have a control with (4,30) shown there and another one with (5,156). Then I wanna draw a line between these 2 controls using the coordinates by GDI.
pDC->MoveTo(4,30); pDC->LineTo(5,156);
But at runtime, the line doesn't correspond to those coordinates. I mean there is a big offset from the expected position. What's wrong? Thx in advance.
if you want to draw a line between two controls, the safest way is to get the controls' actual on-screen positions, something like:
CRect r1, r2;
ctrl1.GetWindowRect(&r1);
ScreenToClient(r1);ctrl2.GetWindowRect(&r2);
ScreenToClient(r2);dc.MoveTo(r1.right, r1.top);
dc.LineTo(r2.left, r2.top); -
if you want to draw a line between two controls, the safest way is to get the controls' actual on-screen positions, something like:
CRect r1, r2;
ctrl1.GetWindowRect(&r1);
ScreenToClient(r1);ctrl2.GetWindowRect(&r2);
ScreenToClient(r2);dc.MoveTo(r1.right, r1.top);
dc.LineTo(r2.left, r2.top);