Reputation: 65
I'm coding in raw C, using win32.
I want to change at runtime the position of a control (a button) to properly keep its relative position inside the parent dialog, which is resizable. I defined both the dialog and the button via a resource script, where dimensions are in dialog base units.
To change the size at runtime I have to deal with the SetWindowPos function, which accepts values in pixels so, to maintain the original proportions, I need to convert in pixels the original distance (in dialog base units).
I've tried to use the value returned from the GetDialogBaseUnits funcion and follow the "conversion procedure" (which is, substantially, a multiplication and a division) reported in the reference page, using the MulDiv function but what I get is a wrong value... In particular I obtain: LOWORD(GetDialogBaseUnits()) = 8 and HIWORD(GetDialogBaseUnits()) = 16 which, used in MulDiv, produce sizes in dialog base units which are exactly the half of the pixel ones (and this is wrong, in my system).
How I can properly perform this conversion?
Upvotes: 3
Views: 3702
Reputation: 11578
Not with GetDialogBaseUnits().
If you have a dialog box, you can do this easily: use the MapDialogRect()
function.
If you have a regular window, you'll have to do the calculations manually. I've asked a question related to it here and wrote a tool for testing possible calculations. The different calculations are close enough to be equally visually useful; don't stress too hard.
Upvotes: 2