Thread: Creating Toolbars

  1. #1
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    798

    Creating Toolbars

    I am using the winAPI tutorial by the forger and I have created an editing window above which I now wish to put a toolbar. I have tried to incorporate the code from the website into my program, the code I have put into the WindProc function under WM_CREATE is as follows:

    Code:
    hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
            hwnd, (HMENU)IDC_MAIN_TOOL, GetModuleHandle(NULL), NULL);
    
    SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
    
    TBBUTTON tbb[3];
        TBADDBITMAP tbab;
    
    tbab.hInst = HINST_COMMCTRL;
        tbab.nID = IDB_STD_SMALL_COLOR;
        SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM)&tbab);
    
        ZeroMemory(tbb, sizeof(tbb));
        tbb[0].iBitmap = STD_FILENEW;
        tbb[0].fsState = TBSTATE_ENABLED;
        tbb[0].fsStyle = TBSTYLE_BUTTON;
        tbb[0].idCommand = ID_FILE_NEW;
    
        tbb[1].iBitmap = STD_FILEOPEN;
        tbb[1].fsState = TBSTATE_ENABLED;
        tbb[1].fsStyle = TBSTYLE_BUTTON;
        tbb[1].idCommand = ID_FILE_OPEN;
    
        tbb[2].iBitmap = STD_FILESAVE;
        tbb[2].fsState = TBSTATE_ENABLED;
        tbb[2].fsStyle = TBSTYLE_BUTTON;
        tbb[2].idCommand = ID_FILE_SAVEAS;
    
        SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
    I have then used the following code (from the website) to designate space for the toolbar:

    Code:
     HWND hTool;
        RECT rcTool;
        int iToolHeight;
    
        HWND hStatus;
        RECT rcStatus;
        int iStatusHeight;
    
        HWND hEdit;
        int iEditHeight;
        RECT rcClient;
    
        // Size toolbar and get height
    
        hTool = GetDlgItem(hwnd, IDC_MAIN_TOOL);
        SendMessage(hTool, TB_AUTOSIZE, 0, 0);
    
        GetWindowRect(hTool, &rcTool);
        iToolHeight = rcTool.bottom - rcTool.top;
    
        // Size status bar and get height
    
        hStatus = GetDlgItem(hwnd, IDC_MAIN_STATUS);
        SendMessage(hStatus, WM_SIZE, 0, 0);
    
        GetWindowRect(hStatus, &rcStatus);
        iStatusHeight = rcStatus.bottom - rcStatus.top;
    
        // Calculate remaining height and size edit
    
        GetClientRect(hwnd, &rcClient);
    
        iEditHeight = rcClient.bottom - iToolHeight - iStatusHeight;
    
        hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT);
        SetWindowPos(hEdit, NULL, 0, iToolHeight, rcClient.right, iEditHeight, SWP_NOZORDER);
    I have included commctrl.h and linked to comctl32.lib in the linker options. All the ID's are defined ok and the program compiles with no errors. The problem is that when the program runs, there is a toolbar sitauted in the correct position but there are no buttons. The website also says that it is necessary to call InitCommonControls() before you can use common controls. I am not sure how to use this function so I simply put

    InitCommonControls(); at the beginning of WinMain(). It compiles fine but still there are no buttons.

    If anyone could shed some light on this problem I would be extremely grateful, thanks.

  2. #2
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    798
    Sorry, I forgot to mention that I am using Bloodshed's DevC++ 4.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help creating multiple text files
    By Tom Bombadil in forum C Programming
    Replies: 19
    Last Post: 03-28-2009, 11:21 AM
  2. Error in creating socket in a client (UDP)
    By ferenczi in forum Networking/Device Communication
    Replies: 2
    Last Post: 11-27-2008, 11:11 AM
  3. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  4. Creating a Simple DLL in C
    By Ultima4701 in forum C Programming
    Replies: 2
    Last Post: 11-23-2002, 01:01 PM
  5. Toolbars ... Rebars... whatever!... ...
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 11-19-2001, 08:44 PM