Link to home
Start Free TrialLog in
Avatar of baigmz
baigmz

asked on

Subclassing Windows Toolbar Control...

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
ASKER CERTIFIED SOLUTION
Avatar of galkin
galkin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of baigmz
baigmz

ASKER

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

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
Avatar of baigmz

ASKER

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
Avatar of baigmz

ASKER

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 ?
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.
Avatar of baigmz

ASKER

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 ?
Do not call create for embedded CToolBarCtrl! Call Attach only and Detach from OnDestroy.
Avatar of baigmz

ASKER

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.
Avatar of baigmz

ASKER

Can anyone kindly respond to my question ? (Please)...baigmz