zoukankan      html  css  js  c++  java
  • DRAWITEMSTRUCT structure 详解

    DRAWITEMSTRUCT 为需要自绘的控件或者菜单项提供了必要的信息。在需要绘制的控件或者菜单项对应的WM_DRAWITEM消息函数中得到一个指向该结构的指针。

    语法:

    typedef struct tagDRAWITEMSTRUCT {
    UINT CtlType;
    UINT CtlID;
    UINT itemID;
    UINT itemAction;
    UINT itemState;
    HWND hwndItem;
    HDC hDC;
    RECT rcItem;
    ULONG_PTR itemData;
    } DRAWITEMSTRUCT;

    成员解释:

    CtlType
    Specifies the control type. This member can be one of the following values.
    ODT_BUTTON
    Owner-drawn button
    ODT_COMBOBOX
    Owner-drawn combo box
    ODT_LISTBOX
    Owner-drawn list box
    ODT_LISTVIEW
    List-view control
    ODT_MENU
    Owner-drawn menu item
    ODT_STATIC
    Owner-drawn static control
    ODT_TAB
    Tab control
    CtlID
    指定了自绘控件的ID值,而对于菜单项则不需要使用该成员
    itemID
    表示菜单项ID,也可以表示列表框或者组合框中某项的索引值。对于一个空的列表框或组合框,该成员的值为–1。这时应用程序只绘制焦点矩形(该矩形的坐标由rcItem 成员给出)虽然此时控件中没有需要显示的项,但是绘制焦点矩形还是很有必要的,因为这样做能够提示用户该控件是否具有输入焦点。当然也可以设置itemAction 成员为合适值,使得无需绘制焦点。 
    itemAction
    指定绘制行为,其取值可以为下表中所示值的一个或者多个的联合。 
    ODA_DRAWENTIRE
    整个控件都必须更新
    ODA_FOCUS
    如果控件需要在获得或失去焦点时被绘制,则设置该值。此时应该检查itemState成员,以确定控件是否具有输入焦点。
    ODA_SELECT
    如果控件需要在选中状态改变时被绘制,则设置该值。此时应该检查itemState 成员,以确定控件是否处于选中状态。
    itemState
    指定了当前绘制操作完成后,所绘项的可见状态。例如,如果菜单项应该被灰色显示,则可以指定ODS_GRAYED状态标志。其取值可以为下表中所示值的一个或者多个的联合。.
    ODS_CHECKED
    The menu item is to be checked. This bit is used only in a menu.
    ODS_COMBOBOXEDIT
    The drawing takes place in the selection field (edit control) of an owner-drawn combo box.
    ODS_DEFAULT
    The item is the default item.
    ODS_DISABLED
    The item is to be drawn as disabled.
    ODS_FOCUS
    The item has the keyboard focus.
    ODS_GRAYED
    The item is to be grayed. This bit is used only in a menu.
    ODS_HOTLIGHT
    Windows 98/Me, Windows 2000/XP: The item is being hot-tracked, that is, the item will be highlighted when the mouse is on the item.
    ODS_INACTIVE
    Windows 98/Me, Windows 2000/XP: The item is inactive and the window associated with the menu is inactive.
    ODS_NOACCEL
    Windows 2000/XP: The control is drawn without the keyboard accelerator cues.
    ODS_NOFOCUSRECT
    Windows 2000/XP: The control is drawn without focus indicator cues.
    ODS_SELECTED
    The menu item's status is selected.
    hwndItem
    窗口或菜单句柄
    hDC
    指定了绘制操作所使用的设备环境。
    rcItem
    指定了将被绘制的矩形区域。这个矩形区域就是上面hDC的作用范围。系统会自动裁剪组合框、列表框或按钮等控件的自绘制区域以外的部分。也就是说rcItem中的坐标点(0,0)指的就是控件的左上角。但是系统不裁剪菜单项,所以在绘制菜单项的时候,必须先通过一定的换算得到该菜单项的位置,以保证绘制操作在我们希望的区域中进行。
    itemData
    Specifies the application-defined value associated with the menu item. For a control, this parameter specifies the value last assigned to the list box or combo box by the LB_SETITEMDATA or CB_SETITEMDATA message. If the list box or combo box has the LBS_HASSTRINGS or CBS_HASSTRINGS style, this value is initially zero. Otherwise, this value is initially the value that was passed to the list box or combo box in the lParam parameter of one of the following messages:
    • CB_ADDSTRING
    • CB_INSERTSTRING
    • LB_ADDSTRING
    • LB_INSERTSTRING
    If CtlType is ODT_BUTTON or ODT_STATIC, itemData is zero.

    =============================================================================

    举个简单的例子:

      如果我们使用一个自定义的按钮,当鼠标按下时由一个动画效果,当鼠标松开时又有一个动画效果,这样就可以用BS_OWNERDRAW样式,利用DRAWITEMSTRUCT中的itemAction子项,当鼠标按下时,itemAction项是ODA_SELECT,当鼠标松开时,itemAction项是也是ODA_SELECT,即:如果状态第一次改变,我们重新绘一次按钮,然后状态改变第二次,再重绘按钮。


    case WM_DRAWITEM:
      if((LPDRAWITEMSTRUCT) lParam->itemAction ==
    ODA_SELECT)
      {
        if
    (push)
          绘制按下时按钮;
        else

          绘制放开时按钮;
      }
      break;

    这样我们就可一看到按下按钮时的动态图像了。

     

  • 相关阅读:
    鼠标不灵了,还好只是线的问题。自己DIY修下了
    [摘]编译MPlayer
    TPLINK路由器 硬重启方法
    Visual C++线程同步技术剖析 (转载)
    CListCtrl一行显示多个图标问题
    一位软件工程师的6年总结
    CCIE红头发讲解CCNA、CCNP视频教程
    图片链
    [摘]如何级联两个TPLINK路由器
    [摘]测试一下你对IP地址的掌握水平
  • 原文地址:https://www.cnblogs.com/lvpengms/p/1667677.html
Copyright © 2011-2022 走看看