工具栏图标Windows API [英] Toolbar Icons Windows API

查看:98
本文介绍了工具栏图标Windows API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用下面显示的代码创建工具栏.

Hi,
I am using the code shown below to create a tool bar.

HWND CreateSimpleToolbar(HWND hWndParent)
{
    // Define some constants.
    const int ImageListID = 0;
    const int numButtons = 3;
    const DWORD buttonStyles = BTNS_AUTOSIZE;
    const int bitmapSize = 16;

    // Create the toolbar.
    HWND hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, 
        WS_CHILD | TBSTYLE_WRAPABLE,
        0, 0, 0, 0,
        hWndParent, NULL, g_hInst, NULL);
    if (hWndToolbar == NULL)
    {
        return NULL;
    }

    // Create the imagelist.
    HIMAGELIST hImageList = ImageList_Create(
        bitmapSize, bitmapSize,   // Dimensions of individual bitmaps.
        ILC_COLOR16 | ILC_MASK,   // Ensures transparent background.
        numButtons, 0);

    // Set the image list.
    SendMessage(hWndToolbar, TB_SETIMAGELIST, (WPARAM)ImageListID, 
        (LPARAM)hImageList);

    // Load the button images.
    SendMessage(hWndToolbar, TB_LOADIMAGES, (WPARAM)IDB_STD_SMALL_COLOR, 
        (LPARAM)HINST_COMMCTRL);

    // Initialize button info.
    // IDM_NEW, IDM_OPEN, and IDM_SAVE are application-defined command constants.
    TBBUTTON tbButtons[numButtons] = 
    {
        { MAKELONG(STD_FILENEW, ImageListID), IDM_NEW, TBSTATE_ENABLED, 
          buttonStyles, {0}, 0, (INT_PTR)L"New" },
        { MAKELONG(STD_FILEOPEN, ImageListID), IDM_OPEN, TBSTATE_ENABLED, 
          buttonStyles, {0}, 0, (INT_PTR)L"Open"},
        { MAKELONG(STD_FILESAVE, ImageListID), IDM_SAVE, 0, 
          buttonStyles, {0}, 0, (INT_PTR)L"Save"}
    };

    // Add buttons.
    SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, 
        (WPARAM)sizeof(TBBUTTON), 0);
    SendMessage(hWndToolbar, TB_ADDBUTTONS, (WPARAM)numButtons, 
        (LPARAM)&tbButtons);

    // Tell the toolbar to resize itself, and show it.
    SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0); 
    ShowWindow(hWndToolbar, TRUE);
    return hWndToolbar;
}

如何用我制作的图标替换工具栏上的新文档图标?

我已将图标添加到资源文件中,其名称为500.

谢谢,
Alex

How can I replace the new document icon on the toolbar with one that I made?

I have added my icon the resources file, its name is 500.

Thanks,
Alex

推荐答案

    你说:
     You said:
 // Initialize button info.
 // IDM_NEW, IDM_OPEN, and IDM_SAVE are application-defined command constants.
 TBBUTTON tbButtons[numButtons] = 
 {
  { MAKELONG(STD_FILENEW, ImageListID), IDM_NEW, TBSTATE_ENABLED, 
   buttonStyles, {0}, 0, (INT_PTR)L"New" },
  { MAKELONG(STD_FILEOPEN, ImageListID), IDM_OPEN, TBSTATE_ENABLED, 
   buttonStyles, {0}, 0, (INT_PTR)L"Open"},
  { MAKELONG(STD_FILESAVE, ImageListID), IDM_SAVE, 0, 
   buttonStyles, {0}, 0, (INT_PTR)L"Save"}
 };





您在TBUTTON数组中发布的以上代码将IDM_NEW更改为您在与要显示的图标相关联的资源文件中声明的id常量.例如,在资源文件中,您加载了一个图标和一个常量 id为ID_NEWDOC,然后将IDM_NEW替换为ID_NEWDOC.应该可以,如果我错了,请纠正我.

The above code that you have posted, in the array of TBUTTON change the IDM_NEW to the id constant that you declared in the resource file that is associated with icon that you want to be shown. For example in the resource file you loaded an icon and the constant id is ID_NEWDOC then replace IDM_NEW with ID_NEWDOC. That should work, correct me if I'm wrong.


这篇关于工具栏图标Windows API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆