Solved

Trapping keydown events from a combo box in the toolbar

Posted on 2000-03-10
13
776 Views
Last Modified: 2013-11-20
For some reason, the EE search engine is not working for me - I have seen some things related to this issue but can't get to them. At any rate, how can I trap keydown events from a combo box which is created as a part of the toolbar?? I'm using the combo box as a kind of "address bar" like IE to drive a CHTMLView.

Thanks...
0
Comment
Question by:captainkirk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
13 Comments
 
LVL 2

Accepted Solution

by:
bratt030900 earned 125 total points
ID: 2606594

Create your own class derived from CComboBox and overwrite OnKeyDown:
void CMyComboBox::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags )
{
 #ifdef _WIN32
            GetParent()->SendMessage(WM_COMMAND,
            MAKEWPARAM(GetDlgCtrlID(), MY_LEFTCLICK),
        LPARAM(m_hWnd));
#else            
            GetParent()->SendMessage(WM_COMMAND,
            GetDlgCtrlID(),
            MAKELONG(m_hWnd, MY_LEFTCLICK));
#endif
  CComboBox::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags );

}
-- you didn't specify what you are trying to do or if you want this to send messages to other classes?
-- we've created classes similar to this for our formated CEdit and for OnChar()
0
 
LVL 4

Author Comment

by:captainkirk
ID: 2612657
bratt- actually I do wish to send the message to the CHTMLView derived class. I'll give your suggestion a shot and get back to you.
0
 
LVL 4

Author Comment

by:captainkirk
ID: 2613031
bratt- I can't seem to get it working... I derived a class from CComboBox, overrode the OnKeyDown handler and replaced the dynamic creation sequence to create a combo of the new type, but the handler never gets called. The combo is created as a child of a third-party toolbar, by the way. Any ideas??
0
Industry Leaders: 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!

 
LVL 2

Expert Comment

by:bratt030900
ID: 2613890
It seems to go into the derived class:
I've declared a CMyComboBox in my Mainframe class and
dynamically created here is the CMyComboBox

// CPP file ---------------------------------------
CMyComboBox::CMyComboBox(){}
CMyComboBox::~CMyComboBox(){}
BEGIN_MESSAGE_MAP(CMyComboBox, CWnd)
      //{{AFX_MSG_MAP(CMyComboBox)
      ON_WM_KEYDOWN()
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CMyComboBox::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags )
{  
      // do anything here including send message to parent..
      CComboBox::OnKeyDown(nChar,nRepCnt,nFlags);
}

// Header file ---------------------------------------
class CMyComboBox : public CComboBox
{
public:
      CMyComboBox();
      virtual ~CMyComboBox();
protected:
      //{{AFX_MSG(CMyComboBox)
      afx_msg void OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags );
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};


0
 
LVL 4

Author Comment

by:captainkirk
ID: 2613915
That's exactly what I have...
Here's how the combo is created:
(m_wndToolBar is a class derived from CToolBar)


const int nDropHeight = 100;

// create the combo box...
m_wndToolBar.SetButtonInfo(6, IDC_COMBO, TBBS_SEPARATOR, 600);

CRect rect;
m_wndToolBar.GetItemRect(6, &rect);
rect.top = 1;
rect.bottom = rect.top + nDropHeight;
rect.left += 5;

if (!m_wndToolBar.m_combo.Create(CBS_DROPDOWN | WS_VISIBLE | WS_TABSTOP, rect, &m_wndToolBar, IDC_COMBO))
{
     TRACE0("Failed to create combo box\n");
     return FALSE;
} // end if
0
 
LVL 2

Expert Comment

by:bratt030900
ID: 2614028
The only diffence I see from mine is you have your ComboBox as a member in another CToolbar dirived class while mine is declared in the mainframe - (I do have other MS switches turned on too?- mine is enabled when the correct  view is open). How is your class CToolbar declared?
if (!m_cboxFind.Create(
      WS_CHILD|WS_BORDER|WS_VISIBLE|CBS_DROPDOWN|WS_DISABLED|CBS_AUTOHSCROLL ,
      findRect, &m_wndToolBar, IDC_FINDNEXT))
{
      TRACE("Failed to create combobox inside toolbar\n");
      return -1;      // fail to create
}
0
 
LVL 4

Author Comment

by:captainkirk
ID: 2614090
in MainFrm.h:

protected:
CStatusBar m_wndStatusBar;
CMyToolBar m_wndToolBar;
..
..
..
class CMyToolBar : public COXCoolToolBar
{
public:
CTVGComboBox    m_combo;
CFont            m_font;
}; // end class CMyToolBar

// COXCoolToolBar is a third party control...

// CTVGComboBox is the class derived from CComboBox...

class CTVGComboBox : public CComboBox
{
// Construction
public:
     CTVGComboBox();

// Attributes
public:

// Operations
public:

// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CTVGComboBox)
      protected:
      virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
      //}}AFX_VIRTUAL

// Implementation
public:
      virtual ~CTVGComboBox();

      // Generated message map functions
protected:
      //{{AFX_MSG(CTVGComboBox)
      afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
      //}}AFX_MSG

      DECLARE_MESSAGE_MAP()
}; // end class CTVGComboBox

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_TVGCOMBOBOX_H__2A2E0F26_F8FC_11D3_B9CA_005004187C4C__INCLUDED_)

The OnKeyDown() override is in the derived class, as you can see... what could be preventing the message handler from getting called??

might have to give you more points for this snake in the grass...

0
 
LVL 2

Expert Comment

by:bratt030900
ID: 2614760
Can I see the CPP of CMyToolBar - this is one tough snake that I don't see
0
 
LVL 4

Author Comment

by:captainkirk
ID: 2616432
it's alot to post here... could I get your email, and I'll send the .cpp / .h
0
 
LVL 4

Author Comment

by:captainkirk
ID: 2617427
Adjusted points from 75 to 125
0
 
LVL 4

Author Comment

by:captainkirk
ID: 2617428
bratt - I'm increasing the points for your efforts...
0
 
LVL 4

Author Comment

by:captainkirk
ID: 2617432
thanks for the help...
0
 
LVL 4

Author Comment

by:captainkirk
ID: 2617437
For all interested, the full solution involves overriding PreTranslateMessage() for the combo box or the parent toolbar and if the message is a WM_KEYDOWN, switching on the key code...
0

Featured Post

Industry Leaders: 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: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…

687 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