RC modifies the actual size of the dialog

Source: Internet
Author: User

We know that you can use NotePad to open the. RC file, and then change the coordinates to change the dialog box size, such:
The following are RC files //////////////////////////////////// //////////////////////////////////////// //// dialog // idd_aboutbox dialogex 0, 0,170, 62 style ds_setfont | ds_modalframe | ds_fixedsys | ws_popup | ws_caption | ws_sysmenu caption "about server" font 9, "Ms Shell
DLG ", 0, 0, 0x1 begin icon idr_mainframe, idc_static, 1.0, ltext" server, ", idc_static, ss_noprefix ltext" Copyright (c) 2010 ", idc_static, 0,170, defpushbutton" OK ", idok, ws_group end, as long as" idd_aboutbox dialogex 0,
62 "the last two numbers can be changed to the size of the about window.

The size value in the dialog box resource is the unit of the dialog box, which is not a pixel but a dlu (dialog logical
Units), which is a coordinate unit irrelevant to the resolution. The Conversion Relationship between pixels is related to the font of the current dialog box. It is not a pixel. to convert it to a pixel, you can use mapdialogrect to convert it. If you want to manually calculate, use the following algorithm:
  Pixelx = muldiv (dialogx, basic horizontal unit of the dialog box, 4)
  Pixely = muldiv (dialogy, basic vertical unit of the dialog box, 8)
 
The dialoglayout class is a simple layout manager used to work with the dialog logical unit (dialog logical units = dlu) in Win32 API. The logical unit of the dialog box is the coordinate unit irrelevant to the resolution. It is useful for the control part arrangement in the dialog box. There is a ing from dlu to pixels. This ing is based on the font used in the dialog box. The X-direction coordinate unit of a dlu is equivalent to 1/4 of the average width of the font used in the dialog box, and the Y-direction coordinate unit is equivalent to 1/8 of the font height used in the dialog box. Note that the average font width is calculated not by the average of all characters, but by the letter... The average width of Z (including uppercase). In other words, it is equal to the string "... Za... The length of Z is divided by 52.
When Visual Studio 6.0 (Visual C ++ 6.0) is used for development, the size of the control in the dialog box in the resource editor and its actual pixel size are very annoying. Especially when the control size of the dialog box is required to change with the screen resolution or the size of the program window, it is even more scratching the head. The reason is that the correspondence between the unit (dlu) in the resource editor and the screen pixel changes with the change of the font type and size of the dialog box. (1) in the horizontal direction 1 dlu = 1/4 average font width; (2) in the vertical direction 1 dlu = 1/8 average font height. This relationship is difficult to determine due to the changing fonts used. In most cases, the dlu calculated using the above formula is not even an integer pixel. In order to better grasp the pixel size of the widget on the screen during the resource editor editing process, according to (1), train of thought: the same width font should be used in the dialog box resource editor; according to (2), the idea is: it is best to use the so-called "system" font, so that the font height is fixed. Verify: Open "dialog properties" in the resource editor of the dialog box, click "font...", and select a font for the dialog box. The following two types of fonts are available: fixedsys and system. First, they are obtained through online search. Second, the two types of fonts have only one size: 12 ", this indicates that the font height is fixed. In the field test, in the VC dialog box project, change the font of the dialog box to "fixedsys" or "system", and change the font size to "12 (small 4 )", create a 100*100 dlu button in the dialog box. Click the button in the Response Function and use getwindowrect () or getclientrect () to obtain the button size. Set breakpoint debugging Observation Result: The pixel size of the button is 200*200! This indicates that 1 dlu in the dialog box resource editor is now equal to 2 pixels. This makes our design much easier. What if the screen resolution changes? The test results are the same on different monitors, and the result is still 1 dlu = 2 pixels. Is there any other font that has such an effect? The "terminal" font can also be selected. The font size is 12, and the test result is also horizontal/vertical direction 1 dlu = 2 pixels. However, there is a problem: the dialog box with the font selected looks strange in the resource editor. the horizontal direction 1 dlu and the vertical direction 1 dlu have different lengths, as if they were squashed. But the program runs normally. In addition, if you select different "terminal" font sizes, the corresponding relationship will also change. By now, we have tested several other commonly used fonts and found that verdana and have a better effect (although they are not same-width fonts for English. For Chinese characters, generally, the font of Chinese characters is of equal width ). Below are the test results (still tested with a 100*100 button): Font/font size/horizontal size/vertical size verdana/8/175/163      /9/200/175      /10/200/200       /11/225/225      /12/250/225/8/150/138   /9/150/150   /10/175/163   /11/200/188   /12/200/200Conclusion 1: If you are not satisfied with the fixedsys and system fonts, it is better to use the 12-character /10-character verdana. Conclusion 2: although only several limited fonts can be used, but it can bring some convenience to programming and is worth it (the loss of the font effect)
 
 
 
From: http://blog.sina.com.cn/s/blog_4dd787e401017vhj.html

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.