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");

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

 

转载于:https://www.cnblogs.com/Open-Source/p/5807479.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值