Solved

Trapping keydown events from a combo box in the toolbar

Posted on 2000-03-10
13
736 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
  • 9
  • 4
13 Comments
 
LVL 2

Accepted Solution

by:
bratt030900 earned 125 total points
Comment Utility

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
Comment Utility
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
Comment Utility
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
 
LVL 2

Expert Comment

by:bratt030900
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Author Comment

by:captainkirk
Comment Utility
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
Comment Utility
Can I see the CPP of CMyToolBar - this is one tough snake that I don't see
0
 
LVL 4

Author Comment

by:captainkirk
Comment Utility
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
Comment Utility
Adjusted points from 75 to 125
0
 
LVL 4

Author Comment

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

Author Comment

by:captainkirk
Comment Utility
thanks for the help...
0
 
LVL 4

Author Comment

by:captainkirk
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now