Print Page | Close Window

Problem Responding CXTPControlCustom Button Click

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=17144
Printed Date: 01 December 2024 at 3:24pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Problem Responding CXTPControlCustom Button Click
Posted By: tommyvee
Subject: Problem Responding CXTPControlCustom Button Click
Date 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



Replies:
Posted By: tommyvee
Date 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.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net