Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I try to create my own ActiveX Control that is shown as a toolbar. For that I used the VS2010 Wizard to create a MFC ActiveX Control.

After the automatic generation of some classes I add the member
C++
CToolBar m_toolbar
and the message handler for the "WM_CREATE" message which creates the method "OnCreate(...)".

C++
int MyCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (COleControl::OnCreate(lpCreateStruct) == -1)
	return -1;

    // TODO:  Add your specialized creation code here
    m_toolbar.Create(this, WS_CHILD | WS_VISIBLE, IDC_MYCTRL_TOOLBAR);
    m_toolbar.LoadBitmap(IDB_TEXTCOMPLEMENT_TOOLBAR);
    m_toolbar.SetButtons(NULL, 5);

    m_toolbar.SetButtonInfo(0, IDC_MYCTRL_NEW,	    TBBS_BUTTON, 0);
    m_toolbar.SetButtonInfo(1, IDC_MYCTRL_DELETE,   TBBS_BUTTON, 1);
    m_toolbar.SetButtonInfo(2, IDC_MYCTRL_MODIFY,   TBBS_BUTTON, 2);
    m_toolbar.SetButtonInfo(3, IDC_MYCTRL_PREVIOUS, TBBS_BUTTON, 3);
    m_toolbar.SetButtonInfo(4, IDC_MYCTRL_NEXT,	    TBBS_BUTTON, 4);

    return 0;
}


C++
IDB_TEXTCOMPLEMENT_TOOLBAR
is a bitmap for the 5 buttons.

I do not get any error during compilation or runtime. The Create() and all other function finishing successfully.

Now I create a MFC Project with a Doc/View Architecture (also with the VS 2010 Wizard). To this project I add my control with the class wizard which generates a wrapper.
In the View-class' "OnCreate()" function I do the following:

C++
int CMFC_OCXView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CView::OnCreate(lpCreateStruct) == -1)
    	return -1;
    
    // TODO:  Add your specialized creation code here
    m_toolbarCtrl.Create(NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 200, 200), this, 1278);
    
    return 0;
}


where m_toolbarCtrl is a member of the type of my control's wrapper.

When I start the MFC application nothing is shown in the view.
I tried already to show other components on the view and they worked fine. E.g. I created some buttons in my ActiveX Control project the same way I did with the CToolBar.

I don't find the mistake why my toolbar is never shown.
Posted
Comments
[no name] 23-Jan-14 15:13pm    
Try adding CBRS_TOP to the Create() style mask.
DFaeuster 24-Jan-14 1:56am    
Nope, this did not solve the problem.

your MFX app resources should be a bitmap and a toolbar resource, with your used ID auf 1278.

Overview: http://msdn.microsoft.com/en-us/library/f9hbax0b.aspx[^]
Toolbar Editor: http://msdn.microsoft.com/en-us/library/kfb33f94.aspx[^]
 
Share this answer
 
Comments
DFaeuster 24-Jan-14 5:42am    
This did not help either.
Btw: why should I define the toolbar and its bitmap in the MFC app? Should not it be the way that an ActiveX control comes with all stuff it needs?
KarstenK 24-Jan-14 5:49am    
it is the way the MFC works. This Create call requires such bitmap (in 16 bit) and a toolbar resource.

Or create it like you did it in the ActiveX-Control
DFaeuster 24-Jan-14 8:24am    
I did not know that I also need a toolbar resource if I dynamically create the toolbar. But let me check it with a clean project. I will set-up everything again since I tried a lot of different approaches. Maybe they are disturbing each other in some way.
So, after playing around with new and clean projects I found the problem.
As described, the creation of my toolbar was always successful but I never was able to see something. The cause of this was that my toolbar was drawn where I could not see it.
You have to add the following bold marked lines to the "OnCreate"-method of the ActiveX Control:

C++
int MyCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (COleControl::OnCreate(lpCreateStruct) == -1)
	return -1;
 
    // TODO:  Add your specialized creation code here
    m_toolbar.Create(this, WS_CHILD | WS_VISIBLE, IDC_MYCTRL_TOOLBAR);
    m_toolbar.LoadBitmap(IDB_TEXTCOMPLEMENT_TOOLBAR);
    m_toolbar.SetButtons(NULL, 5);
 
    m_toolbar.SetButtonInfo(0, IDC_MYCTRL_NEW,	    TBBS_BUTTON, 0);
    m_toolbar.SetButtonInfo(1, IDC_MYCTRL_DELETE,   TBBS_BUTTON, 1);
    m_toolbar.SetButtonInfo(2, IDC_MYCTRL_MODIFY,   TBBS_BUTTON, 2);
    m_toolbar.SetButtonInfo(3, IDC_MYCTRL_PREVIOUS, TBBS_BUTTON, 3);
    m_toolbar.SetButtonInfo(4, IDC_MYCTRL_NEXT,	    TBBS_BUTTON, 4);

    CRect rc;
    GetClientRect(&rc);
    rc.bottom = rc.top + 30;
    m_toolbar.MoveWindow(&rc);

    return 0;
}


This will move the toolbar down to the viewable area of the CView or whereever you want to add the toolbar.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900