15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


CComboBox and WM_CHAR

SBERTRAN.US.ORACLE.COM -- SBERTRAN@us.oracle.com
Wednesday, August 28, 1996

Environment:  VC++ 1.52, Win 3.1, Win 95, NT 3.5 
 
Does anyone out there know of a way to trap WM_CHAR messages to the edit box 
portion of a subclassed combo box? 
 
I have a VBX that utilizes the MFC for its dialogs (it is sort of a Common 
Dialog VBX) and a C API layer for API's.  This VBX is being used in a VB 
application. 
 
In many of the dialogs a common CComboBox class is used.  What I need to do is 
trap the WM_CHAR message when the user types in a "high-ASCII" character (such 
as Alt and then 0,1,9,2).  Our applications prevent the user from entering 
keys that are not valid in the OEM and ASCII character sets.  Since I am 
already subclassing the combo box on the dialog, I cannot re-subclass the edit 
box portion of it (or can I?).  I also tried using SetWindowLong to re-route 
messages to the edit box (that GPF'ed). 
 
Thank you in advance for your time... 
 
********************************************************************* 
* Shawn Bertrand, Software Engineer                                 * 
* 14 Middle Street      	                                    * 
* Nashua, NH  03060-6417             E-mail: sbertran@us.oracle.com * 
*                                                                   * 
*        Mr. Burns: "Use an open-faced club! A sand wedge!"         * 
*            Homer: "Mmmmm... open-faced club sandwich."            * 
********************************************************************* 




Jeff Pek -- jpek@bizserve.com
Friday, August 30, 1996

[Mini-digest: 2 responses]

Try PretranslateMessage()

HTH - Jeff Pek

----------
> From: SBERTRAN.US.ORACLE.COM 
> To: mfc-l@netcom.com
> Subject: CComboBox and WM_CHAR
> Date: Wednesday, August 28, 1996 12:28 PM
> 
> Environment:  VC++ 1.52, Win 3.1, Win 95, NT 3.5 
>  
> Does anyone out there know of a way to trap WM_CHAR messages to the edit
box 
> portion of a subclassed combo box? 
>  
> I have a VBX that utilizes the MFC for its dialogs (it is sort of a
Common 
> Dialog VBX) and a C API layer for API's.  This VBX is being used in a VB 
> application. 
>  
> In many of the dialogs a common CComboBox class is used.  What I need to
do is 
> trap the WM_CHAR message when the user types in a "high-ASCII" character
(such 
> as Alt and then 0,1,9,2).  Our applications prevent the user from
entering 
> keys that are not valid in the OEM and ASCII character sets.  Since I am 
> already subclassing the combo box on the dialog, I cannot re-subclass the
edit 
> box portion of it (or can I?).  I also tried using SetWindowLong to
re-route 
> messages to the edit box (that GPF'ed). 
>  
> Thank you in advance for your time... 
>  
> ********************************************************************* 
> * Shawn Bertrand, Software Engineer                                 * 
> * 14 Middle Street      	                                    * 
> * Nashua, NH  03060-6417             E-mail: sbertran@us.oracle.com * 
> *                                                                   * 
> *        Mr. Burns: "Use an open-faced club! A sand wedge!"         * 
> *            Homer: "Mmmmm... open-faced club sandwich."            * 
> ********************************************************************* 
> 
-----From: David Little 

You won't ever get a WM_CHAR for an  key combination...You want
WM_SYSCHAR or WM_SYSKEYDOWN/UP....

David





Derek F. Groft - UTL -- groftde@ebs.ac.com
Monday, September 02, 1996

I had to do a similar thing once.  Here is some code ( it should work! let
me know if it doesn't).

I created my own CComboEdit class which derives from CEdit.  Once this class
is created with the edit portion of the combo box, you can get ahold of
any messages you want.  In this case, I catch the WM_CHAR message to try
to guess what the user is trying to type. 

Hope this helps,
Derek
----------

class CMyComboBox;

class CMyComboEdit : public CEdit
{
public:
	CMyComboEdit();
	CMyComboBox * m_pComboBox;
	virtual ~CMyComboEdit();
protected:
	//{{AFX_MSG(CUtlComboEdit)
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

class AFX_EXT_CLASS CMyComboBox : public CComboBox, public CUtlWidget
{
public:
	CMyComboBox();
	virtual ~CUtlComboBox();
// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMyComboBox)
	protected:
	virtual void PreSubclassWindow();
	//}}AFX_VIRTUAL

	// Generated message map functions
protected:
	//{{AFX_MSG(CMyComboBox)
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
private:
	CMyComboEdit * m_pEdit;
};

/////////////////////////////////////////////
//////////////CMyComboBox
/////////////////////////////////////////////

void CMyComboBox::PreSubclassWindow() 
{
	ASSERT( (GetStyle() & CBS_OWNERDRAWFIXED) == 0 );

	CComboBox::PreSubclassWindow();

	POINT p = {1,1};
	HWND h = ChildWindowFromPoint(p)->GetSafeHwnd();

	m_pEdit = new CMyComboEdit;
	ASSERT( m_pEdit );

	m_pEdit->SubclassWindow( h );
	m_pEdit->m_pComboBox = this;
}
/////////////////////////////////////////////
////////////CMyComboEdit
/////////////////////////////////////////////

void CMyComboEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	CEdit::OnChar(nChar, nRepCnt, nFlags);

	if ( nChar == VK_BACK )
	{
		CEdit::OnChar(nChar, nRepCnt, nFlags);
	}

	CString source;
	GetWindowText(source);

	int target = m_pComboBox->FindString(0, source);

	if ( target == CB_ERR ) 
	{
		return;
	} 

	DWORD d = m_pComboBox->GetEditSel();
	int start = HIWORD(d);

	m_pComboBox->SetCurSel(target);
	m_pComboBox->SetEditSel(start,-1);
}



Michael Shipkowski -- sasmsx@unx.sas.com
Wednesday, September 04, 1996

[groftde@ebs.ac.com (Derek F. Groft - UTL)] Writes:
> 
> I had to do a similar thing once.  Here is some code ( it should work! let
> me know if it doesn't).
> 
> I created my own CComboEdit class which derives from CEdit.  Once this class
> is created with the edit portion of the combo box, you can get ahold of
> any messages you want.  In this case, I catch the WM_CHAR message to try
> to guess what the user is trying to type. 
> 
> Hope this helps,
> Derek
> ----------
> 
> class CMyComboBox;
> 
> class CMyComboEdit : public CEdit
> {
> public:
> 	CMyComboEdit();
> 	CMyComboBox * m_pComboBox;
> 	virtual ~CMyComboEdit();
> protected:
> 	//{{AFX_MSG(CUtlComboEdit)
> 	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
> 	//}}AFX_MSG
> 	DECLARE_MESSAGE_MAP()
> };
> 
> class AFX_EXT_CLASS CMyComboBox : public CComboBox, public CUtlWidget
> {
> public:
> 	CMyComboBox();
> 	virtual ~CUtlComboBox();
> // Overrides
> 	// ClassWizard generated virtual function overrides
> 	//{{AFX_VIRTUAL(CMyComboBox)
> 	protected:
> 	virtual void PreSubclassWindow();
> 	//}}AFX_VIRTUAL
> 
> 	// Generated message map functions
> protected:
> 	//{{AFX_MSG(CMyComboBox)
> 	//}}AFX_MSG
> 
> 	DECLARE_MESSAGE_MAP()
> private:
> 	CMyComboEdit * m_pEdit;
> };
> 
> /////////////////////////////////////////////
> //////////////CMyComboBox
> /////////////////////////////////////////////
> 
> void CMyComboBox::PreSubclassWindow() 
> {
> 	ASSERT( (GetStyle() & CBS_OWNERDRAWFIXED) == 0 );
> 
> 	CComboBox::PreSubclassWindow();
> 
> 	POINT p = {1,1};
> 	HWND h = ChildWindowFromPoint(p)->GetSafeHwnd();
> 
> 	m_pEdit = new CMyComboEdit;
> 	ASSERT( m_pEdit );
> 
> 	m_pEdit->SubclassWindow( h );
> 	m_pEdit->m_pComboBox = this;
> }
> /////////////////////////////////////////////
> ////////////CMyComboEdit
> /////////////////////////////////////////////
> 
> void CMyComboEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
> {
> 	CEdit::OnChar(nChar, nRepCnt, nFlags);
> 
> 	if ( nChar == VK_BACK )
> 	{
> 		CEdit::OnChar(nChar, nRepCnt, nFlags);
> 	}
> 
> 	CString source;
> 	GetWindowText(source);
> 
> 	int target = m_pComboBox->FindString(0, source);
> 
> 	if ( target == CB_ERR ) 
> 	{
> 		return;
> 	} 
> 
> 	DWORD d = m_pComboBox->GetEditSel();
> 	int start = HIWORD(d);
> 
> 	m_pComboBox->SetCurSel(target);
> 	m_pComboBox->SetEditSel(start,-1);
> }
> 




| Вернуться в корень Архива |