Solved

Combobox events with "CBS_DROPDOWN" style.

Posted on 2002-05-30
8
983 Views
Last Modified: 2013-11-20
Hi,
I derive a a class from CComboBox (CMyComboBox), and in it I capture some events such as OnKillFocus, and PreTranslateMessage (in order to handle Enter-pressing, and Escape-pressing). The combo can be created with CBS_DROPDOWN style or with CBS_DROPDOWNLIST style.
If I create it with CBS_DROPDOWNLIST than everything is fine, but when using CBS_DROPDOWN style, a EditBox is created (as a child of the combobox) and The combobox itself does not get the events.
How can I handle the WM_KILLFOCUS events in CMyComboBox class when using CBS_DROPDOWN style ???

Thanks,
Yoav.
0
Comment
Question by:yoavo
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7044245
Try this

// The following code shows how to subclass the edit control and list box
// controls inside a combo box. It uses WM_CTLCOLOR for subclassing.
// CSuperComboBox represents the combo box.
HBRUSH CSuperComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
   if (nCtlColor == CTLCOLOR_EDIT)
   {
      //Edit control
      if (m_edit.GetSafeHwnd() == NULL)
         m_edit.SubclassWindow(pWnd->GetSafeHwnd());
   }
   else if (nCtlColor == CTLCOLOR_LISTBOX)
   {
      //ListBox control
      if (m_listbox.GetSafeHwnd() == NULL)
         m_listbox.SubclassWindow(pWnd->GetSafeHwnd());
   }
   HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
   return hbr;
}


GOOD LUCK
0
 

Author Comment

by:yoavo
ID: 7044266
I dont think I like this solussion...
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7044271
It will work
another thing is that, How can I solve a microsoft bug in a direct way....


Regards

Roshmon

0
Independent Software Vendors: 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 4

Expert Comment

by:mblat
ID: 7044837
Did you try to everwrire REFLECTED CBN_KILLFOCUS?
In class wizard it is =CBN_KILLFOCUS?

0
 

Author Comment

by:yoavo
ID: 7044882
mblat,
You are wtite. this solves me the kill focus problem, but how can I catch enter/escape pressed ?
0
 
LVL 4

Expert Comment

by:mblat
ID: 7045006
Did you try to everwrire REFLECTED CBN_KILLFOCUS?
In class wizard it is =CBN_KILLFOCUS?

0
 
LVL 4

Expert Comment

by:mblat
ID: 7045016
Ok, it's not that simle actually, at list the way I know how to do it isn't. :-(

1. You need to sublclass CEdit control to CMyEdit.
2. Overwrite CMyEdit::OnGetDlgCode() and return DLGC_WANTALLKEYS from it.
3. Declare
CMyEdit m_edit as member variable of your CMyComboBox;
4. In your CMyComboBox owerwrite CMyComboBox::PreSubclassWindow.
5. After
CComboBox::PreSubclassWindow();
line put the following code:


CWnd* ce = GetWindow(GW_CHILD | GW_HWNDFIRST);
m_edit.SubclassWindow(ce->m_hWnd);

Now you can handle WM_KEYDOWN messages inside CMyEdit class...

Hope it helps...
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 50 total points
ID: 7045585
It's even easier than that:

BOOL CMyCombo::PreTranslateMessage(MSG* pMsg)
{
     if ( pMsg->message == WM_KEYDOWN) {
          if (pMsg->wParam == 27 ) {
               return(1); // eat ESC
          }
          if (pMsg->wParam == 13 ) {
               return(1); // eat Enter
          }
     }
     
     return CComboBox::PreTranslateMessage(pMsg);
}

-- Dan
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 47
Problem to event 3 112
moto 4g phone enable finger print 4 45
Problem to Office 1 40
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

762 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