Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Subclassing Windows Toolbar Control...

Posted on 1998-06-16
10
Medium Priority
?
584 Views
Last Modified: 2013-11-20
Hi,

I am trying to create an OCX, which subclasses the windows
toolbar control. After realizing that the Visual C++ 5.0
Wizards doesn't give you the option of direct subclassing
the toolbar control, I am stuff at this point.

Does any know if such a subclassing is possible in an OCX
(specifically for a toolbar control) ?

Thanks in advance and your cooperation will be appreciated.

Baig
0
Comment
Question by:baigmz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 400 total points
ID: 1317999
Yes you can subclass toolbar common control. Override PreCreatewindow virtual function in COleControl derived class and add code
BOOL CSampleCtrl::PreCreateWindow( CREATESTRUCT& cs )
{
    cs.lpszClass = _T("TOOLBARCLASSNAME");    
return COleControl::PreCreateWindow(cs);
}

Also override IsSubclassedControl and return TRUE from this function
BOOL CSampleCtrl::IsSubclassedControl( ){    return TRUE;}
0
 

Author Comment

by:baigmz
ID: 1318000
Hi,

Thanks for your answer. I followed what you asked me to do and built the OCX. But when wanted to test the ActiveX Control using the ActiveX Control Test Container, which comes along with the Visual C++ 5.0 developer studio, I had a program crash. I can't figure out what is exactly going wrong as I am new to ActiveX/OLE controls.

Can you please let me know if there is something else I need to do to get the toolbar ? Do I have to add code to add the buttons and strings necessary for its construction ? If yes, then where should I do this ?

A quick reply will be appreciated.

Thanks,
Baig

0
 
LVL 7

Expert Comment

by:galkin
ID: 1318001
It should work. The only one thing i have fogotten is to modify OnDraw member function, DoSuperClassPaint should be called.
    void CSampleCtrl::OnDraw( CDC* pdc, const CRect& rcBounds,
        const CRect& rcInvalid )    
{    
DoSuperclassPaint( pdc, rcBounds );
}

For more information see "ActiveX Controls: Subclassing a Windows Control" in VC++ help.

If your control craches launch it in debuger specifying Test Container as an executable to debug with. Then you will be able to discover where crach occurs
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

Author Comment

by:baigmz
ID: 1318002
Hi,

I just found out that it is possible to create the subclassing of the toolbar with ToolbarWindow32, not TOOLBARCLASSNAME. I wonder why this is so where TOOLBARCLASSNAME is defined as ToolbarWindow32.

I have one last question.
Can you give me a sample code, which creates 1 button on this toolbar. I have been trying to do it inside the OnCreate function of COleControl for the toolbar but when I insert the control inside the ActiveX test container, I get only a sqaure without any button color, text or bitmap on it. I sent messages (using SendMessage) to the parent window and with various TB_ADDSTRING, TB_ADDBITMAP, and TB_ADDBUTTONS messages to do this.

Waiting for your kind reply...

Thanks,
Baig
0
 

Author Comment

by:baigmz
ID: 1318003
Hi,

I managed to get the toolbar up (with the bitmap and string) but
now the problem is that the string is getting truncated. I resized the buttons for a bigger size, still the buttons are truncated on a container. Any idea why ?
0
 
LVL 7

Expert Comment

by:galkin
ID: 1318004
I guggest you declaring a member variable of type CToolBarCtrl in your COleControl derived class and attaching to control that is toolbar window juust after window has been created. Then you can take advantage from CtoolBarCtrl class members. You must handle WM_DESTROY message and call Detach function for CToolBarCtrl to detach it from control's window.
0
 

Author Comment

by:baigmz
ID: 1318005
Hi,

I followed you last instruction on creating a toolbar but I couldn't attach. Here the part of my code :

int CMYToolBarCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (COleControl::OnCreate(lpCreateStruct) == -1)
            return -1;
      
      // TODO: Add your specialized creation code here
      INITCOMMONCONTROLSEX lpInitCtrls;
      lpInitCtrls.dwSize = sizeof(lpInitCtrls);
      lpInitCtrls.dwICC = ICC_BAR_CLASSES;
      BOOL bDone = InitCommonControlsEx(&lpInitCtrls);
      ASSERT(bDone != FALSE);

      bDone = m_wndToolBar.Create(WS_CHILD, CRect(0,0,0,0),
                                    this, IDR_TOOLBAR1);

      return 0;
}

I add a few buttons to it and complete the compilation without
any errors. When I drag and drop this OLE control on a form (in VB) the control appears as a window and the actual toolbar appears at the top of the form as another window. Why are there two different windows ? This causes wrong processing of events.

I tried the following line after the create :

 this.Attach(m_wndToolBar); // This leads to a crash.


I need your kind help on this. Do you have any sample code for creating this kind of toolbar OLE control ?
0
 
LVL 7

Expert Comment

by:galkin
ID: 1318006
Do not call create for embedded CToolBarCtrl! Call Attach only and Detach from OnDestroy.
0
 

Author Comment

by:baigmz
ID: 1318007
Hi

Bad news that I have just messed up my toolbar creation code.
Good news is I have started fresh. I want to create a toolbar
as an ActiveX control as you know very well by now. Can you
just give me a sample code/function which I can call from the
CToolBarCtrlEx::OnCreate function ?

This will be of a great help to me.
0
 

Author Comment

by:baigmz
ID: 1318008
Can anyone kindly respond to my question ? (Please)...baigmz
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question