自绘控件之DrawItem(LPDRAWITEMSTRUCT )
来源:互联网 发布:淘宝amp服务商是什么 编辑:程序博客网 时间:2024/06/05 01:18
1.自绘函数:
virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
Parameters
- lpDrawItemStruct
A long pointer to a DRAWITEMSTRUCT structure. The structure contains information about the item to be drawn and the type of drawing required.
An owner-drawn button has the BS_OWNERDRAW style set. Override this member function to implement drawing for an owner-drawnCButton object. The application should restore all graphics device interface (GDI) objects selected for the display context supplied inlpDrawItemStruct before the member function terminates.
Also see the BS_ style values.
2:函数的结构体
The DRAWITEMSTRUCT structure provides information the owner window must have to determine how to paint an owner-drawn control or menu item.
typedef struct tagDRAWITEMSTRUCT { UINT CtlType; UINT CtlID; UINT itemID; UINT itemAction; UINT itemState; HWND hwndItem; HDC hDC; RECT rcItem; DWORD itemData;} DRAWITEMSTRUCT;
Parameters
- CtlType
The control type. The values for control types are as follows:
ODT_BUTTON Owner-drawn button
ODT_COMBOBOX Owner-drawn combo box
ODT_LISTBOX Owner-drawn list box
ODT_MENU Owner-drawn menu
ODT_LISTVIEW List view control
ODT_STATIC Owner-drawn static control
ODT_TAB Tab control
- CtlID
The control ID for a combo box, list box, or button. This member is not used for a menu.
- itemID
The menu-item ID for a menu or the index of the item in a list box or combo box. For an empty list box or combo box, this member is a negative value, which allows the application to draw only the focus rectangle at the coordinates specified by thercItem member even though there are no items in the control. The user can thus be shown whether the list box or combo box has the input focus. The setting of the bits in theitemAction member determines whether the rectangle is to be drawn as though the list box or combo box has input focus.
- itemAction
Defines the drawing action required. This will be one or more of the following bits:
ODA_DRAWENTIRE This bit is set when the entire control needs to be drawn.
ODA_FOCUS This bit is set when the control gains or loses input focus. TheitemState member should be checked to determine whether the control has focus.
ODA_SELECT This bit is set when only the selection status has changed. TheitemState member should be checked to determine the new selection state.
- itemState
Specifies the visual state of the item after the current drawing action takes place. That is, if a menu item is to be dimmed, the state flagODS_GRAYED will be set. The state flags are as follows:
ODS_CHECKED This bit is set if the menu item is to be checked. This bit is used only in a menu.
ODS_DISABLED This bit is set if the item is to be drawn as disabled.
ODS_FOCUS This bit is set if the item has input focus.
ODS_GRAYED This bit is set if the item is to be dimmed. This bit is used only in a menu.
ODS_SELECTED This bit is set if the item's status is selected.
ODS_COMBOBOXEDIT The drawing takes place in the selection field (edit control) of an ownerdrawn combo box.
ODS_DEFAULT The item is the default item.
- hwndItem
Specifies the window handle of the control for combo boxes, list boxes, and buttons. Specifies the handle of the menu (HMENU) that contains the item for menus.
- hDC
Identifies a device context. This device context must be used when performing drawing operations on the control.
- rcItem
A rectangle in the device context specified by the hDC member that defines the boundaries of the control to be drawn. Windows automatically clips anything the owner draws in the device context for combo boxes, list boxes, and buttons, but it does not clip menu items. When drawing menu items, the owner must not draw outside the boundaries of the rectangle defined by thercItem member.
- itemData
For a combo box or list box, this member contains the value that was passed to the list box by one of the following:
3:例子
NOTE: CMyButton is a class derived from CButton. The CMyButton// object was created as follows://// CMyButton myButton;// myButton.Create(_T("My button"), // WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW, // CRect(10,10,100,30), pParentWnd, 1);//// This example implements the DrawItem method for a CButton-derived // class that draws the button's text using the color red.void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { UINT uStyle = DFCS_BUTTONPUSH; // This code only works with buttons. ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON); // If drawing selected, add the pushed style to DrawFrameControl. if (lpDrawItemStruct->itemState & ODS_SELECTED) uStyle |= DFCS_PUSHED; // Draw the button frame. ::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem, DFC_BUTTON, uStyle); // Get the button's text. CString strText; GetWindowText(strText); // Draw the button text using the text color red. COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0)); ::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(), &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER); ::SetTextColor(lpDrawItemStruct->hDC, crOldColor);}
- 自绘控件之DrawItem(LPDRAWITEMSTRUCT )
- CListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
- MFC CStatic控件在DrawItem中自绘
- MFC CStatic控件在DrawItem中自绘
- [转]WM_DRAWITEM与DrawItem()的讨论(自绘)
- MFC 控件重绘(2) NM_CUSTOMDRAW, WM_DRAWITEM, 虚函数DrawItem
- MFC之自绘控件
- MFC之自绘控件
- DrawItem
- DrawItem
- DrawItem
- 关于ComboBox的自绘的异常与DrawItem不响应等问题
- 关于ComboBox的自绘的异常与DrawItem不响应等问题
- 关于控件重绘函数/消息 OnPaint,OnDraw,OnDrawItem,DrawItem的区别
- 关于控件重绘函数/消息 OnPaint,OnDraw,OnDrawItem,DrawItem的区别
- 重绘控件中OnPaint、OnDraw、OnDrawItem和DrawItem的区别
- 关于控件重绘函数/消息 OnPaint,OnDraw,OnDrawItem,DrawItem的区别
- wince控件之自绘列表
- 数据库连接、批量插入
- 【js】严格相等和抽象相等
- 《黑马程序员》Java实用类
- Android的ListView数据更新后,如何使最新的条目可以自动滚动到可视范围内?
- Netty源码– Netty服务器处理流程分析
- 自绘控件之DrawItem(LPDRAWITEMSTRUCT )
- MFC中怎样检测电脑设备管理器中的串口是否存在?
- hdu2005
- 相关常用单位转换 mil 英里 英尺 .......
- 怎么理解HTTP是一种无状态协议?
- js中如何将小写数字金额转换成大写中文数字
- Myeclipse10安装反编译插件JadClipse--(link方式)
- 华为OJ题库-找出字符串中第一个只出现一次的字符
- vim多窗口使用技巧