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

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


Intercepting key down messages in CRichEditCtrl

Paul Mitsui -- PMITSUI@dataflight.com
Monday, January 13, 1997

Environment: VC++ 4.1, Windows95

I'm using an CRichEditCtrl to input information from the user.
Since I've found that rich edit controls cannot be set with the 
window styles ES_UPPERCASE, ES_LOWERCASE, or ES_NUMBER, I'm forced to 
intercept the key down messages but this doesn't seem to work.

I've tried the following example to convert all lowercase letters to 
uppercase but lowercase letters are still being displayed to the 
screen.

I know there is another message handler that I should perform this 
in...but what?


void CMyEditControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
 if ((nChar >= 'a') || (nChar <= 'z'))
  nChar += nChar - 'a' + 'A';

 CRichEditCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}


I've also tried...


void CDBEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) {
 if ((nChar >= 'a') || (nChar <= 'z'))
  nChar += nChar - 'a' + 'A';

 CRichEditCtrl::OnChar(nChar, nRepCnt, nFlags);
}


with no results as well.  The lowercase 'a' prints in the control in 
either case.  Does this look like a job for subclassing?

Thanks in advance.

-Paul
-----------------------------------------------------------
Paul J. Mitsui
Product Development and Support


Dataflight Software
2337 Roscomare Road, Suite 11
Los Angeles, CA 90077
(310) 471-3414



Gururaja D. -- gururaja@aditi.com
Wednesday, January 15, 1997

[Mini-digest: 3 responses]

Hi Paul,

	In the help of the OnChar it is said that, 

	Note : This member function is called by the framework to allow your
application to handle a Windows message. The parameters passed to your
function reflect the parameters received by the framework when the
message was received. If you call the base-class implementation of this
function, that implementation will use the parameters originally passed
with the message and not the parameters you supply to the function.

	So the value of nChar will have no effect if you call the Base Class
member.

	Hence try the following code in OnChar of you CRichEditCtrl Derived
class

void CDBEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if ((nChar >= 'a') && (nChar <= 'z'))
	{
	  nChar = nChar - 'a' + 'A';
	  SendMessage(WM_CHAR, nChar,MAKELPARAM(nRepCnt,nFlags));
	  return ;
	}

	CRichEditCtrl::OnChar(nChar, nRepCnt, nFlags);
}

Hope this helps.
Gururaja

" IF ANYBODY LIKES YOU IT'S HIS WEAKNESS,
                            IF ANYBODY DEPENDS ON YOU IT'S YOUR
GREATENESS"
*************************************************************************
*********

Gururaja                                                        Gururaja
Software Engineer                                         70
Aditi Technologies Private Limited.                4th cross
224/16                                                          SBM
colony
Ramana Maharishi Road                               BSK I stage
 Bangalore 560080                                         (Near Sitha
Circle)
Tel:  (9180) 3312966/67/68                          Bangalore



_________________________________________________________________________
_____________________

Environment: VC++ 4.1, Windows95

I'm using an CRichEditCtrl to input information from the user.
Since I've found that rich edit controls cannot be set with the 
window styles ES_UPPERCASE, ES_LOWERCASE, or ES_NUMBER, I'm forced to 
intercept the key down messages but this doesn't seem to work.

I've tried the following example to convert all lowercase letters to 
uppercase but lowercase letters are still being displayed to the 
screen.

I know there is another message handler that I should perform this 
in...but what?


void CMyEditControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
 if ((nChar >= 'a') || (nChar <= 'z'))
  nChar += nChar - 'a' + 'A';

 CRichEditCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}


I've also tried...


void CDBEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) {
 if ((nChar >= 'a') || (nChar <= 'z'))
  nChar += nChar - 'a' + 'A';

 CRichEditCtrl::OnChar(nChar, nRepCnt, nFlags);
}


with no results as well.  The lowercase 'a' prints in the control in 
either case.  Does this look like a job for subclassing?

Thanks in advance.

-Paul
-----------------------------------------------------------
Paul J. Mitsui
Product Development and Support


Dataflight Software
2337 Roscomare Road, Suite 11
Los Angeles, CA 90077
(310) 471-3414

-----From: hou@tfn.com (Bing Hou)

     
Windows defines VK_A through VK_Z but not VK_a through VK_z, in order to detect 
these keys, you have to combine them with extended keys. Therefore, in your 
OnKeyDown function, the conditions for detecting small letters are never met.

Bing Hou
hou@tfn.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   "Man is still the most extraordinary computer of all."
                                           -- John F. Kennedy
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~             
         
 
______________________________ Reply Separator _________________________________
Subject: Intercepting key down messages in CRichEditCtrl
Author:  Paul Mitsui  at Internet
Date:    1/13/97 10:24 AM


Environment: VC++ 4.1, Windows95
     
I'm using an CRichEditCtrl to input information from the user. 
Since I've found that rich edit controls cannot be set with the 
window styles ES_UPPERCASE, ES_LOWERCASE, or ES_NUMBER, I'm forced to 
intercept the key down messages but this doesn't seem to work.
     
I've tried the following example to convert all lowercase letters to 
uppercase but lowercase letters are still being displayed to the 
screen.
     
I know there is another message handler that I should perform this 
in...but what?
     
     
void CMyEditControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
 if ((nChar >= 'a') || (nChar <= 'z'))
  nChar += nChar - 'a' + 'A';
     
 CRichEditCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
     
     
I've also tried...
     
     
void CDBEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) {
 if ((nChar >= 'a') || (nChar <= 'z'))
  nChar += nChar - 'a' + 'A';
     
 CRichEditCtrl::OnChar(nChar, nRepCnt, nFlags);
}
     
     
with no results as well.  The lowercase 'a' prints in the control in 
either case.  Does this look like a job for subclassing?
     
Thanks in advance.
     
-Paul
----------------------------------------------------------- 
Paul J. Mitsui
Product Development and Support

     
Dataflight Software
2337 Roscomare Road, Suite 11
Los Angeles, CA 90077
(310) 471-3414
-----From: Jim Lawson Williams 

At 10:24 AM 13/01/97 +0000, Paul Mitsui  wrote:
>Environment: VC++ 4.1, Windows95
>
>I'm using an CRichEditCtrl to input information from the user.
>Since I've found that rich edit controls cannot be set with the 
>window styles ES_UPPERCASE, ES_LOWERCASE, or ES_NUMBER, I'm forced to 
>intercept the key down messages but this doesn't seem to work.
>
>I've tried the following example to convert all lowercase letters to 
>uppercase but lowercase letters are still being displayed to the 
>screen.
>
>I know there is another message handler that I should perform this 
>in...but what?
>
>
>void CMyEditControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
>{
> if ((nChar >= 'a') || (nChar <= 'z'))
>  nChar += nChar - 'a' + 'A';
>
> CRichEditCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
>}
>
>
>I've also tried...
>
>
>void CDBEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) {
> if ((nChar >= 'a') || (nChar <= 'z'))
>  nChar += nChar - 'a' + 'A';
>
> CRichEditCtrl::OnChar(nChar, nRepCnt, nFlags);
>}
>
>
>with no results as well.  The lowercase 'a' prints in the control in 
>either case.  Does this look like a job for subclassing?
>
G'day!
I don't understand your architecture.  If you've rolled your own CRichEditCtrl and embedded it in a dialog then you're well beyond my experience.  If you're using CRichEditView and CRichEditDoc then I doubt that subclassing is easy, or even feasible.  My experience is, that after subclassing, you are disconnected from some of the original methods, though connected to the window.  For example, in dealing with a dialog's CEdit, DDX and DDV still operate, but you must use
           m_editSmart.SetWindowText(" ");  
          //where m_editSmart.SubclassDlgItem(IDC_DUMB_EDIT,this)
 and not   SetDlgItemText(IDC_DUMB_EDIT," ");

TN061 may point you in the right direction, but the examples you cite are "case" and "numeric" oriented.  Do you truly need _both_ rich text and in-line character processing?

To proceed with on-the-fly character-translation, consider what you want to do with the cursor-control and numeric-pad keys:

  *  You will see the "printable" set and VK_BACK in OnChar(), but not the arrows,
     end, home, etc.

  *  In OnKeyDown() you will need to examine the scan-code, and may need to know        the "Num Lock" value.  "nChar = 0x47" may mean  "G" or VK_HOME;  0x4b              could be "K", "4", or VK_LEFT.  

Good Luck!

Jim LW



>From the BBC's "Barchester Chronicles":

    "I know that ultimately we are not supposed to understand.
    But I also know that we must try."

       -- the Reverend Septimus Harding, crypt-analyst, clog-dancer, C++ programmer



Kostya Sebov -- sebov@is.kiev.ua
Friday, January 17, 1997

In mfc-l Gururaja wrote:
>
>   Hi Paul,
>
>       In the help of the OnChar it is said that,
>
>       Note : This member function is called by the framework to allow your
>   application to handle a Windows message. The parameters passed to your
>   function reflect the parameters received by the framework when the
>   message was received. If you call the base-class implementation of this
>   function, that implementation will use the parameters originally passed
>   with the message and not the parameters you supply to the function.
>
>       So the value of nChar will have no effect if you call the Base Class
>   member.
>
>       Hence try the following code in OnChar of you CRichEditCtrl Derived
>   class
>
>   void CDBEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
>   {
>       if ((nChar >= 'a') && (nChar <= 'z'))
>       {
>         nChar = nChar - 'a' + 'A';
>         SendMessage(WM_CHAR, nChar,MAKELPARAM(nRepCnt,nFlags));
>         return ;
>       }
>
>       CRichEditCtrl::OnChar(nChar, nRepCnt, nFlags);
>   }
>
>   Hope this helps.
>   Gururaja
>
I used the similar technique to override WM_GETWINDOWTEXT WM_SETWINDOWTEXT
(or whatever it looks like _exactly_). Not sure if it'll work in your case
but in mine it did (I needed to control nonintegral values controlled by the
connected spin-button with UDS_SETBUDDYINTEGER style).

However, the code suggested above has a bug, which should be corrected like this:


void CDBEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    if( !m_bUseDefault )
    {
        Default(); // no need to call ::OnChar, it does nothing more

        m_bUseDefault = FALSE;
        return;
    }

    if ((nChar >= 'a') && (nChar <= 'z'))
    {
      m_bUseDefault = TRUE;

      nChar = nChar - 'a' + 'A';
      SendMessage(WM_CHAR, nChar,MAKELPARAM(nRepCnt,nFlags));
      return ;
    }

}

, where the m_bUseDefault is a BOOL member declared in CDBEditControl, which
should be set to FALSE in OnCreate.

Oterwise it will create the infinite loop.

Hope this'll help,

Kostya.



Here follows the original message:
>
>   _________________________________________________________________________
>   _____________________
>
>   Environment: VC++ 4.1, Windows95
>
>   I'm using an CRichEditCtrl to input information from the user.
>   Since I've found that rich edit controls cannot be set with the
>   window styles ES_UPPERCASE, ES_LOWERCASE, or ES_NUMBER, I'm forced to
>   intercept the key down messages but this doesn't seem to work.
>
>   I've tried the following example to convert all lowercase letters to
>   uppercase but lowercase letters are still being displayed to the
>   screen.
>
>   I know there is another message handler that I should perform this
>   in...but what?
>
>
>   void CMyEditControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
>   {
>    if ((nChar >= 'a') || (nChar <= 'z'))
>     nChar += nChar - 'a' + 'A';
>
>    CRichEditCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
>   }
>
>
>   I've also tried...
>
>
>   void CDBEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) {
>    if ((nChar >= 'a') || (nChar <= 'z'))
>     nChar += nChar - 'a' + 'A';
>
>    CRichEditCtrl::OnChar(nChar, nRepCnt, nFlags);
>   }
>
>
>   with no results as well.  The lowercase 'a' prints in the control in
>   either case.  Does this look like a job for subclassing?
>
>   Thanks in advance.
>
>   -Paul
>   -----------------------------------------------------------
>   Paul J. Mitsui
>   Product Development and Support
>   
>
>   Dataflight Software
>   2337 Roscomare Road, Suite 11
>   Los Angeles, CA 90077
>   (310) 471-3414
>
--- 
Kostya Sebov. 
----------------------------------------------------------------------------
Tel: (38 044) 266-6387 | Fax: (38 044) 266-6195 | E-mail: sebov@is.kiev.ua



Roma -- roma@neonet.lv
Monday, January 20, 1997

Kostya Sebov wrote:
> 
> In mfc-l Gururaja wrote:
> >
[snip]
> >
> >   void CDBEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
> >   {
> >       if ((nChar >= 'a') && (nChar <= 'z'))
> >       {
> >         nChar = nChar - 'a' + 'A';
> >         SendMessage(WM_CHAR, nChar,MAKELPARAM(nRepCnt,nFlags));
> >         return ;
> >       }
> >
> >       CRichEditCtrl::OnChar(nChar, nRepCnt, nFlags);
> >   }
> >
> >   Hope this helps.
> >   Gururaja
> >
[snip]
> 
> However, the code suggested above has a bug, which should be corrected like this:
[snip]
> Oterwise it will create the infinite loop.
> 
 There is NO error in the above code. It will never fall into infinite
loop.
 SendMessage() will be called only when the incoming character is
between 
 lower case 'a' and 'z'. Before call to SendMessage() symbol will be
converted from lower case 
 to upper case symbol (nChar = nChar - 'a' + 'A';) And the character
which will be 
 passed to SendMessage() is UPPER CASE letter which means that condition
in the 
 if((nChar >= 'a') && (nChar <= 'z')) will be FALSE and hence
SendMessage will not
 be called again.

 -Roma



David Little -- dlittle@equinoxcorp.com
Tuesday, January 21, 1997

[Mini-digest: 2 responses]


Can you say "ToUpper()"?  Next you will wonder why INT10 doesn't work when you try to write your character to the screen....

David

----------
From: 	Roma[SMTP:roma@neonet.lv]
Sent: 	Monday, January 20, 1997 6:37 AM
To: 	mfc-l@netcom.com
Cc: 	sebov@is.kiev.ua
Subject: 	Re: Intercepting key down messages in CRichEditCtrl

[snip]

> >
> >   void CDBEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
> >   {
> >       if ((nChar >= 'a') && (nChar <= 'z'))
> >       {
> >         nChar = nChar - 'a' + 'A';
> >         SendMessage(WM_CHAR, nChar,MAKELPARAM(nRepCnt,nFlags));
> >         return ;
> >       }
> >
> >       CRichEditCtrl::OnChar(nChar, nRepCnt, nFlags);
> >   }
> >
> >   Hope this helps.
> >   Gururaja
> >

[snip]

-----From: Peter 

Roma wrote:
> 
> Kostya Sebov wrote:
> >
> > In mfc-l Gururaja wrote:
> > >
> [snip]
> > >
> > >   void CDBEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
> > >   {
> > >       if ((nChar >= 'a') && (nChar <= 'z'))
> > >       {
> > >         nChar = nChar - 'a' + 'A';
> > >         SendMessage(WM_CHAR, nChar,MAKELPARAM(nRepCnt,nFlags));
> > >         return ;
> > >       }
> > >
> > >       CRichEditCtrl::OnChar(nChar, nRepCnt, nFlags);
> > >   }
> > >
> > >   Hope this helps.
> > >   Gururaja
> > >
> [snip]
> >
> > However, the code suggested above has a bug, which should be corrected like this:
> [snip]
> > Oterwise it will create the infinite loop.
> >
>  There is NO error in the above code. It will never fall into infinite
> loop.
>  SendMessage() will be called only when the incoming character is
> between
>  lower case 'a' and 'z'. Before call to SendMessage() symbol will be
> converted from lower case
>  to upper case symbol (nChar = nChar - 'a' + 'A';) And the character
> which will be
>  passed to SendMessage() is UPPER CASE letter which means that condition
> in the
>  if((nChar >= 'a') && (nChar <= 'z')) will be FALSE and hence
> SendMessage will not
>  be called again.
> 
>  -Roma

I just wonder about the testing of the char....won't this fail in
international versions, and aren't there functions to test for/and
correct upper/lower case issues??

Peter R. Vermilye
cpudude@mem.net

PS:  Is there another word for synonym?



Mike Blaszczak -- mikeblas@nwlink.com
Thursday, January 23, 1997

>-----From: Peter 
>> > >         nChar = nChar - 'a' + 'A';

>I just wonder about the testing of the char....won't this fail in
>international versions, and aren't there functions to test for/and
>correct upper/lower case issues??

The code won't fail, but it won't return the desired result.  There
are lowercase and uppercase characters outside of the range of
['A'...'Z'] and ['a'...'z'] in different languages.  The runtime
library provides lots of functions which would be more appropriate
than the if() and assignment statements shown here.

The code serves its purpose, though: it has provided someone with
a question a huge shove in the right direction.

>PS:  Is there another word for synonym?

Try "equivalent term".

[Moderator's note: That's two words. How about "thesaurivative"?]

.B ekiM
http://www.nwlink.com/~mikeblas/
Why does the "new" Corvette look like a 1993 RX-7?
These words are my own. I do not speak on behalf of Microsoft.





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