Click here to Skip to main content
15,912,578 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to put a CRebar or CRebarCtrl in a dialog based application? Pin
bin89226-Feb-04 6:42
bin89226-Feb-04 6:42 
AnswerRe: How to put a CRebar or CRebarCtrl in a dialog based application? Pin
Antti Keskinen6-Feb-04 11:32
Antti Keskinen6-Feb-04 11:32 
GeneralA million thanks!!! Best wishes Pin
bin89227-Feb-04 18:43
bin89227-Feb-04 18:43 
AnswerRe: How to put a CRebar or CRebarCtrl in a dialog based application? Pin
alex.barylski15-May-04 23:36
alex.barylski15-May-04 23:36 
Questionhow can I activate the mouse wheel for a CFormView? Pin
DanYELL6-Feb-04 6:29
DanYELL6-Feb-04 6:29 
AnswerRe: how can I activate the mouse wheel for a CFormView? Pin
Antti Keskinen6-Feb-04 11:52
Antti Keskinen6-Feb-04 11:52 
General,how to create a toolbar in dialog based Pin
Anonymous6-Feb-04 6:08
Anonymous6-Feb-04 6:08 
GeneralRe: ,how to create a toolbar in dialog based Pin
Alexander M.,6-Feb-04 6:17
Alexander M.,6-Feb-04 6:17 
that is not a question on VC++.. it's one for win32api.

there is a source code on MSDN:
/*++

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 retrieve the
//            ToolTip text associated 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
//

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;
}

hope this helps.

Don't try it, just do it! Wink | ;-)
GeneralRe: ,i m using MFC not win32 Pin
Zeeshan Bilal6-Feb-04 6:33
Zeeshan Bilal6-Feb-04 6:33 
General,how to create a toolbar in dialog based Pin
Anonymous6-Feb-04 6:07
Anonymous6-Feb-04 6:07 
GeneralCombo Box Pin
C++NewBe6-Feb-04 5:28
C++NewBe6-Feb-04 5:28 
GeneralRe: Combo Box Pin
David Crow6-Feb-04 5:45
David Crow6-Feb-04 5:45 
GeneralRe: Combo Box Pin
C++NewBe6-Feb-04 5:52
C++NewBe6-Feb-04 5:52 
GeneralRe: Combo Box Pin
David Crow6-Feb-04 6:01
David Crow6-Feb-04 6:01 
GeneralRe: Combo Box Pin
C++NewBe6-Feb-04 7:12
C++NewBe6-Feb-04 7:12 
QuestionHow to create dynamicaly DataGrid Pin
bilas6-Feb-04 5:11
bilas6-Feb-04 5:11 
Questionhow to distiguish an object send via socket Pin
Anonymous6-Feb-04 4:26
Anonymous6-Feb-04 4:26 
AnswerRe: how to distiguish an object send via socket Pin
Alexander M.,6-Feb-04 6:14
Alexander M.,6-Feb-04 6:14 
Questionhow to distiguish an object ,, when send by socket Pin
Anonymous6-Feb-04 4:12
Anonymous6-Feb-04 4:12 
AnswerRe: how to distiguish an object ,, when send by socket Pin
valikac6-Feb-04 9:05
valikac6-Feb-04 9:05 
GeneralChanging External Dependencies Pin
Franz Klein6-Feb-04 4:08
Franz Klein6-Feb-04 4:08 
QuestionSending keys in MFC? Pin
Dev5786-Feb-04 3:49
Dev5786-Feb-04 3:49 
AnswerRe: Sending keys in MFC? Pin
David Crow6-Feb-04 4:16
David Crow6-Feb-04 4:16 
GeneralThanks Pin
Dev5786-Feb-04 5:05
Dev5786-Feb-04 5:05 
GeneralCBT Hook and WriteFile problems Pin
jtmille333333333336-Feb-04 3:48
jtmille333333333336-Feb-04 3:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.