How to get the (text size or height) of the titlebar.
I tried to use GetSystemMetrics(SM_CYCAPTION) but it returns the height of the titlebar not the text size.
Any suggestions?
Call SystemParametersInfo passing SPI_GETNONCLIENTMETRICS. This will populate a NONCLIENTMETRICS structure. Within that structure is lfCaptionFont which contains the information you desire.
Related
I am using a combobox control to show names stored in a database ( I need to preserve space, that is why I use it instead of a listview, for example ).
My problem is that sometimes text is longer than the combobox so part of it can not be seen.
Is there a way to resize combobox' listbox so it can entirely show text, or at least to enable some kind of horizontal scrolling so the user can scroll to see the entire text?
Looking through combobox documentation, I haven't found any style that can solve my problem. Trying to add WS_HSCROLL as a style in my CreateWindowEx call didn't help either.
Thank you.
You are looking for the CB_SETHORIZONTALEXTENT message.
An application sends the CB_SETHORIZONTALEXTENT message to set the width, in pixels, by which a list box can be scrolled horizontally (the scrollable width). If the width of the list box is smaller than this value, the horizontal scroll bar horizontally scrolls items in the list box. If the width of the list box is equal to or greater than this value, the horizontal scroll bar is hidden or, if the combo box has the CBS_DISABLENOSCROLL style, disabled.
Parameters
wParam
Specifies the scrollable width of the list box, in pixels
lParam
This parameter is not used.
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 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.
If I create a full screen window where m_winw and m_winh is the full screen size, it seems to create a window for me where the outside dimension is the full screen and the inside is smaller based on the "decoration" (window border) size. Is there a way to query the window to get it's inside width and height?
m_win=XCreateWindow(m_display, m_rootwin, m_winx, m_winy, m_winw, m_winh, 0,
CopyFromParent,CopyFromParent,m_visual,CWColormap|CWEventMask,&attributes);
This is on linux.
See XGetWindowAttributes, XGetGeometry. According to the man page:
The width and height members are set tothe inside size of the window, not including the border.
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