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

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


Dialogs and WM_CHAR

Michael Smolinski 4444 -- msmolins@glenayre.com
Monday, June 24, 1996

Hello everyone...

Windows 3.1
VC++ 1.51

I would like to process the WM_CHAR (OnChar()) message in a modal dialog box that has
no CEdit controls.  

I added the WM_CHAR message with the Class brouser and put a TRACE inside the
OnChar() function.  This OnChar() never gets called.

In the end, I just added an invisible edit box and mapped the "TEXT CHANGED" (
can't remember the exact name) message of it.  In this OnTextChanged() routine
I called the OnChar() function.  This works fine, but there is one annoying
side-effect.  I have to constantly put focus on this invisible Edit Box (after the
user clicks any other control) in order to get the character input.

Does anybody know a better way to get character input in a modless Dialog?

Or, is there something else I'm missing?

Any help would be appreciated...

Thanks in advance,
	Mike



Bill Campbell -- bill_campbell@ppp.ablecom.net
Tuesday, June 25, 1996

[Mini-digest: 5 responses]

[Moderator's note: I'm considering rejecting messages that say "I haven't
tried this, but...".  I'd like to hear from people on this.]


Mike Wrote :

>Windows 3.1
>VC++ 1.51

>I would like to process the WM_CHAR (OnChar()) message in a modal
>dialog box that has no CEdit controls.


Mike,

	Override CDialog::PreTranslateMessage
Capture WM_CHAR and redirect to your handler routine... I havnt tested this but it should work .. :>)

from the MFC Source Code

BOOL CDialog::PreTranslateMessage(MSG* pMsg)
{
 if (pMsg->message >= WM_KEYFIRST && 
     pMsg->message <= WM_KEYLAST) 

   // maybe translate dialog key
   return ::IsDialogMessage(m_hWnd, pMsg); 

 return FALSE;
}
-----From: "Frederic Steppe" 

Seems like many peoples are trying to intercept keystrokes this times...

Take a look a the CWnd::PreTranslateMessage member function, and/or read some 
recent messages in the list about the same subject.

Frederic Steppe (frederics@msn.com)
-----From: Dalmer Junior 

> 	You can override the PreTranslateMessage.  It is there that you
will receive all messages of the dialog including WM_CHAR .

I Hope help you.


-- 
							Dalmer

*****************************************************************
*  Dalmer B. A. Junior                       Light-Infocon      *
*  mail: dalmer@cgsoft.softex.br          Development Analist   *
*  Office Tel: (083) 333-1707                 --------  __o     *
*  FAX       : (083) 333-1834                -------  _`\<,_    *
*  "Life is Short Ride Tough"               -------  (*)/ (*)   *
*****************************************************************
-----From: kitk@mudshark.sunquest.com (Kit Kauffmann)

You might try PreTranslateMessage: you can certainly get it with a 
ProcessMessageFilter override, though you then have to route it the dialog 
in question (e.g. GetActiveWindow)

HTH!
Make it idiot proof and someone will make a better idiot.

-----From: Niels Ull Jacobsen 

I don't think the dialog will ever receive any WM_CHAR's. These are usual=
ly
send as a result of PreTranslateMessage translating a WM_KEYDOWN.
And the PretanslateMessage of CDialog won't do these translations.

So you need to trap WM_KEYDOWN instead

Niels Ull Jacobsen, Kr=FCger A/S (nuj@kruger.dk)
Everything stated herein is THE OFFICIAL POLICY of the entire Kruger=20
group and should be taken as legally binding in every respect.=20
Pigs will grow wings and fly.





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