0

我使用 MSDN 上的示例创建了一个简单的工具栏(http://msdn.microsoft.com/en-us/library/windows/desktop/hh298381(v=vs.85).aspx)。我给它添加了一些图标。不幸的是,用户界面真的很糟糕。它没有显示在一行中。这是我的代码:HWND CMainDlg::CreateSimpleToolbar(HWND hWndParent) {

const int ImageListID    = 0;
const int numButtons     = 10;
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, g_hInst, NULL);

if (hWndToolbar == NULL)
    return NULL;

// Create the image list.
g_hImageList = ImageList_Create(bitmapSize, bitmapSize,   // Dimensions of individual bitmaps.
    ILC_COLOR4 | ILC_MASK,   // Ensures transparent background.
    numButtons, 0);

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

  //int n =  ImageList_AddIcon(g_hImageList, LoadIcon(HINST_COMMCTRL, MAKEINTRESOURCE(IDI_ICON1))); // ImageList_ReplaceIcon
//HBITMAP     hBitmap             = NULL;  

// hBitmap = (HBITMAP)LoadImage(g_hInst,_T("D:\add.bmp"), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR|LR_LOADFROMFILE); // int i = ImageList_Add(g_hImageList,hBitmap,NULL);

  int index_next = ImageList_AddIcon(g_hImageList, LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_NEXT)));
  int index_prev =   ImageList_AddIcon(g_hImageList, LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_PREV)));
  int index_reload =   ImageList_AddIcon(g_hImageList, LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_RELOAD)));
  int index_open =  ImageList_AddIcon(g_hImageList, LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_OPEN)));
  int index_save =  ImageList_AddIcon(g_hImageList, LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_SAVE)));
  int index_rotate90 =  ImageList_AddIcon(g_hImageList, LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ROTATE90)));
  int index_rotate270 =  ImageList_AddIcon(g_hImageList, LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ROTATE270)));
  int index_free_rotate = ImageList_AddIcon(g_hImageList, LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_FREE_ROTATE)));
  int index_exit = ImageList_AddIcon(g_hImageList, LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_EXIT)));
 int index_enhance = ImageList_AddIcon(g_hImageList, LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ENHANCE)));
  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(index_open, ImageListID), IDM_OPEN, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Open"},
    { MAKELONG(index_save, ImageListID), IDM_SAVE, TBSTATE_ENABLED,     buttonStyles, {0}, 0, (INT_PTR)L"Save"},
    { MAKELONG(index_next, ImageListID),IDM_NEXT, TBSTATE_ENABLED,     buttonStyles, {0}, 0, (INT_PTR)L"Next"},
    { MAKELONG(index_prev, ImageListID), IDM_PREV, TBSTATE_ENABLED,     buttonStyles, {0}, 0, (INT_PTR)L"Previous"},
    { MAKELONG(index_reload, ImageListID),IDM_RELOAD, TBSTATE_ENABLED,     buttonStyles, {0}, 0, (INT_PTR)L"Reload"},
    { MAKELONG(index_rotate90 ,ImageListID), IDM_ROTATE_90, TBSTATE_ENABLED,     buttonStyles, {0}, 0, (INT_PTR)L"Rotate +90"},
    { MAKELONG(index_rotate270, ImageListID), IDM_ROTATE_270, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Rotate -90"},
    { MAKELONG(index_free_rotate,ImageListID), IDM_ROTATE, TBSTATE_ENABLED,     buttonStyles, {0}, 0, (INT_PTR)L"Rotate"},
    { MAKELONG(index_enhance, ImageListID), IDM_SAVE_GRAPH, TBSTATE_ENABLED,     buttonStyles, {0}, 0, (INT_PTR)L"Edge Enhance"},
    { MAKELONG(index_exit, ImageListID), IDM_EXIT, TBSTATE_ENABLED,     buttonStyles, {0}, 0, (INT_PTR)L"EXIT"}
};

// 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);

//ATL::CWindow *window=GetWindow(hWndToolbar);
::ShowWindow(hWndToolbar,  TRUE);

return hWndToolbar;

}

4

0 回答 0