Solved

Subclassing Windows Toolbar Control...

Posted on 1998-06-16
10
569 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 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