Solved

Trapping keydown events from a combo box in the toolbar

Posted on 2000-03-10
13
744 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 69
iSeries FTP Exit Program 8 124
ODBC Connection Logging, ADO.NET 6 56
ShiftLeft challenge 21 76
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 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

15 Experts available now in Live!

Get 1:1 Help Now