Solved

Subclassing Windows Toolbar Control...

Posted on 1998-06-16
10
564 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
  • 6
  • 4
10 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 100 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now