Win32属性页面中的图标很难看 - 4位图标

时间:2013-12-02 16:44:04

标签: c++ winapi

我在我的应用程序中使用Win32 API C ++属性表,并且与主标题或应用程序中的其他图标相比,页眉中使用的图标质量较低。

http://i.imgur.com/goiF7Je.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);

1 个答案:

答案 0 :(得分:1)

最后,我找到了解决上述问题的方法。我使用Tab Control创建了类似的窗口,而不是Property Sheets。

使用标签控制的好处:

  • 更容易维护每个标签的内容(只显示/隐藏HWND),
  • 图标为32位,
  • 它是一个标准控件,如按钮,静态文本等,因此它的工作方式相同。

缺陷:

  • 需要编写更多代码。

这是一个示例窗口: http://i.imgur.com/4AcXvSz.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加载到Tab Control的显示空间时,您必须查找选项卡控件通知。

Tab Control的通知可在此处找到: http://msdn.microsoft.com/en-us/library/windows/desktop/bb760548(v=vs.85).aspx

相关问题