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.
Related
I have a list control. I want to draw selection rectangle on my own.
For example: when i clicked on an item it will draw an selection ractangle on that item and the item is next to it (or can be somewhere else).
Can anybody tell me how to do that ?
Thank you!
To draw a focus rectangle, call the DrawFocusRect function. To enable Visual Styles, call the DrawThemeBackground function (Parts and States: LBCP_ITEM and LBPSI_SELECTED).
Either way, you will have to create an owner-drawn List Box to be able to adjust rendering. For an MFC CListBox control you have to override at least CListBox::DrawItem (and usually also CListBox::MeasureItem).
When a ListView item is selected, its color changes to indicate that it is selected. Now what I want to do is to disable this visual effect and implement my own, so for example I want when an item is selected to draw a rectangle around the item.
How can I do that? (Note that I am talking about the Icon view).
This is a case for custom drawing of controls.
It's all about handling the NM_CUSTOMDRAW notification and then to draw the control more or less by yourself.
I've never done it by myself changing the appearance seriously but I've change background colors of controls using this mechanism.
There is a lot of information about this on the internet...
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'd like to draw a color "frame" within a QT window. So, I have
setFixedSize(WIDTH, HEIGHT);
and I'd like to draw, say, a red (filled) border within width and height. Could anyone help me out?
Depends on a couple of things:
Is it a border around an existing widget? If it's just a border around an existing widget don't go down the route of painting it yourself, it's much simpler to use Stylesheets than draw it.
If of course you need a custom or very specific style, then you're best off drawing it using the Painting System. I'd strongly suggest do it using stylesheets unless you do need specifics. The paint system can be a bit unwieldy for just adding a border to a widget.
I am trying to create a custom control that displays a bitmap with per-pixel alphablend (as some of you already know for other questions).
Right now I am using a custom control in the resource editor and I attach it to a class derived from CWnd. When I register my custom class I set the hbrBackground of the WNDCLASS structe to NULL_BRUSH to achive the transparency of the control.
In the OnPaint of the control I use AlphaBlend to paint the per-pixel alpha blend bitmap.
This works quite well but I have this two problems:
I want to change the displayed bitmap when the mouse is over the control. As the control is transparent, the areas that one bitmap that are not overlapped by the other bitmap are not erased. How can I erase the background when the image is changed?
The second problem is related with two overlapping controls. My control is painted over other control that has a gradient (in fact is inside other control). The problem is that if I put my control before in the z-order the other controls overlap my control and mine is not displayed. If I put the other control before in the z-order I can not get the mouse message in my control.
Maybe I am doing something wrong or I am wrong in how I am trying to implement my control. Any kind of help would be appreciated.
Thanks,
Javier
I'll take a chance. :-)
This should give you all you need to accomplish what I think you want.
General Solution for Transparent Controls
As far as Z-order issues, the z-order does not affect message priority. You'll need to post some code so we can determine what is happening there.