Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Subclassing Windows Toolbar Control...

Posted on 1998-06-16
10
Medium Priority
?
588 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 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

963 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