Change the size of a window based on the length of the text string

Source: Internet
Author: User

Ask a question:

Based on the contents of the text file, the control is dynamically created with Cwin subclasses. In the Create method, all controls are created with the following code, based on the message text font selected by the user in the Display Properties dialog box:

Nonclientmetrics NCM;

ncm.cbsize = sizeof (nonclientmetrics);

SystemParametersInfo (spi_getnonclientmetrics, sizeof (NCM), &NCM, 0);

M_defaultfont.createfontindirect (&ncm.lfmessagefont);

After you get the font, the next question is how to determine the height and width of the static control to display the full text?

The first thing to be clear is that the Display Properties dialog box is right-click on the desktop, select the Properties menu item, and then select the dialog box (figure I) that appears in the Appearance property page.

Figure I

The user can select the active window, the message box, and the color and font of the text in this dialog box. You can call the SystemParametersInfo function and use Spi_getnonclientmetrics as the first parameter to find out what font the user has chosen; systemparametersinfo function to fill in the nonclientmetrics structure with the information you need:

// NONCLIENTMETRICS 结构(winuser.h)
//
struct NONCLIENTMETRICS
{
UINT cbSize;
int iBorderWidth;
int iScrollWidth;
int iScrollHeight;
int iCaptionWidth;
int iCaptionHeight;
LOGFONT lfCaptionFont;
int iSmCaptionWidth;
int iSmCaptionHeight;
LOGFONT lfSmCaptionFont;
int iMenuWidth;
int iMenuHeight;
LOGFONT lfMenuFont;
LOGFONT lfStatusFont;
LOGFONT lfMessageFont;
};

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.