Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Attaching to a CWnd pSite does not work
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Attaching to a CWnd pSite does not work

 Post Reply Post Reply
Author
Message
fredwobus View Drop Down
Newbie
Newbie
Avatar

Joined: 02 September 2004
Location: Austria
Status: Offline
Points: 22
Post Options Post Options   Thanks (0) Thanks(0)   Quote fredwobus Quote  Post ReplyReply Direct Link To This Post Topic: Attaching to a CWnd pSite does not work
    Posted: 03 November 2004 at 7:38am
Hi,

In my application I need a toolbar (with codejock-style flashy look&feel), which isn't docked to a CMainFrm or any other FrameWnd, but simply fixed inside the window of a dialog.
The toolbar should be permanently docked to the window just like the toolbar in the CHeroesView of the Common\Advanced sample.

I am trying to adapt the DynamicPopups sample to my needs (using Xtreme Toolkit 9.51)

I want the undo toolbar to be shown in the CDynamicPopupsView instead of it being docked to the CMainFrm.
Modifying the sample, the toolbar is created in CDynamicPopupsView::OnInitialUpdate() and moved into position in  CDynamicPopupsView::OnSize() using CalcDockingLayout() - (just like CHeroesView::OnSize from the Advanced Sample).
The OnCreateControl method also moved from the CMainFrm class to the CDynamicPopupsView class.

The toolbar is created and in the right place, the Add and Remove buttons work, but the "Undo popup" button ID_BUTTON_POPUP does not behave correctly.
The OnCreateControl method is not called for the ID_BUTTON_UNDO control, which creates the custom CControlUndo control.
Therefore the button pops up a default menu with one disabled entry [Undo] (just like the default in the RC file.

Investigating the problem I found the difference in behaviour in CXTPControls::AddMenuItem (XTPControls.cpp:117). That is the place where the pSite is determined to which the WM_XTP_CREATECONTROL message is sent.

In my modified application the WM_XTP_CREATECONTROL message is not sent to my CDynamicPopupsView (which has a handler for it creating the custom CControlUndo control), but to some different window, where it does nothing.


If you read this far, you can imagine what I am asking - How do I make sure my commandbar gets a valid pSite, which receives its messages such as WM_XTP_CREATECONTROL ????

Note, that I create the toolbar in CDynamicPopupsView::OnInitialUpdate() using the this pointer as the pParentWnd.


If you need my example project or any more code or info, let me know.

Thanks,
   Fred


Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 03 November 2004 at 9:01am

I made all same and it works.

May be you forget to add ON_XTP_CREATECONTROL() macro to message map?

 

Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
fredwobus View Drop Down
Newbie
Newbie
Avatar

Joined: 02 September 2004
Location: Austria
Status: Offline
Points: 22
Post Options Post Options   Thanks (0) Thanks(0)   Quote fredwobus Quote  Post ReplyReply Direct Link To This Post Posted: 03 November 2004 at 9:57am
Yes I have a correct message handler for ON_XTP_CREATECONTROL in CDynamicPopupsView.

It only works if the menu is loaded by the OnCreateControl in CMainFrm.
Try again and but remove the ON_XTP_CREATECONTROL() macro from the message map in CMainFrm.
The button popup in the CDynamicPopupsView window should now show the [Undo] menu.
It never shows the menu assembled in CControlUndo::OnCalcDynamicSize, because the
CControlUndo class is never instantiated for that popup.
The handler CDynamicPopupsView::OnCreateControl  is never called for (lpCreateControl->nID == ID_BUTTON_UNDO). Therefore we do not get the chance to insert our own control class.

Cheers,

Fred



Edited by fredwobus
Back to Top
fredwobus View Drop Down
Newbie
Newbie
Avatar

Joined: 02 September 2004
Location: Austria
Status: Offline
Points: 22
Post Options Post Options   Thanks (0) Thanks(0)   Quote fredwobus Quote  Post ReplyReply Direct Link To This Post Posted: 04 November 2004 at 2:52am
Hi Oleg,

I googled this forum and found some help in the article https://forum.codejock.com/forum_posts.asp?TID=489 "Topic: Paint UI with mix of themes"

Although apparently unrelated it does offer a crucial piece of adivice - " try to call pCommadnBars->SetSite() "

I now got the DynamicPopups sample to work without the initialisation for the CMainFrm.

The commandbars now work within the CDynamicPopupsView like so:
The red code is normally done by InitCommandBars() in a FrameWnd. As I donÄt have one here (just a CDialog) that never got called, and the command bar didn't have the correct pSite pointer to send its XTP_xx messages to.



void CDynamicPopupsView::OnInitialUpdate()
{
    CFormView::OnInitialUpdate();
    CXTPCommandBars* pCommandBars = CXTPCommandBars::CreateCommandBars();

    m_pToolBar = new CXTPToolBar();
    m_pToolBar->CreateToolBar(WS_VISIBLE|WS_CHILD|CBRS_TOOLTI PS, this);
    m_pToolBar->LoadToolBar(IDR_TOOLBAR_EXT);

    m_pToolBar->SetCommandBars(pCommandBars);
    pCommandBars->SetSite(this);


    m_pToolBar->GetControls()->Remove(m_pToolBar->GetCo ntrol(0));
    CXTPControl* pControl = m_pToolBar->GetControls()->Add(xtpControlButtonPopup,
                                                                           ID_BUTTON_POPUP, _T(""), 0);
    pControl->SetFlags(xtpFlagManualUpdate);


    ResizeParentToFit();
    m_wndList.AddString(_T("Undo Edit"));
    m_wndList.AddString(_T("Undo Resize"));
}



Cheers, Fred.

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.