|Looks like CodeProject has changed its formatting resulting in oddities like shown in the Introduction:|
When you change the font of a list view control, the control or its parent window does not get a chance to respecify the height of the rows. NoCan someone please fix the formatting?
WM_MEASUREITEM message is sent to the controls parent window. The net effect is that when the font is changed for the control, the row height is no longer valid.
|1) I have a listctrl with OWNERDRAWFIXED + Extended LVS_EX_CHECKBOXES style|
2) i want to set font of a listctrl
3) handling wm_measureitem
4) Handling onSetFont
Tried everything but doesnt change the row height to the height i want.
|This is what I want, thank you.|
this is such a nice article,
please tell me how can change row height when using checkbox option in listctrl?
thanks in advance.
|Thank you! This is very useful !!! |
Thank you very mush.
The clde project supply us a
new and wonderful communication stage.
If you want to set row height, but do not want to draw items self you may use this:
- Add CListView (CListCtrl) - derived class
- Catch WM_MEASUREITEM by reflection (as described) in your class
- MeasureItem () should set required item height in lpMeasureItemStruct-> itemHeight
- Create view (control) with LVS_OWNERDRAWFIXED style (you may set this style in overrided PreCreateWindow method)
- Override DrawItem () but leave it empty
- Catch WM_CREATE. Reset LVS_OWNERDRAWFIXED there (call "ModifyStyle (LVS_OWNERDRAWFIXED, 0);" in OnCreate () method)
i have a problem with OnSetFont (WPARAM wParam, LPARAM); function,
i cant catch the message WM_WINDOWPOSCHANGED, mean if i use SetFont (newfont);
the execution jumps in OnSetFont () function, but the SendMessage ();
SendMessage (WM_WINDOWPOSCHANGED, 0, reinterpret_cast (& wp));
dont go to MeasureItem () part!
Any suggestions for that problem?
for first: thanks for this good article!
And i have some question, is it posible to set different rowheights,
e.g. all even row with own rowheight and all odd with other row height !?
with best regards
|I have a window that contains 2 owner drawn list controls. Whenever measureitem is called, it is always called on the same control, and the second control never gets the height resized properly. Any ideas how I can force it to resize both controls, and not just one? |
|Can I set the Height of the Header to Constant Values.|
What I am doing wrapping the text in the ListBox according to window size on resize event.
so I am changing the Height of the ListControl so that it fits all the text.
But I want the Header Height of the ListControl to be constant.
|How to set Listbox as hidden?|
i dont know how to create a dyanmic array?
so i decided to use list box?
i dont need this to be show in my dialog area?
can u help me?
|Now riddle me this; why is it that I have to define the WM_FONT message handler again? I'm not trying to change the font. I simply want to change the row height? The author says that we have to do this but how does that help me when I don't have any code that sets the font anyway? How am I going to trigger this whole process programmatically?|
It sure seems like all of the row height changing methods are nothing but fudges. I've seen the one where you setup a blank icon too. Why is it that we have to play such strange games? Doesn't it seem like we ought to be able to change the row height? That seems like a pretty basic thing to ask a list control to do.
|Whenever the font is conceptually changed, the height needs to be recalculated. By using SWP_FRAMECHANGED we can force the height to be recalculated (the problem / bug in the normal list control) anytime a font change occurs. If the height of your list changes on other factors you may not need to override SetFont to do the SWP_FRAMECHANGED but could do it where appropriate.|
Summary: There are no WM_MEASUREITEM's without SWP_FRAMECHANGED and in the example font is what row height is based on so it makes the sensitive change event.
|It seems that this handler has changed. Because I am using visual studio .net 7.0. When I implement the method via the class wizard and change it to ON_WM_MEASUREITEM_REFLECT, the software won't compile.|
// Header file declaration
afx_msg void OnMeasureItem (int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
// C ++ file. message map
// The function definition
void TCS_ListControl :: OnMeasureItem (int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
// TODO: Add your message handler code here and / or call default
CListCtrl :: OnMeasureItem (nIDCtl, lpMeasureItemStruct);
notice the extra argument nIDCtl. I didn't see this in the example. But that is what my Visual Studio .net compiler creates when I create the function in the wizard. What the wizard creates compiles until I add the reflection and then it complains that the function doesn't exist. Then I change
CListCtrl :: OnMeasureItem (nIDCtl, lpMeasureItemStruct); to
void TCS_ListControl :: MeasureItem (int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
and now the compiler complains that the int argument is invalid. What gives? What the heck is going on?
|Any pointers on how this can be done in ListCtrl with large icon view. The DrawItem () is not getting called once the view property for the list control is set to non report view.|
Thanks in advance for your help.
|I am writing an owner drawn combo box which is intended to be filled with names of the fonts in the system the names will be in the font. Just like the font selector in MS Word. In this case the size of font i am using is 12. Will the item height be same for all the items or is it variable. Can u suggest some ideas?|
|Since the height of all items must be the same, you could set the row height to that of the font with the largest height.|