sdk toolbar建立

来源:互联网 发布:重庆java招聘 编辑:程序博客网 时间:2024/05/16 18:45
//////////////////////////////////////////////////////////////////////////
HWND CreateAToolbar(HINSTANCE hinst,HWND hwndParent,TBBUTTON tbButtons[],int NUM_BUTTONS)
{
    HWND hwndToolbar;
    TBADDBITMAP tb;

    TBBUTTON 
*ptbButton = NULL; //sizeof (TBBUTTON) 没有他就会发生访问违例
    ptbButton = tbButtons;
        
    InitCommonControls(); 
    hwndToolbar 
= CreateToolbarEx ( 
        hwndParent, 
// parent
        WS_CHILD | WS_BORDER | WS_VISIBLE | TBSTYLE_TOOLTIPS | 
        CCS_ADJUSTABLE, 
// window style
        ID_TOOLBAR, // toolbar ID
        11// number of bitmaps
        (HINSTANCE)HINST_COMMCTRL, // mod instance
        IDB_STD_SMALL_COLOR, // resource ID for bitmap(从标准的bitmap中取图片)
        (LPCTBBUTTON)ptbButton, // address of buttons
        NUM_BUTTONS - 4// number of buttons  先创建前NUM_BUTTONS - 4个button
        1616// width & height of buttons
        1616// width & height of bitmaps
        sizeof (TBBUTTON)); // structure size
    
    
//修改后4个的图片
    
// Add the system-defined view bitmaps.
    
// The hInst == HINST_COMMCTRL
    
// The nID == IDB_VIEW_SMALL_COLOR
    tb.hInst = HINST_COMMCTRL;
    tb.nID 
= IDB_VIEW_SMALL_COLOR;//指定图片来的地方前面有11个标准的图片,
    
//所以从12开始,返回非标准的图片的index
    int stdidx = SendMessage (hwndToolbar, TB_ADDBITMAP,0, (LPARAM)&tb);//重要的 stdix = 15
    
    
//将非标准的图片放入后4个button中的iBitmap变量中
    
// Update the indexes to the bitmaps.
    for (int index = NUM_BUTTONS-4 ; index < NUM_BUTTONS; index++)
        tbButtons[index].iBitmap 
+= stdidx;  //开始是iBitmap = 0 现在后4的iBitmap = 15
    
    
//建立后4个button,从tbButtons[NUM_BUTTONS-4]开始
    
// Add the view buttons.
    SendMessage (hwndToolbar, TB_ADDBUTTONS, 4/*后4个*/, (LONG) &tbButtons[NUM_BUTTONS-4]/*开始的button*/);
    
    
if (hwndToolbar == NULL)
    
{
        MessageBox (NULL, 
"Toolbar not created!", NULL, MB_OK);
        
return 0;
    }

    
return hwndToolbar;
}

 

 

//////////////////////////////////////////////////////////////////////////

void InitToolbar(HINSTANCE hinst,HWND hwndToolbar)
{
    HWND hwndCombo,hwndTT;
    TOOLINFO lpToolInfo;
    
char *szStrings[] = {"Nancy""Dale""Dennis""Herman""Ken""Kyle",
        
"Nigel""Renan""Ruediger"}
;
    
    
// Create the combo box and add it to the toolbar.
    hwndCombo = CreateWindowEx (0L// no extended styles
        "COMBOBOX"// class name
        ""// default text
        WS_CHILD | WS_BORDER | WS_VISIBLE |
        CBS_HASSTRINGS 
| CBS_DROPDOWN, // styles and defaults
        00100250// size and position
        hwndToolbar, // parent window
        (HMENU)IDM_COMBO, // ID
        hinst, // current instance
        NULL); // no class data
    
    
if (hwndCombo)
    
{
        
// Add strings to the combo box.
        for (int idx = 0; idx < sizeof szStrings / sizeof szStrings[0]; idx++)
            SendMessage (hwndCombo, CB_INSERTSTRING, (WPARAM)(
-1), 
            (LPARAM)szStrings[idx]);
    }
 
    
    
// This code is in the main window procedure after the combo box
    
// has been created.
    
// Set the window procedure for the combo box.
    lpfnDefCombo = (WNDPROC) GetWindowLong (hwndCombo, GWL_WNDPROC);
    SetWindowLong (hwndCombo, GWL_WNDPROC, (LONG)ComboWndProc);
    
    
// Get the handle to the ToolTip window.
    hwndTT = (HWND) SendMessage (hwndToolbar, TB_GETTOOLTIPS, 00);
    
    
if (hwndTT)
    
{
        
// Fill out the TOOLINFO structure.
        lpToolInfo.cbSize = sizeof (lpToolInfo);
        
// The uID is the handle of the tool (the combo box).
        lpToolInfo.uFlags = TTF_IDISHWND | TTF_CENTERTIP;
        
// The string ID in the resource
        lpToolInfo.lpszText = (LPTSTR)IDM_COMBO;
        
// The window that gets the ToolTip messages
        lpToolInfo.hwnd = hwndToolbar;
        
// The tool
        lpToolInfo.uId = (UINT)hwndCombo;
        
// The instance that owns the string resource
        lpToolInfo.hinst = hinst;
        
        
// Set up the ToolTip for the combo box.
        SendMessage (hwndTT, TTM_ADDTOOL, 0,
            (LPARAM)(LPTOOLINFO)
&lpToolInfo);
    }

}

 

使用函数

原创粉丝点击