Cooker
Cooker

Reputation: 441

Dialog box units to screen coordinates

Someone can explain me how to convert dialog box units to screen coordinates values ? I saw that there is MapDialogRect function, but its converting RECT, i want to convert the x,y and cx,cy values to screen coordinate values and i dont really understand how to achieve this.

Thanks in advance.

Upvotes: 1

Views: 3039

Answers (1)

Raymond Chen
Raymond Chen

Reputation: 45173

If you already have a window handle, then just use the MapDialogRect function. As others have noted, MapDialogRect takes a RECT, so if you don't have a RECT, you can create one.

RECT rc;
rc.left = x;
rc.top = y;
rc.right = x + cx;
rc.bottom = y + cy;
MapDialogRect(hdlg, &rc);

If your problem is that you don't have a dialog box handle in the first place, then the documentation for the MapDialogRect function tells you how to perform the calculations: Determine the the average character dimensions for the dialog box (which the documentation calls baseunitX and baseunitY) and then plug it into the formulas.

Note that this calculates the client rectangle of the dialog box. You still have to add non-client space. It's not clear what you're trying to do, so I don't know whether adding non-client space is appropriate or not.

Upvotes: 7

Related Questions