Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding a toolbar to a generic CWnd

226 views
Skip to first unread message

David Mc Kenna

unread,
Sep 26, 1996, 3:00:00 AM9/26/96
to

Could anyone tell me how to add a Toolbar to a CWnd, I know how to add a
toolbar to a window of type CFrameWnd, but now I wish to add it to a
generic CWnd. Must I create a context for the toolbar, this is the code
I have at the moment:

BEGIN_MESSAGE_MAP(Window, CWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()

int Window::OnCreate (LPCREATESTRUCT lpcs)
{
// Create toolbar at the top of the generic window
ToolBar.Create(this)
ToolBar.LoadToolBar(IDR_MAINFRAME))
}

Thanks for any help

David Mc Kenna

Karen T. Fura

unread,
Oct 1, 1996, 3:00:00 AM10/1/96
to

>BEGIN_MESSAGE_MAP(Window, CWnd)
> ON_WM_CREATE()
>END_MESSAGE_MAP()

>Thanks for any help

>David Mc Kenna

This solution is in the 'Visual C++ 4 How-To by
Scott Stanfield and Ralph Arvesen published
by the Waite Group. It's been very useful to me.

Karen Fura


Karen T. Fura

unread,
Oct 1, 1996, 3:00:00 AM10/1/96
to

Karen T. Fura

unread,
Oct 1, 1996, 3:00:00 AM10/1/96
to

Shankar Ganesh

unread,
Oct 1, 1996, 3:00:00 AM10/1/96
to

David Mc Kenna (da...@euristix.ie) wrote:
: Could anyone tell me how to add a Toolbar to a CWnd, I know how to add a
: toolbar to a window of type CFrameWnd, but now I wish to add it to a
: generic CWnd. Must I create a context for the toolbar, this is the code
: I have at the moment:

: BEGIN_MESSAGE_MAP(Window, CWnd)
: ON_WM_CREATE()
: END_MESSAGE_MAP()

: int Window::OnCreate (LPCREATESTRUCT lpcs)
: {
: // Create toolbar at the top of the generic window
: ToolBar.Create(this)
: ToolBar.LoadToolBar(IDR_MAINFRAME))
: }

: Thanks for any help

: David Mc Kenna

I'm assuming here that the CWnd is your top-level window. Derive a
class from CToolbar, add a handler for WM_IDLEUPDATECMDUI as below. If
your CWnd is not the main window of your application, you will also need
to modify its parent frame window to pass the WM_IDLEUPDATECMDUI message
on to the CWnd's toolbar using SendMessageToDecendants().

LRESULT CYourToolBar::OnIdleUpdateCmdUI(WPARAM wParam,
LPARAM lParam)
{
if (IsWindowVisible())
{
CFrameWnd* pParent = (CFrameWnd*)GetParent();
if (pParent)
OnUpdateCmdUI(pParent, (BOOL)wParam);
}
return 0L;
}

That's about it...
--
/ ___| / ___| __ _ _ __ ___ ___| | I do not speak for
\___ \ | | _ / _` | '_ \ / _ \/ __| '_ \ Tata Unisys or
___) | | |_| | (_| | | | | __/\__ \ | | |Nationwide Ins.
|____(_) \____|\__,_|_| |_|\___||___/_| |_|------------------

0 new messages