• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

博客园    首页    新随笔       管理    订阅  订阅

MFC实现 自适应操作系统的CListCtrl控件

     新建对话框应用程序,删除自动生成的控件后,拖拽一个CListCtrl控件,绑定变量名为:m_listctrl。在对话框初始化成员函数OnInitDialog()中键入以下代码即可实现自适应系统的CListCtrl控件!

    #include "uxtheme.h"
    #pragma comment(lib,"uxtheme.lib")  

    // 获取当前窗口style
    
    LONG lStyle;
    lStyle = GetWindowLong(m_listctrl.m_hWnd, GWL_STYLE);
    lStyle &= ~LVS_TYPEMASK; //清除显示方式位
    lStyle |= LVS_REPORT; //设置为report风格
    SetWindowLong(m_listctrl.m_hWnd, GWL_STYLE, lStyle);//设置style

    // 设置扩展风格
    
    DWORD dwStyle = m_listctrl.GetExtendedStyle();
    dwStyle |= LVS_EX_FULLROWSELECT;// 选中某行使整行高亮(和report风格配合使用)

    m_listctrl.SetExtendedStyle(dwStyle); 
 
    // 设置windows explorer风格主题
    
    ::SetWindowTheme(m_listctrl.m_hWnd, L"explorer", NULL);

    m_listctrl.InsertColumn(0, L"工资", LVCFMT_LEFT, 100); 
    m_listctrl.InsertColumn(1, L"姓名", LVCFMT_LEFT, 100);    
    m_listctrl.InsertColumn(2, L"学号", LVCFMT_LEFT, 100);
  
    int nRow = m_listctrl.InsertItem(0, L"2400");    
    m_listctrl.SetItemText(nRow, 1, L"ャ玥夜ゞ");   
    m_listctrl.SetItemText(nRow, 2, L"007");

 下面是这两种样式的对比图:

 

posted @ 2016-08-25 16:52  ヤ玥夜ゞ  阅读(975)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3