Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginner Programmer : Coordinates Conversion Issues : Pls Help 1

Status
Not open for further replies.

cdgios

Technical User
Jul 17, 2002
40
US
Hi I am creating an application in which a dialog box displays the contents of registers of some device in the binary format. I have ctreated some of the child window controls (edit controls) via the resource editor in Visual C++. And and I am trying to create a few more at run time (when processing the WM_INITDIALOG message). At run time, when i use the function GetWindowRect()/ GetClientRect() function to get the position of an edit control that i created using the resource editor, i get values different than what i see in the resource file (.RC file). For example, the x and y coordinates of an edit control in the .RC file is (50, 42). The x & y coordinates for the same control when i use the function getWindowRect (inorder to get the position of the child window with respect to the client area of the parent window) are (163, 221). I figure that the units must be different? I want to know what units are being used in both cases and what the convesion factor should be if I am creating more edit controls at run time that need to be aligned with the already created control through the resource editor.

Thanks
Best Regards
Chandra
 
Hi, the measurements are in pixels. You can use the CWnd class member functions 'ScreenToClient()' and 'ClientToScreen()' to convert between the two.
 
Thanks qednick! I had not seen this fonction before you mentioned it (maybe I was not looking hard enough ;-), and it really makes my code for moving controls around soooo much simpler!

Vincent
 
No Probs Vincent.... we all learn the hard way! Now, whenever I'm playing with a new VC++ class for the first time, I make sure to read through all the member functions first so I know what I can do with the class.
As an example, if I ever wanted to search a CString string for a particular character, I used to write my own 'for' loops to check each character in the string. Then I discovered a [previously overlooked] member function that does that for me!
 
Hello Gednick, thanks for your reply. I agree and understand that the 'ScreenToClient()' and 'ClientToScreen() functions can convert between the Screen and Client coordinates in pixels. The problem is that, When I create resources via the resource editor, the resource editor creates entries in the resource script file (.RC) for each control/window. The numbers that entered in the resource script file by the editor for the position and size of the controls are entirely different that what i get
when i call GetClientRect() or GetWindowRect() for the same controls. Now i realize that the values returned by those two functions are in screen coordinates and i have converted them to client coordinates callinf ScreenTClient (). Now the values returned from GetClientRect()/GetWindowRect() or their equivalent client coordinates are totaaly different than the entries that i find in the resource script. So, I am trying to understand in what coordinates and units does the resource editor enter values for position and size of controls in the resource script.

Thankyou very much for your help
Best Regards
Chandra
 
the coordinates stored in the .RC file are probably the same as the ones the Dialog Editor uses. Here is what the MSDN help file has to say:

"The location and size of a dialog box, as well as the location and size of controls within it, are measured in dialog units (DLUs). A DLU is based on the size of the dialog box font, normally 8-point MS Sans Serif. A horizontal DLU is the average width of the dialog box divided by four. A vertical DLU is the average height of the font divided by eight."

Maddeningly absurd, if you ask me, but that's the way it is.

Vincent
 
Yeppers - I agree!! If only these things were all mapped in the same coordinate system - life would be so much more easier!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top