所有者绘制按钮强制刷新
Owner Draw Button Force Refresh
我有 4 个所有者绘制按钮,它们用作我的程序的选项卡系统。我遇到的问题是,当我单击其中一个按钮时,我需要更改其他按钮的图像。但是每当我尝试重置图像时,它只会更改我单击的按钮上的图像。有没有办法在不被单击的情况下更改其他按钮上的图像?
INT_PTR CALLBACK Springboard::DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam){
static DRAWITEMSTRUCT* pdis;
switch (msg) {
case WM_DRAWITEM:
pdis = (DRAWITEMSTRUCT*) lParam;
// (winuser.h) Maybe you also want to account for pdis->CtlType (ODT_MENU, ODT_LISTBOX, ODT_COMBOBOX, ODT_BUTTON, ODT_STATIC)
switch(pdis->CtlID) {
case IDC_TAB1:
theSpringboard.myManageOwnerDrawIconButton(pdis, hInstance);
break;
case IDC_TAB2:
theSpringboard.myManageOwnerDrawIconButton(pdis, hInstance);
break;
case IDC_TAB3:
theSpringboard.myManageOwnerDrawIconButton(pdis, hInstance);
break;
case IDC_TAB4:
theSpringboard.myManageOwnerDrawIconButton(pdis, hInstance);
break;
case IDC_TAB5:
theSpringboard.myManageOwnerDrawIconButton(pdis, hInstance);
break;
default:
break;
}
int Springboard::myManageOwnerDrawIconButton(DRAWITEMSTRUCT* pdis, HINSTANCE hInstance) {
static RECT rect;
static HBITMAP hCurrIcon, hSTDc, hSTDoff, hSTDon, hVFXc, hVFXoff, hVFXon, hCITYc, hCITYoff, hCITYon, hMAXc, hMAXoff, hMAXon, hSETc, hSEToff, hSETon;
rect = pdis->rcItem;
hSTDoff = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_STDOFF));
hSTDon = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_STDON));
hSTDc = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_STDCLICK));
hVFXoff = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_VFXOFF));
hVFXon = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_VFXON));
hVFXc = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_VFXCLICK));
hCITYoff = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_CITYOFF));
hCITYon = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_CITYON));
hCITYc = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_CITYCLICK));
hMAXoff = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_MAXOFF));
hMAXon = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_MAXON));
hMAXc = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_MAXCLICK));
hSEToff = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SETTINGOFF));
hSETon = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SETTINGON));
hSETc = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SETTINGCLICK));
if (IDC_TAB1 == pdis->CtlID) {
// If the button is selected, display the
// "active" icon, else the "inactive" icon:
if (pdis->itemState & ODS_SELECTED) hCurrIcon = hSTDc;
else hCurrIcon = hSTDoff;
if(TabRoll == 1) hCurrIcon = hSTDon;
}
if (IDC_TAB2 == pdis->CtlID) {
// If the button is selected, display the
// "active" icon, else the "inactive" icon:
if (pdis->itemState & ODS_SELECTED) hCurrIcon = hVFXc;
else hCurrIcon = hVFXoff;
//if(TabRoll == 2) hCurrIcon = hVFXon;
}
if (IDC_TAB3 == pdis->CtlID) {
// If the button is selected, display the
// "active" icon, else the "inactive" icon:
if (pdis->itemState & ODS_SELECTED) hCurrIcon = hCITYc;
else hCurrIcon = hCITYoff;
//if(TabRoll == 3) hCurrIcon = hCITYon;
}
if (IDC_TAB4 == pdis->CtlID) {
// If the button is selected, display the
// "active" icon, else the "inactive" icon:
if (pdis->itemState & ODS_SELECTED) hCurrIcon = hMAXc;
else hCurrIcon = hMAXoff;
//if(TabRoll == 4) hCurrIcon = hMAXon;
}
if (IDC_TAB5 == pdis->CtlID) {
// If the button is selected, display the
// "active" icon, else the "inactive" icon:
if (pdis->itemState & ODS_SELECTED){
hCurrIcon = hSETc;}
else{
hCurrIcon = hSEToff;}
//if(TabRoll == 5) hCurrIcon = hSETon;
}
HDC hdc = CreateCompatibleDC(pdis->hDC);
SelectObject(hdc, hCurrIcon);
BitBlt(pdis->hDC,0,
0,ICON_WIDTH,
ICON_HEIGHT, hdc, 0, 0, SRCCOPY);
DeleteDC(hdc);
return(RET_OK);
}
您可以简化DlgProc
:
INT_PTR CALLBACK Springboard::DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DRAWITEM:
theSpringboard.myManageOwnerDrawIconButton((DRAWITEMSTRUCT*)lp, hInstance);
break;
//...
return FALSE;
}
在 myManageOwnerDrawIconButton
中,您需要进行以下更改:
从HDC hdc = CreateCompatibleDC(pdis->hDC);
自:
HDC hdc = pdis->hDC;
,然后你不需要打电话DeleteDC(hdc);
更改rect
声明,它不一定是静态的。
RECT rect = pdis->rcItem;
其他静态变量需要初始化一次,这就是静态的全部意义:
static HBITMAP hCurrIcon = (HBITMAP) LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_something));
//...
ODS_SELECTED
只是意味着按下按钮。您可能希望使用自己的全局变量来手动跟踪按钮,设置选择并删除其他按钮的选择...
ps,我为您的问题添加了winapi
标签。
相关文章:
- 问:如何使用C++中的按钮从窗口打开窗口
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- QML按钮点击功能执行顺序
- 当用户超过按钮点击限制时报告
- 函数计算用户按下按钮的频率
- 热键/按钮,根据需要进行编译,但不运行(在F5和Ctrl+Shift+B之间)
- FLTK:按下哪个按钮 - 将数字传递给按钮的回调 (lambda)
- 如何通过按下第三个窗口中的按钮,将QString从一个窗口获取到另一个窗口
- 垂直方向的 Gtk3+ 旋转按钮 (c/c++)
- Qt自定义QPush按钮未显示在布局上
- SDL 操纵杆按钮按下/C++
- 如何使用按钮更新GTK3图像以使用C++从相机捕获图片
- Qt中来自不同功能的按钮引用
- 是否可以配置提升日志刷新?
- 如何在qt中同步应用程序和显示器的刷新率?
- WinAPI 在单击第一个对话框上的按钮控件并销毁第一个对话框后创建第二个对话框
- ImGui 在单击按钮后冻结
- WinAPI 无法创建按钮
- 按钮悬停在 QT 中垂直布局的选项卡小部件中不起作用
- 所有者绘制按钮强制刷新