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"}
    };STD_FILEOPEN是 windows自定义的  id, 和imagelistid组合后 是什么意思呢?难道可以随意组合嘛? 我觉得 随意组合后的结果,还是一个正确的位图id嘛?怕不是吧。
怎么可以随意组合呢? 

解决方案 »

  1.   

    imagelistid应该是位图的ID,随意组合的结果就是工具条显示不同的位图,比如打开显示的是保存的位图,你可以改变imagelistid这个顺序就知道了
      

  2.   


    const int ImageListID    = 0;看这里!!!  我随意修改了一下: TBBUTTON tbButtons[numButtons] = 
    {
    { 10000, 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"}
    };结果发现,第一个button的图标不见了可见是不能够随意修改的,那么tbbutton的第一个字段到底该如何赋值呢?遵循什么规则呢?
      

  3.   

    你查一下是不是还有一个ImageList的控件或类型的变量,这个ImageList类型的变量里存放的是位图的ID,会不会和这里的一致才可以
      

  4.   

    还有高手知道为什么嘛msdn没有解释啊
      

  5.   

    // icon indexes for standard bitmap#define STD_CUT                 0
    #define STD_COPY                1
    #define STD_PASTE               2
    #define STD_UNDO                3
    #define STD_REDOW               4
    #define STD_DELETE              5
    #define STD_FILENEW             6
    #define STD_FILEOPEN            7
    #define STD_FILESAVE            8
    #define STD_PRINTPRE            9
    #define STD_PROPERTIES          10
    #define STD_HELP                11
    #define STD_FIND                12
    #define STD_REPLACE             13
    #define STD_PRINT               14如果:const int ImageListID    = 0;
    MAKELONG(STD_FILEOPEN, ImageListID) 后 还是 STD_FILEOPEN
    不 需要 这么 搞的。你要 试试的话,可以改 高字:
    const int ImageListID    = 1;
    MAKELONG(STD_FILEOPEN,ImageListID)
    这个 1 可能 自绘时 会 用到。 
      

  6.   


    可以试试这个完成源码,粘贴就可以用了, 来自msdn调用函数放在wm_create即可
    HIMAGELIST g_hImageList = NULL;HWND CreateSimpleToolbar(HWND hWndParent)
    {
    // Declare and initialize local constants.
    const int ImageListID    = 0;
    const int numButtons     = 3;
    const int bitmapSize     = 16; const DWORD buttonStyles = BTNS_AUTOSIZE; // Create the toolbar.
    HWND hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, 
    WS_CHILD | TBSTYLE_WRAPABLE, 0, 0, 0, 0, 
    hWndParent, NULL, hInst, NULL); if (hWndToolbar == NULL)
    return NULL; // Create the image list.
    g_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)g_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); // Resize the toolbar, and then show it.
    SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0); 
    ShowWindow(hWndToolbar,  TRUE); return hWndToolbar;
    }const int ImageListID    = 0;// 换成1后,toolbar上的3个按钮的图标不见了。奇怪难道只能是0吗?msdn对toolbar的数据结构TBBUTTON 的这个字段的解释到底是啥意思啊?比如 我想换成自定义的icon。
    肯定要填我自己的icon的id,但是又不能乱填写.
      

  7.   

    _TBBUTTON { int iBitmap; //***加载图 int idCommand; //*** BYTE fsState; BYTE fsStyle; DWORD dwData; int iString; //***加载字符串 } TBBUTTON, NEAR* PTBBUTTON, FAR* LPTBBUTTON; typedef const TBBUTTON FAR* LPCTBBUTTON;
      

  8.   

    MAKELONG macro
    Creates a LONG value by concatenating the specified values.wLow
    The low-order word of the new value.
    wHigh
    The high-order word of the new value.
      

  9.   


    TBBUTTON tbButtons[numButtons] = 
    {
    { IDI_ICON1, 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"}
    };看第一个 参数用的是icon, 16*16,原因是:// Create the image list.
    g_hImageList = ImageList_Create(bitmapSize, bitmapSize,   // Dimensions of individual bitmaps.
    ILC_COLOR16 | ILC_MASK,   // Ensures transparent background.
    numButtons, 0); 里面要求16*16的
      

  10.   

    MAKELONG 
    不是需要makelong转换一下么?
      

  11.   


     IDI_ICON1的值130 和 谁makelong?
    如果和imaglist的id makelong的话,那么是多余的,
    因为其值是0.
      

  12.   


    最终可以显示的,是 采用系统自己的图标,比如 打开文件的那种图标,一直想改成自定义的图标,所以肯定的修改id啊(图标的id)结果看不到自定义的了
      

  13.   

     MAKELONG(STD_FILENEW,  ImageListID//自定义不行么)
      

  14.   

    是啊,  郁闷死了,自己的 icon高布上吗,
    getlasterror又不管用谢谢你额了啊有经验的帮忙看看
      

  15.   

    不要makelong
    直接 给 一个 IDI_XXX 就行了
      

  16.   


    TBBUTTON tbButtons[numButtons] = 
    {
    { IDI_ICON1, 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"}
    };
    10楼,你看,确实不行,是否是位图或者图标有要求,我的格式不对所致 16*16 , 位深度为32
      

  17.   

     IDI_ICON1 是不是不在 工具条 上 ?
      

  18.   

    没有看到icon啊,所以才继续追问啊
    代码在20,就不贴了
      

  19.   


    没有看到icon啊代码在20楼,就不贴了谁帮忙试试
    我2台机子都不成功,不可以看到图标
     
      

  20.   

    给个例子:
    CMyToolBar:: ONCreate
    {
    BOOL bl=m_ImageList.Create(IDB_BITMAP1,16,10,ILC_COLOR4 | ILC_MASK);
    if(bl)
    {
    CToolBarCtrl &tbc=GetToolBarCtrl();
    tbc.SetImageList(m_ImageList);
    }
    ......
    }IDB_BITMAP1 在资源中 插入 一个 bmp, 上 面 放 几个 16,15,的 图(可以从 toolbar 复制)这样 就可以 显示 你的 icon 了。