2010-06-21 74 views
2

我想創建一個工具欄,我的位圖將是40x40,我試圖使工具欄的寬度爲40像素。我希望它是一個垂直toobar。我沒有得到這個代碼的橫向結果:幫助WinAPI工具欄

HWND OGLTOOLBAR::create(HWND parent,HINSTANCE hInst,WNDPROC prc, int *toolWidthPtr) 
{ 
    if (toolhWnd != NULL) 
    { 
     return toolhWnd; 
    } 
    int iCBHeight;    // Height of the command bar 
    DWORD dwStyle;    // Style of the toolbar 
    HWND hwndTB = NULL;   // Handle to the command bar control 
    RECT rect,     // Contains the coordinates of the main 
     // window client area   
     rectTB;    // Contains the dimensions of the bounding 
    // rectangle of the toolbar control 
    INITCOMMONCONTROLSEX iccex; // The INITCOMMONCONTROLSEX structure 
TBBUTTON tbButton[8]; 
wchar_t *txt = L"wii"; 
for(int i = 0; i < 8; i += 2) 
{ 
    tbButton[i].iBitmap = 0; 
    tbButton[i].fsStyle = BTNS_BUTTON; 
    tbButton[i].fsState = TBSTATE_ENABLED; 
    tbButton[i].iString = (INT_PTR)txt; 
    tbButton->idCommand = 0; 

} 

for(int i = 1; i < 8; i += 2) 
{ 
    tbButton[i].iBitmap = 0; 
    tbButton[i].fsStyle = BTNS_BUTTON; 
    //tbButton[i].fsState = TBSTATE_ENABLED; 
    tbButton[i].iString = (INT_PTR)txt;\ 
    tbButton->idCommand = 0; 

} 

    iccex.dwSize = sizeof (INITCOMMONCONTROLSEX); 
    iccex.dwICC = ICC_BAR_CLASSES; 

    // Register toolbar control classes from the DLL for the common 
    // control. 
    InitCommonControlsEx (&iccex); 

    // Create the toolbar control. 
    dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_TOOLTIPS | TBSTYLE_WRAPABLE | TBSTYLE_TRANSPARENT | CCS_VERT 
     ; 

    if (!(hwndTB = CreateToolbarEx (
     parent,    // Parent window handle 
     dwStyle,   // Toolbar window styles 
     (UINT) 666, // Toolbar control identifier 
     8,   // Number of button images 
     hInst,    // Module instance 
     (UINT)LoadImage(hInst,MAKEINTRESOURCE(IDB_BRUSH),0,0,0,LR_VGACOLOR),  // Bitmap resource identifier 
     tbButton,   // Array of TBBUTTON structure 
     // contains button data 
     sizeof(tbButton)/sizeof(TBBUTTON), 
     // Number of buttons in toolbar 
     40,  // Width of the button in pixels 
     40,  // Height of the button in pixels 
     40,   // Button image width in pixels 
     40,  // Button image height in pixels 
     sizeof (TBBUTTON))))// Size of a TBBUTTON structure 
    { 
     return NULL; 
    } 

    // Add ToolTips to the toolbar. 
    SendMessage (hwndTB, TB_SETTOOLTIPS, (WPARAM) NUM_TOOLS, 
     (LPARAM) 8); 

    // Reposition the toolbar. 
    GetClientRect (parent, &rect); 
    GetWindowRect (hwndTB, &rectTB); 
    iCBHeight = 40; 


    mainWindow = parent; 
    toolhWnd = hwndTB; 
    return hwndTB; 

} 

我確定CCS_VERT應該使它垂直。我怎樣才能使這個toobar〜40像素寬,並有8個方塊向下而不是水平。由於

我真的不想分離,我只是認爲這將有助於但它沒有...

回答

2

SDK docs

創建垂直工具

的創建垂直工具欄 的關鍵是將CCS_VERT包含在窗口 風格,中,併爲每個按鈕設置TBSTATE_WRAP 風格

強調添加。