Article ID: 168289
Article Last Modified on 11/21/2006
// MyToolBar.h : headerfile
class CMyToolBar : public CToolBar
{
...
protected:
virtual LRESULT DefWindowProc(UINT message, WPARAM wParam,
LPARAM lParam);
...
};
// MyToolBar.cpp : implementation file
#include "stdafx.h"
#include "mytoolbar.h"
...
LRESULT CMyToolBar::DefWindowProc(UINT message, WPARAM wParam,
LPARAM lParam)
{
// the toolbar common control does not handle these messages well
// if the WS_VISIBLE style is not turned on under Windows 95
DWORD style = GetStyle();
if (message == TB_DELETEBUTTON || message == TB_INSERTBUTTON)
{
if (!(style & WS_VISIBLE))
{
ModifyStyle(0,WS_VISIBLE);
}
}
LRESULT lresult = CToolBar::DefWindowProc(message, wParam, lParam);
if (message == TB_DELETEBUTTON || message ==TB_INSERTBUTTON)
{
if (!(style & WS_VISIBLE))
{
ModifyStyle(WS_VISIBLE,0);
}
}
return lresult;
}
You can derive the CToolBar by using ClassWizard to derive from "generic
CWnd" and changing all CWnd references to CToolBar.
BOOL CMainFrame::OnCreate(...)
{
...
m_wndToolBar.SetButtonText(0,"New");
m_wndToolBar.SetButtonText(1,"Open");
m_wndToolBar.SetButtonText(2,"Save");
m_wndToolBar.SetButtonText(4,"Cut");
m_wndToolBar.SetButtonText(5,"Copy");
m_wndToolBar.SetButtonText(6,"Paste");
m_wndToolBar.SetButtonText(8,"Print");
m_wndToolBar.SetButtonText(9,"About");
CRect temp;
m_wndToolBar.GetItemRect(0,&temp);
m_wndToolBar.SetSizes( CSize(temp.Width(),temp.Height()),
CSize(16,15));
return 0;
}
(c) Microsoft Corporation 1997, All Rights Reserved.
Contributions by Sridhar S. Madhugiri, Microsoft Corporation
Keywords: kbnoupdate kbtoolbar kbuidesign kbprb KB168289