Problem Responding CXTPControlCustom Button Click |
Post Reply |
Author | |
tommyvee
Groupie Joined: 21 August 2007 Location: United States Status: Offline Points: 11 |
Post Options
Thanks(0)
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 createdUINT 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* controlCXTPControlCustom* pCustomButton = CXTPControlCustom::CreateControlCustom(&m_wndTVButton1); // Set the ID of the custom control to the ID of the radio buttonpCustomButton->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 |
|
tommyvee
Groupie Joined: 21 August 2007 Location: United States Status: Offline Points: 11 |
Post Options
Thanks(0)
|
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. |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |