for example:
HIMAGELIST   himlNormal;
himlNormal = ImageList_Create(szButtonIconSize.cx, szButtonIconSize.cy, ILC_COLORDDB, 0, MAX_BUTTON);
ImageList_Add(himlNormal, (HBITMAP)hBitmap, NULL);
...
SendMessage(hToolBarWnd, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)himlNormal);
...
...
ImageList_Destroy(himlNormal);

解决方案 »

  1.   

    to yu_hl:
        能发个完整的例子给我吗?
      

  2.   

    /*****************************************************************************
       BuildCoolBar
    *****************************************************************************/
    HWND BuildCoolBar(HWND hwndParent)
    {
    HWND     hwndCoolBar = NULL;
    LRESULT  lResult;hwndCoolBar = CreateWindowEx( WS_EX_TOOLWINDOW, 
                                  REBARCLASSNAME, 
                                  NULL,
                                  WS_VISIBLE | WS_BORDER | WS_CHILD |
                                  WS_CLIPCHILDREN | WS_CLIPSIBLINGS | 
                                  RBS_TOOLTIPS | RBS_VARHEIGHT | RBS_BANDBORDERS |
                                  CCS_NODIVIDER | CCS_NOPARENTALIGN |
                                  ((g_wSide & 0x01) ? CCS_VERT : 0),  
                                  //g_wSide is odd if this is a vertical bar
                                  0, 0, 200, 100, hwndParent, (HMENU)ID_COOLBAR, 
                                  g_hInst, NULL);if(hwndCoolBar)
       {
       REBARINFO      rbi;
       HIMAGELIST     himlCoolBar;
       HICON          hIcon;
       REBARBANDINFO  rbbi;
       HWND           hwndChild;
       RECT           rc;
       TCHAR          szString[64];   //set up the CoolBar
       himlCoolBar = ImageList_Create(32, 32, ILC_COLORDDB | ILC_MASK, 1, 0);
       hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_MAINICON));   ImageList_AddIcon(himlCoolbar, hIcon);   rbi.cbSize  = sizeof(rbi);
       rbi.fMask   = RBIM_IMAGELIST;
       rbi.himl    = himlCoolBar;
       lResult = SendMessage(hwndCoolBar, RB_SETBARINFO, 0, (LPARAM)&rbi);
       
       //add a band that contains a combobox
       hwndChild = CreateWindowEx(   0, 
                                     TEXT("combobox"), 
                                     NULL,
                                     WS_VISIBLE | WS_CHILD | WS_TABSTOP |
                                     WS_VSCROLL | WS_CLIPCHILDREN |
                                     WS_CLIPSIBLINGS | CBS_AUTOHSCROLL | 
                                     CBS_DROPDOWN,
                                     0, 0, 100, 200, hwndCoolBar,
                                     (HMENU)ID_COMBOBOX, g_hInst, NULL);   //add some stuff to the combobox
       {
       int   i;   for(i = 0; i < 25; i++)
          {
          wsprintf(szString, TEXT("Item %d"), i + 1);
          SendMessage(hwndChild, CB_ADDSTRING, 0, (LPARAM)szString);
          }
       }
       
       GetWindowRect(hwndChild, &rc);
       
       ZeroMemory(&rbbi, sizeof(rbbi));
       rbbi.cbSize       = sizeof(REBARBANDINFO);
       rbbi.fMask        = RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_ID | RBBIM_STYLE | 
                              RBBIM_COLORS | RBBIM_TEXT | RBBIM_BACKGROUND |
                              RBBIM_IMAGE;
       rbbi.cxMinChild   = rc.right - rc.left;
       rbbi.cyMinChild   = rc.bottom - rc.top;
       rbbi.clrFore      = GetSysColor(COLOR_BTNTEXT);
       rbbi.clrBack      = GetSysColor(COLOR_BTNFACE);
       rbbi.fStyle       = RBBS_CHILDEDGE | 
                            RBBS_FIXEDBMP;
       rbbi.wID          = ID_COMBOBOX;
       rbbi.hwndChild    = hwndChild;
       rbbi.lpText       = TEXT("ComboBox");
       rbbi.hbmBack      = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_BACKGROUND));
       rbbi.iImage       = 0;   lResult = SendMessage(hwndCoolBar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)(LPREBARBANDINFO)&rbbi);   //add a band that contains a button
       hwndChild = CreateWindowEx(   0, 
                                     TEXT("button"), 
                                     TEXT("Button"),
                                     WS_CHILD | 
                                        BS_PUSHBUTTON,
                                     0, 0, 100, 50, 
                                     hwndCoolbar, 
                                     (HMENU)ID_BUTTON, 
                                     g_hInst, 
                                     NULL);
       
       GetWindowRect(hwndChild, &rc);
       
       ZeroMemory(&rbbi, sizeof(rbbi));
       rbbi.cbSize       = sizeof(REBARBANDINFO);
       rbbi.fMask        =  RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_ID |
                               RBBIM_STYLE | RBBIM_COLORS | RBBIM_TEXT |
                               RBBIM_BACKGROUND;
       rbbi.cxMinChild   = rc.right - rc.left;
       rbbi.cyMinChild   = rc.bottom - rc.top;
       rbbi.clrFore      = GetSysColor(COLOR_BTNTEXT);
       rbbi.clrBack      = GetSysColor(COLOR_BTNFACE);
       rbbi.fStyle       = RBBS_CHILDEDGE | 
                            RBBS_FIXEDBMP;
       rbbi.wID          = ID_BUTTON;
       rbbi.hwndChild    = hwndChild;
       rbbi.lpText       = TEXT("Button");
       rbbi.hbmBack      = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_BACKGROUND));   lResult = SendMessage(hwndCoolBar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)(LPREBARBANDINFO)&rbbi);
       }MoveCoolBar(hwndParent);return hwndCoolBar;
    }
      

  3.   

    sorry, 我现在没有完整例子。
      

  4.   

    to yu_hl:
       题外话,怎么给你们两个人分??
      

  5.   

    HIMAGELIST CreateImageList(HINSTANCE hInst)
    {
    HIMAGELIST hImgList;

    InitCommonControls();
    hImgList = ImageList_LoadImage(hInst, MAKEINTRESOURCE(IDB_TOOLBAR), 20, 5, CLR_DEFAULT, 
    IMAGE_BITMAP, LR_DEFAULTCOLOR);
    return hImgList;
    }
    HWND CreateToolbar(HWND hWndParent)
    {
    HIMAGELIST hImgList = NULL; HWND hToolbar;
    TBBUTTON tbb[2];
    hToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | TBSTYLE_FLAT, 0, 0, 0, 0, hWndParent, (HMENU)ID_TOOLBAR, g_hInst, NULL);
    SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); //Required for System hImgList = CreateImageList(g_hInst);
    SendMessage(hToolbar, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)hImgList); tbb[0].iBitmap = 0;
    tbb[0].idCommand = IDC_TBOPEN;
    tbb[0].fsState = TBSTATE_ENABLED;
    tbb[0].fsStyle = TBSTYLE_BUTTON;
    tbb[0].iString = -1;
    tbb[1].iBitmap = 1;
    tbb[1].idCommand = IDC_TBCLOSE;
    tbb[1].fsState = TBSTATE_ENABLED;
    tbb[1].fsStyle = TBSTYLE_BUTTON;
    tbb[1].iString = -1;
    SendMessage(hToolbar, TB_ADDBUTTONS, 2, (LPARAM)&tbb);
    SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);
    ShowWindow(hToolbar, SW_SHOW);
    return hToolbar;
    }