最好能给出简单些的方法比如我做了以下步骤:
 1.生成一个名为 MyToolbar 的 Win32 Application 工程。
 #include <commctrl.h> 
  链接 comctl32.lib
 2. 写出主程序代码,然后调用 InitCommcontrols( );
 3. 选择 New--->File---->Resource Script 建立一个资源文件
 4. 选择 Insert---->Resource----->Toolbar; 建立一ID 为IDR_TOOLBAR 的Toolbar的资源.跟着应该怎样做 ?? 还请高手指教~~
最好能给出源代码及相应的建立步骤,谢谢 !

解决方案 »

  1.   

    我自己没试过...
    不过MSDN中有例子http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/shellcc/Toolbar1/default.asp
      

  2.   

    Creating a Toolbar
    You can use two functions to create a toolbar—CreateToolbarEx or CreateWindowEx. The CreateToolbarEx function creates a toolbar and adds an initial set of buttons to it. You can also use CreateWindowEx, specifying the TOOLBARCLASSNAME window class to create a toolbar that initially contains no buttons. The TOOLBARCLASSNAME window class is registered when the common control dynamic-link library (DLL) is loaded. To ensure that this DLL is loaded, use the InitCommonControlsEx function first. If you create an empty toolbar, you add buttons to it by using the TB_ADDBUTTONS or TB_INSERTBUTTON message. If you retrieve the size of the toolbar, you must send the TB_AUTOSIZE message after all the items and strings have been inserted into the control to cause the toolbar to recalculate its size based on its content. 
      

  3.   

    TOOLBAR.C/*++Copyright (c) 1998  Microsoft Corporation
    All rights reserved.Module Name:--*/
    // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
    // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
    // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
    // PARTICULAR PURPOSE.
    //
    // Copyright (C) 1993-1995 Microsoft Corporation.  All Rights Reserved.
    //
    //  MODULE: toolbar.c
    //
    //  PURPOSE: Handles general routines for the Toolbar control
    //
    //  FUNCTIONS:
    //    CreateTBar    - Creates the Toolbar control for the sample.
    //    MsgNotify     - Handles the WM_NOTIFY message that gets sent to
    //                    the parent window to get ToolTip Text.
    //  COMMENTS:
    //#include <windows.h>            // required for all Windows applications
    #include <windowsx.h>
    #include <commctrl.h>           // prototypes and defs for common controls
    #include "globals.h"            // prototypes specific to this application
    #include "toolbar.h"            // prototypes and #defines for toolbar.c
    #include "statbar.h"
    #include "resource.h"// Global Variable for the toolbar control.HWND    hWndToolbar;//  **TODO**  Change the following values to match your toolbar bitmap
    //
    // NUMIMAGES    = Number of images in toolbar.bmp.  Note that this is not
    //                the same as the number of elements on the toolbar.
    // IMAGEWIDTH   = Width of a single button image in toolbar.bmp
    // IMAGEHEIGHT  = Height of a single button image in toolbar.bmp
    // BUTTONWIDTH  = Width of a button on the toolbar (zero = default)
    // BUTTONHEIGHT = Height of a button on the toolbar (zero = default)#define NUMIMAGES       20
    #define IMAGEWIDTH      18
    #define IMAGEHEIGHT     17
    #define BUTTONWIDTH     0
    #define BUTTONHEIGHT    0//  **TODO**  Add/remove entries in the following array to define the 
    //            toolbar buttons (see documentation for TBBUTTON).TBBUTTON tbButton[] =
    {
        {0,   IDM_FILENEW,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {1,   IDM_FILEOPEN,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {2,   IDM_FILESAVE,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {3,   IDM_EDITCUT,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {0,   0,               TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0},
        {4,   IDM_EDITCOPY,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {5,   IDM_EDITPASTE,   TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {6,   IDM_FILEPRINT,   TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {0,   0,               TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0},
        {7,   IDM_ABOUT,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
    };
    TBBUTTON tbButtonNew[] =
    {
        { 8,  IDM_ERASE,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        { 9,  IDM_PEN,         TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {10,  IDM_SELECT,      TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {11,  IDM_BRUSH,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {12,  IDM_AIRBRUSH,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {13,  IDM_FILL,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {14,  IDM_LINE,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {15,  IDM_EYEDROP,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {16,  IDM_ZOOM,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {17,  IDM_RECT,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {18,  IDM_FRAME,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
        {19,  IDM_OVAL,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},};//
    //  FUNCTION: CreateTBar(HWND)
    //
    //  PURPOSE:  Calls CreateToolBarEx()
    //
    //
    //  PARAMETERS:
    //
    //  hwnd - Window handle : Used for the hWndParent parameter of the control.
    //
    //  RETURN VALUE:
    //
    //  If toolbar control was created successfully Return TRUE,
    //  else returns FALSE.
    //
    //  COMMENTS:
    //
    //char pszStrings[] = {'&','N','E','W','\0','\0'};BOOL CreateTBar(HWND hwnd)
    {
      int iNew;
      UINT ID;  hWndToolbar = CreateToolbarEx(hwnd,
                                      WS_CHILD | WS_VISIBLE   
                                      | CCS_ADJUSTABLE | TBSTYLE_TOOLTIPS,
                                      IDM_TOOLBAR,
                                      NUMIMAGES,
                                      hInst,
                                      IDB_BMP,
                                      tbButton,
                                      sizeof(tbButton)/sizeof(TBBUTTON),
                                      BUTTONWIDTH,
                                      BUTTONHEIGHT,
                                      IMAGEWIDTH,
                                      IMAGEHEIGHT,
                                      sizeof(TBBUTTON));
        iNew = SendMessage(hWndToolbar, TB_ADDSTRING,(WPARAM) 0, (LPARAM) pszStrings); 
        iNew = SendMessage(hWndToolbar, TB_MAPACCELERATOR, (WPARAM) 'N', (LPARAM) &ID);    return (hWndToolbar != NULL);
    }//
    //  FUNCTION: MsgNotify(HWND, UINT, WPARAM, LPARAM)
    //
    //  PURPOSE:  WM_NOTIFY is sent to the parent window to get the
    //            tooltip text assoc'd with that toolbar button.
    //
    //  PARAMETERS:
    //
    //    hwnd      - Window handle  (Unused)
    //    uMessage  - Message number (Unused)
    //    wparam    - Extra data     (Unused)
    //    lparam    - TOOLTIPTEXT FAR*
    //
    //  RETURN VALUE:
    //    Always returns 0 - Message handled
    //
    //
    //  COMMENTS:
    //    This message fills in the lpszText field of the TOOLTIPTEXT
    //    structure if code == TTN_NEEDTEXT
    //---------for more--------------------
      

  4.   


    LRESULT MsgNotify(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
    {
        
        LPTOOLTIPTEXT   lpToolTipText;
        static char     szBuffer[64];
        static UINT     i=0;
        LPNMHDR         lpnmhdr;    lpToolTipText = (LPTOOLTIPTEXT)lparam;
        lpnmhdr = (LPNMHDR)lparam;    // We do this to customize the toolbar; otherwise
        // the customize dialog box goes away.
      
        if (lpnmhdr->code == TBN_QUERYINSERT)
            return TRUE;    else if (lpnmhdr->code == TBN_QUERYDELETE)
        {
            return TRUE;
        }    else if (lpnmhdr->code == TBN_DELETINGBUTTON)
        {
            return TRUE;
        }    else if (lpnmhdr->code == TBN_BEGINDRAG)
            return TRUE;    else if (lpnmhdr->code == TBN_ENDDRAG)
            return TRUE;    else if (lpnmhdr->code == TBN_BEGINADJUST)
            return TRUE;    else if (lpnmhdr->code == TBN_INITCUSTOMIZE)
            return TRUE;    else     if (lpnmhdr->code == TBN_GETBUTTONINFO)
        {
            LPTBNOTIFY lpTbNotify = (LPTBNOTIFY)lparam;
            char  szBuffer [20];
            if (lpTbNotify->iItem < 12)    // 20 = the total number of buttons
            {                              // tbButton and tbButtonNew
                                                        // Send back information about the
                                                        // other 12 buttons in tbButtonNew;
                                           
                lpTbNotify->tbButton = tbButtonNew[lpTbNotify->iItem];            LoadString(hInst,
                           4000+ lpTbNotify->iItem,   // string ID == command ID
                           szBuffer,
                           sizeof(szBuffer));            lstrcpy (lpTbNotify->pszText, szBuffer);
                lpTbNotify->cchText = sizeof (szBuffer);
                return TRUE;
            }
            else
            return 0;
        }
        else
        if (lpToolTipText->hdr.code == TTN_NEEDTEXT)
        {                LoadString(hInst,
                       lpToolTipText->hdr.idFrom,   // string ID == command ID
                       szBuffer,
                       sizeof(szBuffer));        UpdateStatusBar(lpToolTipText->lpszText, 0, 0);//        lpToolTipText->lpszText = szBuffer;
    // Depending on what is entered into the hInst parameter of TOOLTIPTEXT
    // structure, the lpszText member can be a buffer or an INTEGER VALUE
    // obtained from MAKEINTRESOURCE()...        lpToolTipText->hinst = hInst;
            lpToolTipText->lpszText = MAKEINTRESOURCE(lpToolTipText->hdr.idFrom);
        }    return 0;
    }
      

  5.   

    看看这个!
    http://www.vcroad.com/shownews.asp?newsid=498
      

  6.   

    这几段,我已在 MSDN 里看过了,但太复杂了。而且不能编译, 不知为什么。
      

  7.   

    我给你写了一个DEMO
    你的信箱?
    [email protected]
      

  8.   

    新写的绝对符合要求
    -----------------------
    // UseToolBar.cpp : Defines the entry point for the application.
    //#include "stdafx.h"
    #include <windows.h>
    #include <commctrl.h>//warnning:must set the linker to link the library:comctl32.lib
    #include "winsdk.rc"
    #define NUM_BUTTONS 8
    HWND CreateAToolBar (HWND);
    long PASCAL WndProc (HWND, UINT, WPARAM, LPARAM);HINSTANCE hInst;
    HWND hWndToolBar;
    char pszCaption[][NUM_BUTTONS]=
    {
    "New","Open","Save","","Large","Small","Report","List"
    };int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        LPSTR lpszCmdParam, int nCmdShow)
    {
        static char         szAppName[] = "HelloWin";
        HWND                hwnd;
        MSG                 msg;
        WNDCLASS            wndclass;    if (!hPrevInstance)
        {
            wndclass.style          = CS_HREDRAW|CS_VREDRAW;
            wndclass.lpfnWndProc    = WndProc;
            wndclass.cbClsExtra     = 0;
            wndclass.cbWndExtra     = 0;
            wndclass.hInstance      = hInstance;
            wndclass.hIcon          = LoadIcon (NULL, IDI_APPLICATION);
            wndclass.hCursor        = LoadCursor (NULL, IDC_ARROW);
            wndclass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
            wndclass.lpszMenuName   = NULL;
            wndclass.lpszClassName  = szAppName;        RegisterClass (&wndclass);
        }
        hwnd = CreateWindow(szAppName,
                            "The Hello Program",
                            WS_OVERLAPPEDWINDOW,
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,
                            CW_USEDEFAULT,
                            NULL,
                            NULL,
                            hInstance,
                            NULL);    ShowWindow (hwnd, nCmdShow);
        UpdateWindow (hwnd);
        hInst = hInstance;    while (GetMessage (&msg, NULL, 0, 0))
        {
            TranslateMessage (&msg);
            DispatchMessage (&msg);
        }
        return msg.wParam;
    }long APIENTRY WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
        {
            HDC         hdc;
            PAINTSTRUCT ps;
            RECT        rect;
            
            switch (message)
            {
            case WM_CREATE:
                hWndToolBar=CreateAToolBar(hwnd);
                return 0;
    case WM_SIZE:
    SendMessage(hWndToolBar,WM_SIZE,wParam,lParam);
    return 0;
            case WM_PAINT:
                hdc = BeginPaint (hwnd, &ps);
                GetClientRect (hwnd, &rect);
                SetBkMode(hdc, TRANSPARENT);
    SetTextColor(hdc,RGB(0,0,255));
                DrawText (hdc, "Hello Windows! from [email protected] 宋业文 南京 扬子石化 ", -1, &rect,
                    DT_SINGLELINE|DT_CENTER|DT_VCENTER);
                return 0;
            
            case WM_NOTIFY:
                return 0;
            
            case WM_DESTROY:
                PostQuitMessage (0);
                return 0;
            }    return DefWindowProc (hwnd, message, wParam, lParam);
        }HWND CreateAToolBar(HWND hWndParent)
    {
    HWND hWndToolbar;
    TBADDBITMAP tb;
    int index, stdidx;
    INITCOMMONCONTROLSEX icex;//assert to load comctl32.dll// Toolbar buttons
    TBBUTTON tbButtons [] = 
    {
    {STD_FILENEW, IDM_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
    {STD_FILEOPEN, IDM_OPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
    {STD_FILESAVE, IDM_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
    {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, 0},//separator
    {VIEW_LARGEICONS, IDM_LARGEICON, TBSTATE_ENABLED, TBSTYLE_BUTTON, 
    0L, 0},
    {VIEW_SMALLICONS, IDM_SMALLICON, TBSTATE_ENABLED, TBSTYLE_BUTTON, 
    0L, 0},
    {VIEW_LIST, IDM_LISTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 
    0L,0},
    {VIEW_DETAILS, IDM_REPORTVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 
    0L, 0},
    }; // Ensure that the common control DLL is loaded. 
    icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    icex.dwICC  = ICC_BAR_CLASSES;
    InitCommonControlsEx(&icex);// Create the toolbar
    hWndToolbar = CreateToolbarEx (hWndParent, 
    WS_CHILD | WS_BORDER | WS_VISIBLE | TBSTYLE_TOOLTIPS, 
    ID_TOOLBAR, 11, (HINSTANCE)HINST_COMMCTRL, IDB_STD_SMALL_COLOR, 
    (LPCTBBUTTON)&tbButtons, 0, 0, 0, 100, 30, sizeof (TBBUTTON));// Add the next four buttons
    tb.hInst = HINST_COMMCTRL;
    tb.nID = IDB_VIEW_SMALL_COLOR;
    stdidx = SendMessage (hWndToolbar, TB_ADDBITMAP, 12, (LPARAM)&tb);for (index = 4; index < NUM_BUTTONS; index++)
    {
    tbButtons[index].iBitmap += stdidx;
    }int iIndexString[NUM_BUTTONS];
    for (index = 0; index < NUM_BUTTONS; index++)
    {
    iIndexString[index]=SendMessage(hWndToolbar, TB_ADDSTRING, (WPARAM)hInst, (LPARAM) (LPSTR) pszCaption[index]); 
    tbButtons[index].iString=iIndexString[index];
    }SendMessage (hWndToolbar, TB_ADDBUTTONS, 8, (LONG) &tbButtons);
                  
    return hWndToolbar;} 
      

  9.   

    RegisterClass
    CreateWindow
    ShowWindow