Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Problem Responding  CXTPControlCustom Button Click
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Problem Responding CXTPControlCustom Button Click

 Post Reply Post Reply
Author
Message
tommyvee View Drop Down
Groupie
Groupie


Joined: 21 August 2007
Location: United States
Status: Offline
Points: 11
Post Options Post Options   Thanks (0) Thanks(0)   Quote tommyvee Quote  Post ReplyReply Direct Link To This Post Topic: Problem Responding CXTPControlCustom Button Click
    Posted: 23 August 2010 at 1:56am

I am updating an application that used a much older version of the CodeJock libraries.

The application has a complicated class that is derived from CButton used in a toolbar, so I would like to just use this class with CXTPControlCustom.
While the toolbar buttons appear fine, there is no response when they are clicked.
 
So I modified the Samples\CommandBars\CommonControls sample to add a CButton to the CommandBar using CXTPControlCustom to try to understand the problem. I am unable to get any action out of clicking the CXTPControlCustom CButton in the modified sample, either.
 
Seems like I am missing something obvious and I hope some CodeJock experts can help out.
 
 
Here is the code from the modified sample application, where I create the custom control.
 
int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)

{

  int iID = lpCreateControl->nID;

  // Create the Button control

  if (lpCreateControl->nID == ID_TVTOOLBAR_BMP2)

  {

     // Get the ID of the control currently being created

    UINT nID = lpCreateControl->nID;

    m_wndTVButton1.Create("TVButton1",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,

    CRect(0, 0, 70, 20), this, ID_TVTOOLBAR_BMP2);

    m_wndTVButton1.SetFocus();

    // Use m_wndTVButton1 to create a CXTPControlCustom* control

    CXTPControlCustom* pCustomButton = CXTPControlCustom::CreateControlCustom(&m_wndTVButton1);

    // Set the ID of the custom control to the ID of the radio button

    pCustomButton->SetID(nID);

    lpCreateControl->pControl = pCustomButton;

    return TRUE;

  }

Here is the code from the MESSAGE_MAP where I tried to catch the button click event (I tried various methods, none worked).

ON_COMMAND(ID_TVTOOLBAR_BMP2, OnTVButtonClicked)

ON_BN_CLICKED(ID_TVTOOLBAR_BMP2,OnTVButtonClicked)

ON_XTP_EXECUTE(ID_TVTOOLBAR_BMP2, OnTVButtonExecute)

and the simple functions that never get called are below.
 

void CMainFrame::OnTVButtonClicked()

{

   AfxMessageBox("TV Button Clicked Msg");

}

void CMainFrame::OnTVButtonExecute(NMHDR *pNMHDR,LRESULT *pResult)

{

   AfxMessageBox("TV Button Clicked Execute Msg");

}

Thanks for the help,

Tom
Back to Top
tommyvee View Drop Down
Groupie
Groupie


Joined: 21 August 2007
Location: United States
Status: Offline
Points: 11
Post Options Post Options   Thanks (0) Thanks(0)   Quote tommyvee Quote  Post ReplyReply Direct Link To This Post Posted: 05 September 2010 at 7:55pm
After a while I figured this out by wandering through the samples. To respond to a click on a CXTPControlCustom control, you need to use a MESSAGE_MAP defined in your custom control with an ON_CONTROL_REFLECT macro like,
ON_CONTROL_REFLECTION(BN_CLICKED, OnTVButtonClicked).

I am not sure why direct ON_COMMAND() macros in MainFrame.cpp message map do not work for CXTPControlCustom controls, but they don't and following the sample is not too hard. I would still like to understand why the messaging works this way.
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.172 seconds.