Conversion between the size and pixels of the VC Control

Source: Internet
Author: User

Function: This function returns the basic unit of the system dialogue, which is the average width and height of the system font characters. For the dialog box that uses the system font, you can use these values to convert between the dialog box template, for example, between the dialog box template and pixel. For a dialog box that does not use the system font, the conversion from the unit of the dialog box template to the pixel depends on the font used in the dialog box. The MaPDialogRect function is used to easily convert one type of dialog box. MaPDialogRect considers the font and correctly converts the unit of a rectangle template to this pixel.

Function prototype: LONG GetDialogBaseUnits (VOID );

Parameter: none.

Return Value: the return value is a 32-bit value containing the basic unit of the conversation. The low-level characters returned contain the basic unit of the horizontal dialog box, and the high-level characters contain the basic unit of the vertical dialog box.

Note: The basic horizontal unit returned by the GetDialogBaseUnits function is the same as the average width of Characters in the system font in pixels. The basic vertical unit is the same as the average height of Characters in the system font in pixels; the basic unit of a dialog box that does not use the system font is equal to the average width and average height of the dialog box font characters in pixels. You can use the GetTextMetrics and GetTextExtentPoint32 functions to calculate these values for a selected font. However, if the calculation result is different from those executed by the system, you can use the MapDialogRect function to avoid possible errors. Each horizontal basic unit is the same as the four horizontal dialog box template units. Each Vertical Basic Unit is the same as the eight vertical dialog box template units. Therefore, use the following formula to convert the template unit of the dialog box to pixels:

PiselX = (temptateunitX★BaseunitX)/4; PiseIY = (templateunitY★BaseunitY)/8

Similarly, the following formula is used to convert pixels into dialog box template units: templateunitX = (pixelX★4)/baseunitX; templateunitY = (plxelY★8)/baseunitY

Windows CE: Windows CE does not support any extended error value of this function.

Quick query: Windows NT: 3.1 and later; Windows: 95 and later; Windows: 1.0 and later; header file: Winuser. h; library file: user32.lib

 

The above method is not successful at last, and then the ratio between them is calculated through fine-tuning:

VC6.0:

Control width/pixel width = 4/7

Control height/pixel height = 2/3

VS2005:

Control width/pixel width = 2/3

Control height/pixel height = 3/5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.