Trapping keydown events from a combo box in the toolbar

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...
LVL 4
captainkirkAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
bratt030900Connect With a Mentor Commented:

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
 
captainkirkAuthor Commented:
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
 
captainkirkAuthor Commented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
bratt030900Commented:
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
 
captainkirkAuthor Commented:
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
 
bratt030900Commented:
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
 
captainkirkAuthor Commented:
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
 
bratt030900Commented:
Can I see the CPP of CMyToolBar - this is one tough snake that I don't see
0
 
captainkirkAuthor Commented:
it's alot to post here... could I get your email, and I'll send the .cpp / .h
0
 
captainkirkAuthor Commented:
Adjusted points from 75 to 125
0
 
captainkirkAuthor Commented:
bratt - I'm increasing the points for your efforts...
0
 
captainkirkAuthor Commented:
thanks for the help...
0
 
captainkirkAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.