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.
Related
I have created some (CMFCToolBar) toolbars and added buttons and icons to them. I read on Microsoft's official website that CMFCToolBar takes 23x22 button size and 16x15 icon size (ref: link).
If I use 16x15 for the icons, then icons appear blurry. This is because the icons are originally with size 16x16. I used the function SetSizes(CSize (23,23), CSize(16,16)) to change icon size but the icons do not appear right:
Is there another way to set icon and button size?
Update
I called the SetSize function before create toolbar but the icon still appear a little blurry:
I want to know if there is a way to set Icon/button Transparent or make it clear like we can set toolbar transparent through TBSTYLE_TRANSPARENT in CreateEx function.
SetSizes is a static function that affects the complete library.
It should be called before you create any toolbar or menu object.
Best location is in InitInstance of you applicxation.
But my tipp: Use the sizes that are recommended! 16x15 and 23x22....
Transparency can be done with standard 32bit RGB/A bitmaps.
If you have a 16 color bitmap you should use RGB(192,192,192) as the standard color for the background. It is automatically replaced with the needed background color.
This has been answered here too.
I need a dialog box where I can choose colour, font format, font style, and font size. I mean using wxWidgets (need a dialog with wxColourDialog and wxFontDialog in a same dialog box).
Notice that under Windows the native font selection dialog already allows you to select the font colour too. This is not the case under the other platforms however, so you would need to use the non-native, and hence ugly, wxGenericFontDialog there if you really need to select both at once.
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).
I have implemented custom draw for an CTreeCtrl in my MFC Smart Device program. I have successfully changed the color of specific nodes of the CTreeCtrl. I am now trying to understand how to get the default font used to draw text in the control so I can add a strike-through to the font for certain nodes. How would I go about getting the default font used to draw text in the CTreeCtrl and apply a font strike-through to the font?
Use GetFont() to get the font of the control. Strike-through can't be done with ::DrawText AFAIK, but it's easy to just add a GoTo()/LineTo(). You can use GetTextExtent() to get the size of the bounding rectangle and derive the left/right of the strike through line from that.
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