-
March 6th, 2022, 05:35 PM
#1
Toolbar in MFC
Hello
i try to create a simple toolbar with a mfc but the compiler can't find the class CToolbar:
Code:
#include <afxwin.h>
#include "resource.h"
class CResApp : public CWinApp
{
public:
BOOL InitInstance();
};
class TB: public CMFCToolBar;
class CResFrame : public CFrameWnd
{
public:
CResFrame()
{
Create(NULL, TEXT("Resources Fundamentals"));
}
};
BOOL CResApp::InitInstance()
{
m_pMainWnd = new CResFrame;
TB a;
a.Create(&m_pMainWnd);
m_pMainWnd->SetMenu(&hMenu);
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
class TB: public CMFCToolBar{
public:
TB(CResFrame *CRF){
Create(CRF,CBRS_TOP,IDR_TOOLBAR1);
}
}
CResApp theApp;
What's wrong?
-
March 6th, 2022, 07:23 PM
#2
Re: Toolbar in MFC
Ok, found the include. The following code is compiled without errors but the toolbar is not showed:
Code:
#include <afxwin.h>
#include<afxext.h>
#include "resource.h"
class CResApp : public CWinApp
{
public:
BOOL InitInstance();
};
//class TB : public CToolBar{};
class CResFrame : public CFrameWnd
{
public:
CResFrame()
{
Create(NULL, TEXT("Resources Fundamentals"));
}
};
BOOL CResApp::InitInstance()
{
m_pMainWnd = new CResFrame;
HICON hIcon = LoadIcon(IDI_ICON);
HICON hPrev = m_pMainWnd->SetIcon(hIcon, FALSE);
CMenu hMenu;
hMenu.LoadMenu(IDR_MENU);
CToolBar a;
a.Create(m_pMainWnd, CBRS_TOP, IDR_TOOLBAR1);
m_pMainWnd->SetMenu(&hMenu);
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
CResApp theApp;
-
March 7th, 2022, 03:27 AM
#3
Re: Toolbar in MFC
You don't see your toolbar because it doesn't belong to any frame window.
Check it out: Toolbars
Victor Nijegorodov
-
March 7th, 2022, 05:37 AM
#4
Re: Toolbar in MFC
 Originally Posted by VictorN
You don't see your toolbar because it doesn't belong to any frame window.
Check it out: Toolbars
Did it with the following code:
Code:
a.Create(m_pMainWnd, CBRS_TOP, IDR_TOOLBAR1);
-
March 7th, 2022, 06:54 AM
#5
Re: Toolbar in MFC
 Originally Posted by Quasar999
Did it with the following code:
Code:
a.Create(m_pMainWnd, CBRS_TOP, IDR_TOOLBAR1);
With this "code" you only create some toolbar. Nothing else.
Again: Check it out: Toolbars
Victor Nijegorodov
-
March 9th, 2022, 06:46 PM
#6
Re: Toolbar in MFC
1) When I created a toolbar on a dialog, I needed to call LoadToolBar() after Create()
2) is a local variable, so it will go out of scope when the function exits. Maybe it needs to be a member variable.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|