15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


ClistBox - MeasureItem Message

Raja Segar -- rsz@pc.jaring.my
Friday, October 04, 1996

Environment: Win95, Visual C++ 4.0

I just want to clarify some thing.. Correct me if i'm wrong:-
 a) If a CListBox has the style OwnerDrawFixed it is supposed to receive
    MeasureIitem message once. 
 b) If a CListBox has the style OwnerDrawVariable it receives
    MeasureItem message for every entry in the list box.

My problem is when the style is OwnerDrawFixed I can't get MeasureItem
at all but when it's OwnerDrawVariable the MeassageItem handler get hit
everytime a entry is added which is what is expected.

Am i missing something here regarding the OwnerDrawFixed Style
Please Help if Possible.
Bye & thanks in advance.
 (  _ \/ __)(_   )
  )   /\__ \ / /_ 
 (_)\_)(___/(____)@pc.jaring.my




Gerry Sweeney -- gerry@hornbill.com
Monday, October 07, 1996


Environment: Win95, Visual C++ 4.0

I have just found this in the MFC Help..

<---------- snip ---------->
For self-drawing list boxes and combo boxes, you must override MeasureItem 
and DrawItem. You must specify the OWNERDRAWVARIABLE style in the dialog 
template (LBS_OWNERDRAWVARIABLE and CBS_OWNERDRAWVARIABLE respectively). The 
OWNERDRAWFIXED style will not work with self-drawing items since the fixed 
item height is determined before self-drawing controls are attached to the 
list box. (The Win 3.1 member functions CListBox::SetItemHeight and 
CComboBox::SetItemHeight can be used to get around this limitation.)
<--------- snip ----------->

Even with this documentation I find this hard to believe. In an app I have 
(log file viewer) written using MFC for NT 3.51 & 95. I have a view class 
which creates a CListBox with the following styles:-

if(!m_listBox.Create(
WS_CHILD |
WS_VISIBLE |
WS_VSCROLL |
LBS_NOTIFY |
LBS_OWNERDRAWFIXED |
LBS_NOINTEGRALHEIGHT, r, this, 5000))

In this app, 'OnMeasureItem' gets called once and once only when the list 
box is created.

I have another application which is a 16bit app using VCv1.52 and this has a 
dialog box with three owner drawn listboxes. Again these have the 
OWNERDRAWFIXED style. See the Dilaog resource below:-

IDD_HDMAILADDRDLG DIALOG DISCARDABLE  30, 40, 285, 154
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Maill Address Book"
FONT 8, "MS Sans Serif"
BEGIN
    EDITTEXT        IDC_SEARCH,5,12,114,12,ES_AUTOHSCROLL
    LISTBOX         IDC_ADDRESSLIST,5,39,114,91,LBS_SORT |
                    LBS_OWNERDRAWFIXED | LBS_HASSTRINGS |
                    LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
    PUSHBUTTON      "Details",IDC_DETAILS,5,135,40,15
    PUSHBUTTON      "To ->",IDC_ADDTOLIST,124,38,36,13
    PUSHBUTTON      "Remove",IDC_REMOVETO,124,52,36,13
    LISTBOX         IDC_TOLIST,165,39,114,41,LBS_SORT | LBS_OWNERDRAWFIXED | 

                    LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | WS_VSCROLL |
                    WS_TABSTOP
    PUSHBUTTON      "Cc ->",IDC_ADDCCLIST,124,87,36,13
    PUSHBUTTON      "Remove",IDC_REMOVEFROM,124,101,36,13
    LISTBOX         IDC_CCLIST,165,88,114,41,LBS_SORT | LBS_OWNERDRAWFIXED | 

                    LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | WS_VSCROLL |
                    WS_TABSTOP
    PUSHBUTTON      "Cancel",IDCANCEL,198,135,40,15
    DEFPUSHBUTTON   "OK",IDOK,240,135,40,15
    LTEXT           "Mail Address List",IDC_STATIC,5,29,80,8
    LTEXT           "Search",IDC_STATIC,5,3,113,8
END

In this instance the 'OnMeasureItem' member of the DialogBox class gets 
called three times. One for each list box as the dialog box is created.

Armed with my debuger and working code I have proved this and I can only 
assume that the snipet of help file above is wrong.


Hope this helps.

Gerry Sweeney
Hornbill Systems Ltd
 -----------------------------------------------------------------
>I just want to clarify some thing.. Correct me if i'm wrong:-
> a) If a CListBox has the style OwnerDrawFixed it is supposed to receive
>    MeasureIitem message once.
> b) If a CListBox has the style OwnerDrawVariable it receives
>    MeasureItem message for every entry in the list box.

>My problem is when the style is OwnerDrawFixed I can't get MeasureItem
>at all but when it's OwnerDrawVariable the MeassageItem handler get hit
>everytime a entry is added which is what is expected.

>Am i missing something here regarding the OwnerDrawFixed Style
>Please Help if Possible.
>Bye & thanks in advance.
>(  _ \/ __)(_   )
> )   /\__ \ / /_
> (_)\_)(___/(____)@pc.jaring.my




C. Zhang -- cz17309@goodnet.com
Tuesday, October 08, 1996

Gerry Sweeney wrote:
> 
> Environment: Win95, Visual C++ 4.0
> 
> I have just found this in the MFC Help..
> 
> <---------- snip ---------->
> For self-drawing list boxes and combo boxes, you must override MeasureItem
> and DrawItem. You must specify the OWNERDRAWVARIABLE style in the dialog
> template (LBS_OWNERDRAWVARIABLE and CBS_OWNERDRAWVARIABLE respectively). The
> OWNERDRAWFIXED style will not work with self-drawing items since the fixed
> item height is determined before self-drawing controls are attached to the
> list box. (The Win 3.1 member functions CListBox::SetItemHeight and
> CComboBox::SetItemHeight can be used to get around this limitation.)
> <--------- snip ----------->
> 
> Even with this documentation I find this hard to believe. In an app I have
> (log file viewer) written using MFC for NT 3.51 & 95. I have a view class
> which creates a CListBox with the following styles:-
> 
> if(!m_listBox.Create(
> WS_CHILD |
> WS_VISIBLE |
> WS_VSCROLL |
> LBS_NOTIFY |
> LBS_OWNERDRAWFIXED |
> LBS_NOINTEGRALHEIGHT, r, this, 5000))
> 
> In this app, 'OnMeasureItem' gets called once and once only when the list
> box is created.
> 
> I have another application which is a 16bit app using VCv1.52 and this has a
> dialog box with three owner drawn listboxes. Again these have the
> OWNERDRAWFIXED style. See the Dilaog resource below:-
> 
> IDD_HDMAILADDRDLG DIALOG DISCARDABLE  30, 40, 285, 154
> STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
> CAPTION "Maill Address Book"
> FONT 8, "MS Sans Serif"
> BEGIN
>     EDITTEXT        IDC_SEARCH,5,12,114,12,ES_AUTOHSCROLL
>     LISTBOX         IDC_ADDRESSLIST,5,39,114,91,LBS_SORT |
>                     LBS_OWNERDRAWFIXED | LBS_HASSTRINGS |
>                     LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
>     PUSHBUTTON      "Details",IDC_DETAILS,5,135,40,15
>     PUSHBUTTON      "To ->",IDC_ADDTOLIST,124,38,36,13
>     PUSHBUTTON      "Remove",IDC_REMOVETO,124,52,36,13
>     LISTBOX         IDC_TOLIST,165,39,114,41,LBS_SORT | LBS_OWNERDRAWFIXED |
> 
>                     LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | WS_VSCROLL |
>                     WS_TABSTOP
>     PUSHBUTTON      "Cc ->",IDC_ADDCCLIST,124,87,36,13
>     PUSHBUTTON      "Remove",IDC_REMOVEFROM,124,101,36,13
>     LISTBOX         IDC_CCLIST,165,88,114,41,LBS_SORT | LBS_OWNERDRAWFIXED |
> 
>                     LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | WS_VSCROLL |
>                     WS_TABSTOP
>     PUSHBUTTON      "Cancel",IDCANCEL,198,135,40,15
>     DEFPUSHBUTTON   "OK",IDOK,240,135,40,15
>     LTEXT           "Mail Address List",IDC_STATIC,5,29,80,8
>     LTEXT           "Search",IDC_STATIC,5,3,113,8
> END
> 
> In this instance the 'OnMeasureItem' member of the DialogBox class gets
> called three times. One for each list box as the dialog box is created.
> 
> Armed with my debuger and working code I have proved this and I can only
> assume that the snipet of help file above is wrong.
> 
> Hope this helps.
> 
> Gerry Sweeney
> Hornbill Systems Ltd
There are two places to implement these two functions, DrawItem and
MeasureItem. One is in the Dialog which is the parent window of the
control and another is in the control itself.

The paragraph you quoted refers to the second situation only.

>  -----------------------------------------------------------------
> >I just want to clarify some thing.. Correct me if i'm wrong:-
> > a) If a CListBox has the style OwnerDrawFixed it is supposed to receive
> >    MeasureIitem message once.
> > b) If a CListBox has the style OwnerDrawVariable it receives
> >    MeasureItem message for every entry in the list box.
> 
> >My problem is when the style is OwnerDrawFixed I can't get MeasureItem
> >at all but when it's OwnerDrawVariable the MeassageItem handler get hit
> >everytime a entry is added which is what is expected.
> 
> >Am i missing something here regarding the OwnerDrawFixed Style
> >Please Help if Possible.
> >Bye & thanks in advance.
> >(  _ \/ __)(_   )
> > )   /\__ \ / /_
> > (_)\_)(___/(____)@pc.jaring.my



Gabriel Parlea-Visalon -- Gabriel@derivs.demon.co.uk
Thursday, October 10, 1996

In your message dated Tuesday 8, October 1996 you wrote :
> > <---------- snip ---------->
> > For self-drawing list boxes and combo boxes, you must override MeasureItem
> > and DrawItem. You must specify the OWNERDRAWVARIABLE style in the dialog
> > template (LBS_OWNERDRAWVARIABLE and CBS_OWNERDRAWVARIABLE respectively). The
> > OWNERDRAWFIXED style will not work with self-drawing items since the fixed
> > item height is determined before self-drawing controls are attached to the
> > list box. (The Win 3.1 member functions CListBox::SetItemHeight and
> > CComboBox::SetItemHeight can be used to get around this limitation.)
> > <--------- snip ----------->

> There are two places to implement these two functions, DrawItem and
> MeasureItem. One is in the Dialog which is the parent window of the
> control and another is in the control itself.
> 
> The paragraph you quoted refers to the second situation only.
> 

This is simply wrong. DrawItem() and MeasureItem() are two virtual member 
functions of CListBox and CComboBox. They get called only if the control 
(listbox or combobox) is owner-draw.

If you don't overload them you get the default implementation which simply 
asserts FALSE.

Read carefully the initial poster's quote from the documentation. When you 
encounter the word must, well, you must follow it.

By all means, if you can support your statement with some code or a quote from 
the documentation, I'm sure everyone would only be thrilled to see it.

I hope this helps you,

Gabriel

-- 
                             Gabriel Parlea-Visalon
                               Software Engineer
                           Derivative Trading Systems
                           gabriel@derivs.demon.co.uk





| Вернуться в корень Архива |