The dialog contains the static text control. When intializing the dialog the application sets a custom text to this static text control:
HWND hWnd = GetDlgItem(IDC_MY_STATIC_TEXT);
::SetWindowText(hWnd, szMyCustomText);
I need to know the number of the lines that the specified text will be broken into and this text width when it is displayed in UI. Could you please share your idea?
This will depend on the font, DPI and other settings. I recommend looking up static text controls which says:
The system displays as much text as it can in the static control and clips whatever does not fit. To calculate an appropriate size for the control, retrieve the font metrics for the text. For more information about fonts and font metrics, see Fonts and Text.
Combined with this post about calculating the size of the resulting text should get you on your way to calculating the text width (and with knowledge of the text height the number of lines).
Related
I am having a static control in which I am setting some text. When I am trying to set lengthy text in the static control the text is getting clipped.
Can anyone please let me know, how can I prevent the text from getting clipped.
The problem is that a static control always clips a word, that is longer than the width of the control. If you use the SS_LEFT style words are wrapped into the next line. So a higher control would help (I can read in the comments that this is possible).
But the Style must be SSLEFT and not SS_LEFTNOWRAP!
Another solution would be to use a Read Only Edit control without a border In this case you can scroll inside the edit control, because it is possible to give it the focus. Also you are able to use a vertical or horizontal scrollbar.
As long as you don't use WS_TABSTOP you will se no real difference between a read only edit control without a border and a static control. Except that the edit control can be activated with the mouse.
Make the static text control larger than the text you a putting in it. A window draws in its client and non-client space. It clips to its window.
If you're concerned about space on a dialog or form, or, language translation could be a possible issue, then you should consider using a CStatic tool tip. Using a tool tip would allow you to keep the current size for the control and provide a mechanism to display its full text. When the user mouses over the CStatic, a tool tip pops up to display the entire text. It's a compromise I've had to use to balance UI design with space on a dialog.
I'm using SetIconSpacing() in my CListCtrl icon view and the spacing is fine except I'm also displaying the image name under the image. Right now I'm forcing the spacing to m_ctrlList.SetIconSpacing(CSize(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT+20)); where the 20 represents the text height. Is there a way to get the text height from the control?
I'm using the standard control, no funny biz.
Many thanks
You can use GetTextExtentPoint32() function. Here's what you have to do.
Use/Create any DeviceContext(CClientDC is best).
Get the font from the CListCtrl and assign the font to dc using SelectObject() function.
Now use GetTextExtentPoint32() function and get the font height.
Now set the old font back to dc.
That's it.
I am creating a MFC CDialog and adding a bitmap in a picture control and I have edit controls that need to be placed relative to positions on the image. However the size of the image in the picture control changes when I run my application.
This makes it difficult to align my edit boxes with the image.
Can anybody tell me why this happens?
There is no code to post as this is entirely done in the dialog editor of VS2013.
Windows adjusts the size of dialogs to match the system font, which can be changed by the user. For information about this look up dialog base units. If you need your dialog layout to match a bitmap then you need to override the Windows adjustment and explicitly set the size and location of the controls at run time. That would mean that in OnInitDialog you use MoveWindow on the dialog itself and on every control to set their size and location in pixel units that match the bitmap.
I want to display HTML text inside a RECT structure within a win32 window. I have found a lot of APIs which helps me render HTML in a separate window, but my requirement is that we dont have to assign a separate window handle for the HTML being displayed.
The RECT structure is basically two points representing a rectangle, as documented here. You can't store any other kind of information inside of a RECT.
Perhaps what you need to do requires creating an EDITTEXT control, described here and use it display the HTML as text. You can use the values from the RECT to define the x, y, width and height parameters of the EDITTEXT.
In a Win32 GUI application I need to determine the width of area occupied by a string on a toolbar button so that I adjust the button width accordingly. The toolbar is plain old ToolbarWindow32 windows class. I use the following code:
HDC dc = GetDC( toolbarWindowHandle );
SIZE size;
GetTextExtentPoint32( dc, stringToMeasure, tcslen(stringToMeasure), &size );
For some fixed string (say "Hello") size.cx is filled with say 72 but when I make a screenshot of the toolbar with the very same string displayed on a button I see that the string occupies say 56 pixels.
The difference clearly depends on system fonts settings. I use "large fonts" and the value obtained by code is bigger than what is occupied on screen. On machines with "small fonts" the value obtained is smaller.
I thought if I use GetTextExtentPoint32() on a window device context it will return exactly the right size. What am I doing wrong?
The font used by the toolbar won't be selected into the DC so you'll need to work out what font it is using, create a copy, select it into the DC, get the size and then select the font out (else you could end up with a resource leak). You will currently be getting the size of the system font I expect, or whatever the default DC font is.
You could try finding the font handle used by sending a WM_GETFONT message to the toolbar window but this isn't guaranteed to return the actual font used when the text is displayed. It all depends on how the toolbar works internally.
However I'm pretty sure that the Win32 toolbar uses the menu font for rendering button text, which can be discovered using a combination of SystemParametersInfo and the NONCLIENTMETRICS structure.
If I was at work I'd post some code.
Don't you just love Win32?
BTW, I use the toolbar button text feature and have never had to size the button by hand in this way.
http://msdn.microsoft.com/en-us/library/ms724947(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms724506(VS.85).asp