组合框和图片控件
图片属性更改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);
}