zoukankan      html  css  js  c++  java
  • MFC_2.4 组合框和图片控件

    组合框和图片控件

    1.拖控件

    图片属性更改Type 为Bitmap 名字也要改,不能为IDC_STATIC

    绑定变量控件,重命名。

    2.初始化

    // 设置一个定时器,用于更新图片
    SetTimer(0x100, 100, NULL);

    // 初始化组合框控件
    m_ComboBox.InsertString(0, L"第一个");
    m_ComboBox.InsertString(1, L"第二个");
    m_ComboBox.InsertString(2, L"第三个");
    m_ComboBox.SelectString(0, L"第一个");

    3.响应定时器跟按钮

    // 更新图片
    void CDefaultDlg::OnTimer(UINT_PTR nIDEvent)
    {
    // 更新到第几张图片
    static int index = 0;

    if (nIDEvent == 0x100)
    {
    // 根据当前的 index 加载位图
    CBitmap Bitmap;

    // 计算 index 的值
    index = index == 49 ? 0 : index + 1;

    // 根据 index 加载图片
    Bitmap.LoadBitmapW(IDB_BITMAP1 + index);

    // 设置位图
    m_StaticCtrl.SetBitmap(Bitmap);
    }

    CDialogEx::OnTimer(nIDEvent);
    }


    // 响应
    void CDefaultDlg::OnBnClickedButton1()
    {
    CString Text = L"";

    // 获取选中项的下标
    CString indexStr;
    int index = m_ComboBox.GetCurSel();
    indexStr.Format(L"%d", index);

    // 获取选中的字符串
    m_ComboBox.GetWindowTextW(Text);

    // 输出信息
    MessageBox(indexStr + L": " + Text);

    }

     

  • 相关阅读:
    连接数据库,创建表,插入数据,更新数据
    常用的表达式转换
    同构与异构
    Bitmap(一)
    ListView的优化尝试
    Animation初探(二)
    Animation初探(一)
    关于ActionBar的坑
    关于Bitmap的加载(二)
    关于Bitmap的加载(一)
  • 原文地址:https://www.cnblogs.com/ltyandy/p/10928325.html
Copyright © 2011-2022 走看看