zoukankan      html  css  js  c++  java
  • [WTL]CListViewCtrl自绘

    1. CCustomDraw和LVS_OWNERDRAWFIXED

    我发现我去掉了LVS_OWNERDRAWFIXED风格,继承了CCustomDraw的CListView自绘就OK了。

    2. CCustomDraw<T>

    CCustomDraw<T> 利用静多态,给派生类一个可以定制自绘Options的策略。

    // custom draw return flags
    // values under 0x00010000 are reserved for global custom draw values.
    // above that are for specific controls
    #define CDRF_DODEFAULT          0x00000000
    #define CDRF_NEWFONT            0x00000002
    #define CDRF_SKIPDEFAULT        0x00000004
    #define CDRF_DOERASE            0x00000008 // draw the background
    #define CDRF_SKIPPOSTPAINT      0x00000100 // don't draw the focus rect

    #define CDRF_NOTIFYPOSTPAINT    0x00000010
    #define CDRF_NOTIFYITEMDRAW     0x00000020
    #if (_WIN32_IE >= 0x0400)
    #define CDRF_NOTIFYSUBITEMDRAW  0x00000020  // flags are the same, we can distinguish by context
    #endif
    #define CDRF_NOTIFYPOSTERASE    0x00000040

    3. 如何设置不同的Row Height?

        LRESULT OnMeasureItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
        {
            LPMEASUREITEMSTRUCT p = (LPMEASUREITEMSTRUCT)lParam;
            return 0;
        }

    这是第一种吧,需要设置LVS_OWNERDRAWFIXED风格属性。但是这样就和我的CCustomDraw派生冲突了。

    第二种是:

    void SetEntryHeight(int nEntryHeight)
    {
            CImageList imageList;
            imageList.Create(1, nEntryHeight - 1, ILC_COLOR, 11);
            CListViewCtrl::SetImageList(imageList.m_hImageList, LVSIL_SMALL);
            imageList.Destroy();

    但是!我马上Google了很多文章,最后的结论是,OwnerDraw的CListCtrl才可以通过第一种方式设置不同的行高,而CustomDraw的不行。我想交替地Add/Remove 

    LVS_OWNERDRAWFIXED 风格,但是另外一篇BLOG说:

    设置LVS_OWNERDRAWFIXED风格需要在Create或者PreSubclassWindow函数中进行,否则MeasureItem不会被调用。

    看,这个世界总是有很多不如意的地方!

    看来,解决的方案只能是完全Paint,既是使用LVS_OWNERDRAWFIXED,而不是

    CCustomDraw。然后用
    MeasureItem来设置不同行的高度。
  • 相关阅读:
    SharePoint Workflow 定义文件示例
    XC#、Smart Client
    ASP.NET 2.0,无刷新页面新境界!
    ShadowFax Beta 1.0 is now AVAILABLE!
    SharePoint Data Provider
    《WalkThrough : SharePoint WebPart 入门指南 四》完成
    单元测试...
    Visual Studio 2005 Team System
    Return of Rich Client
    Implement Membership & Roles & Personalization in ASP.NET 1.1
  • 原文地址:https://www.cnblogs.com/healerkx/p/2209049.html
Copyright © 2011-2022 走看看