轻钢龙骨 影音室:OnMeasureItem

来源:百度文库 编辑:九乡新闻网 时间:2024/04/27 14:38:17
-

CWnd::OnMeasureItem 

afx_msg void OnMeasureItem( int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct );

参数说明

nIDCtl

The ID of the control.

nIDCtl控件的ID。

lpMeasureItemStruct

Points to a MEASUREITEMSTRUCT data structure that contains the dimensions of the owner-draw control.

lpMeasureItemStruct指向一个MEASUREITEMSTRUCT数据结构,其中包含自画控件的大小。

备注

The framework calls this member function by the framework for the owner of an owner-draw button, combo box, list box, or menu item when the control is created.

Override this member function and fill in the MEASUREITEMSTRUCT data structure pointed to by lpMeasureItemStruct and return; this informs Windows of the dimensions of the control and allows Windows to process user interaction with the control correctly.

If a list box or combo box is created with the LBS_OWNERDRAWVARIABLE or CBS_OWNERDRAWVARIABLE style, the framework calls this function for the owner for each item in the control; otherwise this function is called once.

Windows initiates the call to OnMeasureItem for the owner of combo boxes and list boxes created with the OWNERDRAWFIXED style before sending the WM_INITDIALOG message. As a result, when the owner receives this call, Windows has not yet determined the height and width of the font used in the control; function calls and calculations that require these values should occur in the main function of the application or library.

If the item being measured is a CMenu, CListBox or CComboBox object, then the MeasureItem virtual function of the appropriate class is called. Override the MeasureItem member function of the appropriate control’s class to calculate and set the size of each item.

OnMeasureItem will be called only if the control's class is created at run time, or it is created with the LBS_OWNERDRAWVARIABLE or CBS_OWNERDRAWVARIABLE style. If the control is created by the dialog editor, OnMeasureItem will not be called. This is because the WM_MEASUREITEM message is sent early in the creation process of the control. If you subclass by using DDX_Control, SubclassDlgItem, or SubclassWindow, the subclassing usually occurs after the creation process. Therefore, there is no way to handle the WM_MEASUREITEM message in the control's OnChildNotify function, which is the mechanism MFC uses to implement ON_WM_MEASUREITEM_REFLECT.

当控件被创建的时候,框架为自画按钮、组合框、列表框或菜单项调用这个成员函数。

重载这个函数并填充lpMeasureItemStruct指向的MEASUREITEMSTRUCT数据结构,然后返回;这将通知Windows控件的大小,并使Windows能够正确地处理控件的用户交互。

如果列表框或组合框是用LBS_OWNERDRAWVARIABLE或CBS_OWNERDRAWVARIA- BLE风格创建的,则框架为控件中的每一个项调用这个函数;否则这个函数只被调用一次。

在发送WM_INITDIALOG消息之前,Windows为用OWNERDRAWFIXED风格创建的组合框和列表框的拥有者发出对OnMeasureItem的调用。其结果是,当拥有者接收到这个调用时,Windows还没有确定在控件中使用的字体的高度和宽度;需要这些值的函数调用和计算应该发生在应用程序或库的主函数中。

如果要测量的的项是CMenu,CListBox或CComboBox对象,则将调用适当的类的虚函数MeasureItem。重载适当的控件类的MeasureItem成员函数以计算并设置每个项的大小。

仅当控件类是在运行时创建,或者它是用LBS_OWNERDRAWVARIABLE或CBS_OWNERDRAWVARIABLE风格创建的时候,OnMeasureItem才会被调用。这是因为WM_MEASUREITEM消息时在控件创建过程的早期被发送的。如果你使用DDX_ Control,SubclassDlgItem或SubclassWindow进行了子类化,则子类化过程通常发生在创建过程之后。因此,在控件的OnChildNotify函数中无法处理WM_MEASUREITEM消息,这是MFC用来实现ON_WM_MEASUREITEM_REFLECT的机制。

Note   This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.

注意 框架调用这个成员函数以允许你的应用程序处理一个Windows消息。传递给你的成员函数的参数反映了接收到消息时框架接收到的参数。如果你调用了这个函数的基类实现,则该实现将使用最初传递给消息的参数(而不是你提供给这个函数的参数