Win32属性页中的图标是丑陋的4位图标
Icons in Win32 Property Pages are ugly - 4 bit icons
我在应用程序中使用Win32 API C++属性表,与例如主标题或应用程序中的其他图标相比,页头中使用的图标质量较低。
https://i.stack.imgur.com/SxxWc.png
在附加的图片中,两个房屋图标都来自同一资源。
有没有办法把它改成32位的彩色图标?
const int Sheets = 2;
PROPSHEETPAGE psp[Sheets];
for (int i=0; i<Sheets; ++i)
{
psp[i].dwSize = sizeof(PROPSHEETPAGE);
psp[i].dwFlags = PSP_USEICONID | PSP_USETITLE;
psp[i].lParam = 0;
psp[i].pfnCallback = NULL;
psp[i].hInstance = m_hInst;
}
psp[0].pszTemplate = MAKEINTRESOURCE(IDDNEW_IS0);
psp[0].pszIcon = MAKEINTRESOURCE(IDI_GENERAL_TAB);
psp[0].pfnDlgProc = IntegrationServer::tabGeneral;
psp[0].pszTitle = "General";
psp[1].pszTemplate = MAKEINTRESOURCE(IDDNEW_IS1);
psp[1].pszIcon = MAKEINTRESOURCE(IDI_GENERAL_REQUESTS);
psp[1].pfnDlgProc = IntegrationServer::tabRequests;
psp[1].pszTitle = "Requests";
PROPSHEETHEADER psh;
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_USEICONID | PSH_PROPSHEETPAGE | PSH_NOCONTEXTHELP | PSH_NOAPPLYNOW;
psh.hInstance = m_hInst;
psh.pszIcon = MAKEINTRESOURCE(IDI_GENERAL_TAB);
psh.pszCaption = (LPSTR) "Integration Server configuration";
psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
psh.nStartPage = 0;
psh.ppsp = (LPCPROPSHEETPAGE) &psp;
psh.hwndParent = m_hWnd;
PropertySheet(&psh);
最后,我找到了解决上述问题的方法。我使用Tab控件创建了类似的窗口,而不是属性表。
使用Tab控件的好处:
- 更容易维护每个选项卡的内容(只显示/隐藏HWND)
- 图标是32位
- 它是一个标准控件,类似于按钮、静态文本等,所以它以相同的方式工作
缺陷:
- 需要编写更多的代码
以下是一个示例窗口:https://i.stack.imgur.com/0dxEv.png
源代码:
/*
Need this:
#include <commctrl.h >
#pragma comment(lib, "Comctl32.lib")
#pragma comment(linker,"/manifestdependency:"type='win32' "
"name='Microsoft.Windows.Common-Controls' version='6.0.0.0' "
"processorArchitecture='*' publicKeyToken='6595b64144ccf1df' "
"language='*'"")
*/
// get HWND of Tab Control
HWND tab = GetDlgItem(hDlg, IDC_TAB1);
// get current instance
HINSTANCE hInst = (HINSTANCE) GetModuleHandle(NULL);
// insert 7 tabs in our Tab Control
TCITEM tie;
tie.mask = TCIF_TEXT | TCIF_IMAGE;
LPSTR item[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
for (int i = 0; i < 7; i++)
{
tie.pszText = item[i];
tie.iImage = i;
if (TabCtrl_InsertItem(tab, i, &tie) == -1)
break;
}
// insert 7 icons for each Tab
HIMAGELIST hi = ImageList_Create(16, 16, ILC_COLOR32, 0, 7);
if (hi != NULL)
{
int icons[] = {IDI_ACTIONADD, IDI_ACTIONDELETE, IDI_ACTIONEDIT,
IDI_ACTIONIMPORT, IDI_ACTIONVIEW, IDI_CONFIGURATION,
IDI_CONF_CLEANUP};
for (int i =0; i<7; ++i)
{
HICON icon = (HICON) LoadImage(hInst, MAKEINTRESOURCE(icons[i]), IMAGE_ICON, 16, 16, 0);
ICONINFO iconinfo;
GetIconInfo(icon, &iconinfo);
HBITMAP bitmap = iconinfo.hbmColor;
ImageList_Add(hi, bitmap, NULL);
DestroyIcon(icon);
}
}
TabCtrl_SetImageList(tab, hi);
// Set position and size of child window to
// put it on the entire surface of tab display window
RECT rect;
GetClientRect(tab, &rect);
// This will collect entire Tab window and will return rectangle, which will
// fulfill display space
TabCtrl_AdjustRect(tab, FALSE, &rect);
// Create child window, which will be inserted into Tab display space
HWND child = CreateDialog(hInst, MAKEINTRESOURCE(IDD_IS_COMMON_CLEANUP),
tab, IntegrationServer::empty);
// Set child window position and size to fulfill Tab Control
// those "-2", "-1" etc. are just for me - I don't like white space :)
SetWindowPos(child, NULL,
rect.left-2, rect.top-1, rect.right-rect.left+2, rect.bottom-rect.top+2,
SWP_NOZORDER);
// Show child window
ShowWindow(child, SW_SHOW);
之后,当用户要更改当前显示的选项卡时,您必须查找选项卡控件通知,并将新的HWND加载到选项卡控件的显示空间中。
选项卡控件的通知可在此处找到:http://msdn.microsoft.com/en-us/library/windows/desktop/bb760548(v=vs.85).aspx
相关文章:
- 最高有效数字侧的第N位
- 如何获取一个数字的前3位
- C / C++ 移位/偏移/向左或向右移动位图?
- 对字符串进行位操作
- 如何在24位SDL_Surface上设置像素的颜色
- 将浮动的heightmap数组导出为16位原始值
- 将尾部调用void(i32,..)位转换为llvm::函数以获取FnAttribute
- C++Union/Struct位域的实现和可移植性
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- 将按位if条件转换为普通if条件
- 对字符数组中的元素执行逐位操作
- 将位字段导出到数组
- 将应用程序从32位移植到64位时出现问题
- 逐位操作的隐式类型转换
- 位阵列上的快速AND运算
- 64位机器上的C++内存对齐
- CToolbar是否支持带有32位图标的按钮
- Win32属性页中的图标是丑陋的4位图标
- 如何在启用Windows Aero主题时在标题栏上绘制位图图标
- 将图标转换为位图——副作用