How to filter lower case characters in an edit control?

Hi to all,

I created a class that enherits from CEdit and overrode its OnChar() message 
handler to intercept the entered keys and filter only those that are lower 
case. It also verifies if an entered key is upper case to convert it to lower 
case and filter it.

Everything works good except the conversion from upper to lower case. The 
problem is that even if the OnChar() handler does convert the character to 
lower case, the character is still displayed in the edit box as it was 
entered, i.e. in upper case.

Please note that if I remove the line: "nChar = tolower(nChar);", the upper 
case characters will be rejected and this is not what I want. I want the same 
behaviour than the edit control's Lowercase property, which will convert all 
characters to lowercase as they are typed into the edit box. However, this 
property allows all other character types to be output.

Here's the code of the OnChar() message handler:

#define BACK_SPACE      8

void CEditLoCase::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
    TRACE("OnChar(): %c ; %d\n", nChar, nFlags);

    // Filter all the characters in 'm_pFilter' to be processed.
    nChar = tolower(nChar);
    if ((nChar >= 'a' && nChar <= 'z') ||
        nChar == BACK_SPACE)
    {
        CEdit::OnChar(nChar, nRepCnt, nFlags);
    }
    else
    {
        MessageBeep(MB_OK);
    }
}


I appreciate any help and thank you in advance.

Geo
0
Geo (129)
10/21/2006 1:10:02 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
1319 Views

Similar Articles

[PageSpeed] 17

>I created a class that enherits from CEdit and overrode its OnChar() message 
>handler to intercept the entered keys and filter only those that are lower 
>case. It also verifies if an entered key is upper case to convert it to lower 
>case and filter it.

Geo,

Why not just create the control with the ES_LOWERCASE style?

Dave
0
davidl7375 (2060)
10/21/2006 6:41:43 PM
Geo schrieb:

> void CEditLoCase::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
> {
[...]
>         CEdit::OnChar(nChar, nRepCnt, nFlags);

To "hook" into the default behaviour of a Non-MFC windows control, you need 
"Window"-subclassing instead of "C++ MFC" subclassing. If you step into the 
CEdit::OnChar function above with your debugger, you will notice that the 
handler will probably do nothing (I have not checked), at least it will not 
forward the message to the windows edit control.

Have a look at CWnd::SubclassWindow.

Norbert
0
nunterberg (207)
10/22/2006 9:22:00 AM
This problem arises because Microsoft totally screwed up the MFC implementation on day 1.
You can't change ANY of the parameters that are coming in; the superclass call simply
takes the incoming parameters and reuses them, instead of doing something intelligent,
such as using your parameters!  (That paragraph at the end of every MFC call is there
because I collarred the MFC guys at an MVP conference and told them they had to fix MFC to
be right.  They didn't, but they at least notified us that every call is screwed up.
Apparently they never *actually* understood object-oriented programming and subclassing,
and kludged up something that sort-of-worked most of the time.)

However, as already pointed out, using the ES_LOWERCASE flag will solve your problem, so
your approach is needlessly complicated.  You don't even need subclassing to implement it,
just a ModifyStyle call (ES_LOWERCASE and ES_UPPERCASE are two style bits that can be
freely modified after the control is created)
				joe

On Sat, 21 Oct 2006 06:10:02 -0700, Geo <Geo@discussions.microsoft.com> wrote:

>Hi to all,
>
>I created a class that enherits from CEdit and overrode its OnChar() message 
>handler to intercept the entered keys and filter only those that are lower 
>case. It also verifies if an entered key is upper case to convert it to lower 
>case and filter it.
>
>Everything works good except the conversion from upper to lower case. The 
>problem is that even if the OnChar() handler does convert the character to 
>lower case, the character is still displayed in the edit box as it was 
>entered, i.e. in upper case.
>
>Please note that if I remove the line: "nChar = tolower(nChar);", the upper 
>case characters will be rejected and this is not what I want. I want the same 
>behaviour than the edit control's Lowercase property, which will convert all 
>characters to lowercase as they are typed into the edit box. However, this 
>property allows all other character types to be output.
>
>Here's the code of the OnChar() message handler:
>
>#define BACK_SPACE      8
****
Why 8?  Why not _T('\b')?
****
>
>void CEditLoCase::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
>{
>    TRACE("OnChar(): %c ; %d\n", nChar, nFlags);
>
>    // Filter all the characters in 'm_pFilter' to be processed.
>    nChar = tolower(nChar);
>    if ((nChar >= 'a' && nChar <= 'z') ||
>        nChar == BACK_SPACE)
>    {
>        CEdit::OnChar(nChar, nRepCnt, nFlags); 
****
This ignores your change to nChar and simply reuses the original nChar value, which it has
hidden away!  
****
>    }
>    else
>    {
>        MessageBeep(MB_OK);
>    }
>}
>
>
>I appreciate any help and thank you in advance.
>
>Geo
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
10/22/2006 4:42:44 PM
Reply:

Similar Artilces:

Filters *SOS* Filters *SOS* Filters *SOS*
1) On formLoad, I need to show only those items which are unassigned. 2) I need for the end-under to select only the items they are assigned to. 3) I need an option to select "ALL" so I can view all items. Any insight offered would be appreciated!!! On Wed, 29 Aug 2007 16:24:01 -0700, valdaiway <valdaiway@discussions.microsoft.com> wrote: >1) On formLoad, I need to show only those items which are unassigned. Use a query to put a criterion on the field that defines the assigned status. I assume you know how that information is stored in your table; nobody here does, ...

extracting sheets on the basis of Row character
Hi, I have the below data...i have only shown the st column but i have the data in 15 coulmns. Like this i have 20 sheets... and i need a separate sheets for the name that are contained in column A ie separate sheet for "Mark" where it will extract the data from 20 sheets where there is row with name mark... Name Mark Steve Mark Gary Mark Gary Steve Regards, radha If desired, send your file to my address below. I will only look if: 1. You send a copy of this message on an inserted sheet 2. You give me the newsgroup and the subject line ...

Curser Movement control
Hi, Usually, when I press tab, the curser will move to the next cell on the right. If I press enter, the curser will move down one row on the same column. How can I, say, move the curser 5 cells to the right when I press Tab key or Enter Key? Thank You. GL One way to explicitly control the exact "next cell of focus" selection, is to select the cells in the desired order of travel, and then preserve this ordered movement by creating a named range. This old post describes the steps that can be taken to create such a "named range". http://tinyurl.com/39vzv -- HTH, RD...

Criteria for Advanced Filter HELP
I have what I think is a simple question that I need answered IMMEDIATELY. I have a spreadsheet with 20 fields and I want to filter it so it only shows records that have something in of any of 5 of those fields. So once filtered, I will not have any records that have all 5 of those fields blank. I know I have done this before but I'll be damned if I can remember or find out how. -- Thanks You all are teaching me so much don't cross-post -- answer supplied in misc NG "knowshowrosegrows" <knowshowrosegrows@discussions.microsoft.com> wrote in message news:ACBC0...

#### being printed instead of characters
I have a text cell that when it prints the cell prints out as all ######. I have tried to expand to cell but still get only the characters #. Is there a limit on the number of characters that will fit into a cell? --- Message posted from http://www.ExcelForum.com/ From the XL2000 Help file, "Worksheet and workbook specifications": Length of cell contents (text) - 32,767 characters. Only 1,024 display in a cell; all 32,767 display in the formula bar. HTH Ed "mconville" <mconville.yhu4b@excelforum-nospam.com> wrote in message news:mconville.yhu4b@excelforum-...

Master slide has graphics that cannot be edited
I am using PPT 2007, but I think I am attempting to edit a slide deck that was created with PPT 2003. When I go to Slide Master view, I see two different graphics and a text box on the slide that I cannot edit. The two graphics and text box were probably on the master slide when the deck was created with PPT 2003. (They are NOT part of the "background" of the master slide.) When you click on the graphics and the text box when you are in Slide Master view, nothing happens. Does anyone know how to edit these graphics and the text box? Thanks! Tim If I was...

Employee Filters
Hello: On the employee filters in the HR Preferenes window, would this restrict seeing employee information in both Payroll and HR? Also, would it restrict reporting on certain employees in a division or department? Thanks! childofthe1980s Your message does not indicate which version of Great Plains you are using. Using 8.0 with SP3 applied, HR filters do apply to some of employee information outside of HR. The settings will filter selected forms, Smartlists and Lists items. The HR filter setting do not apply to reports outside of HR. The filtered forms are: Employee Maintenance,...

Filtering based on a filter
Hello, I have an Excel Worksheet with a Pivot Table at the top with a Filter and a data set returned from a DB2 database below it. I would like to filter the DB2 data set based on the Pivot Table filter that is enabled. Any ideas? Thanks! James, You can't filter two ranges on the same worksheet. You can, instead, drill-down on your pivot table, which will show all items that go into the value on a newly created separate sheet. The drawback to that is that you cna only drill down on one item at a time, and it is a separate sheet. HTH, Bernie MS Excel MVP "James" <an...

Question on the IMF filtering in exchange...
Hey I installed the IMF filter last night and it works great, with one exception. I set both thresholds to the same (5) and got almost all blocked emails into the archive that were junk...So that is good. However I had some users report that there was mail in their junk folder that should have been good Inbox mail. This I undersyand and can live with as folas-positives...the problem is, since both settings on the folter tab were set to 5, how does it know to send the mail to archive rather than Junk folder? Why wouldn't it just send them all to archive if both settings were at ...

Filtering without Filter
I just don't get the following. Any ideas? "A" row I have two different values I use: "Contact" and "Not a contact". "B" row I have the person's name (employee). "C" row I have a quantity, just one number. Now what I need is to output quantities of how many Contacts Employee1 or Employee2 or Employee3 have. Also what I need is to get the number of contacts - which can be found on row "C". Should I use COUNT.IF ? Row A can have 2 or more different values so should there be somekind of conditional IF function included? T...

Creating some sort of control by MFC. Problems
Hi there. I need to implement following: In my main project I have a tab control which has few tabs. On that tab there are some windows where different modules of my application are implemented. Now I need to make some sort of license program where depending of some conditions users will be able to use different modules. Also I would like to implement module's window design and logic in separated DLL so I will be able to modify modules without recompiling main program. I'm using MFC for my main project. Currently the best solutions which I see is to create a MFC DLL and make a d...

Filtering #11
Hi, can ayone tell me how I could do the following in excel 2007 or 2010: Horse Trainer Sam M Jones John M Jones Colin S Attwater Steve J Jackson Brian B Mathers James B Mathers Martin G Raggy Patrick S Thomson What I want to do is filter the dataset on 'Trainer' so that it only shows me the Trainers who feature once in the list. So if I was to do this properly it would only show S Attwater and G Raggy as the other trainers have more than one horse..... Hopefully someone can help because it is driving me crazy !! Thanks David Give this macro a try... Sub HideDuplicateTr...

Junk filter BEFORE other filters?
I am running Outlook 2003 and the Junk filter was working really well. Then I started making other filters...one of them looks for my domain name in the headers and if it's there it moves the email to a folder. Problem is, this filter seems to activate before the junk filter, so the junk sn't being filtered now! How can I set the junk filter to do it's job first and THEN to run my own rules? -- Bryan Anderson <www.anderson-it.com> I created this rule and set it as the first rule to run: Apply this rule after the message arrives with 'X-Spam-Level:******'or'...

Unable to open Window Firewall in Control Panel
Hi All, I have WinXP Pro SP3 and when I go to Control Panel and double click on the 'Windows Firewall' icon I get an error message. There is no error number, only the text, The service Windows Firewall/Internet Connection Service (ICS) is not started. Do your wish to start it? I then click on the 'Yes' button and after a second to two I get another error message. This message states that the service could not be started. The error text that I post here is not word for word but you should get the idea of my problem. I am unable to check the status or add exclu...

Pasting into a filtered list
Can anyone tell me if it is possible to paste a list of price updates into a filtered list. - I have filtered the list to show just the products whose prices need to be updated, when I try to paste the updated prices, into the list, the prices are not just pasted into the visible cells but the hidden cells between. Can I paste into the visible cells only or do I have to update each line manually. I am using Excel 2002 Any help would be much appreciated Can you sort the list to bring the products that need updating together in the list? If not, try something like this: Your list of product...

Transforming an IF...Then to Case...When
Hi, I try to converet this simple If...Then to a Case...When but get error mesaages. Anyone can help me to pinpoit my error? IF...THEN (which works) select IIF(Left(isin, 2)= 'US', 'America', 'Non US') from stub_internal CASE..WHEN (with errors) select CASE WHEN left(isin, 2)= 'US' THEN 'America' ELSE 'Non US' END as Origin from stub_internal Thanks! -- Message posted via http://www.accessmonster.com Hi - Your IF - THEN as posted won't work either - you'll get a compilation error. If you are only dealing with two options ( U...

Macro to copy a VLOOKUP formula
Hello, I was wondering if somebody could help me with this macro… I have some data with a filter on, so that only the rows with blank cells are showing. I want to enter a VLOOKUP in the cell, and copy it down to all the blank cells. I tried just recording a macro, but when I run the macro it doesn’t work. Any ideas of how to do it? Example: 1) Before the filter: Colums A -B - C A x x - 1st Row A - 2nd Row A x x - 3rd Row A - 4th row A x x - 5th row 2) After the fil...

Controlling excel chart axis
Hi, I have automated plotting of charts of date v/s speed recorded on a particular day with date on the x-axis and speed on the y-axis for each car that is being tested say Focus, Escort and Ikon. The graph gets displayed properly for the first data selected (say Focus) from a combo box. Now, for the other selection, the graph axis are getting reversed i.e date is getting plotted on the y-axis and speed on the x-axis ! Is there some why to control this ? I’m using Excel with VBA. TIA Is it still the same type of chart? You must somehow be mixing up Values and XValues for ...

apply filter macro
I have a access db that works on win xp but does not work on win 2007 I have a combo box that triggers a apply filter macro using a query sort. no problem on win 2000 or win xp or win 2003 Help AlT ...

Using Unicode characters in Visio
It seems that Visio 2000/2002 does NOT support Unicode characters as the other Office tools (e.g. Word, Excel) do. In Visio 2000/2002 running on Window XP/2000, I can use Unicode fonts (e.g. Arial, Tahoma) to type or paste English characters only. For example, I cannot paste the Vietnamese word (e.g. "Vi&#7879;t") correctly in Visio!!! Is there any way to work arround this problem? Thanks in advance, Tan ...

IP filtering based on corresponding MX records
Hello Dears, How can I implement the following? Used: Exchange 2003 SP2 in FE/BE configuration; FE is in perimeter zone (capable to “speak” with DNS, BE, DCs and retrieve info) So, somebody connects my FE to sent an e-mail to one of domain users. I need something like that: When connecting, see the “mail from: user@somedomain.xxx”; Verify if there is a record MX for the IP address from which the connection was established in DNS for the domain “somedomain.xxx” If not – drop connection (attention: MX record, not SPF) Is it possible with Exchange 2003 SP2 only? How? Thank you, Alex I be...

Month Filter
I keep a log of checks that I receive in my department throughout the year. I have the checks listed by date (mm/dd/yy), payee, check #, etc. What I want to do is be able to filter the list by month (ex., March 2005). Is there a way to do this? Thanks Joseph You can Try EasyFilter Joseph http://www.rondebruin.nl/easyfilter.htm -- Regards Ron de Bruin http://www.rondebruin.nl "Joseph" <joe@nospam.com> wrote in message news:%23lQNnTawFHA.464@TK2MSFTNGP15.phx.gbl... >I keep a log of checks that I receive in my department throughout the year. I have the checks lis...

Using a form in Excel to Filter
I would like to create a form in Excel that is similar to a form in Access. This form will hold all fields on the underlying spreadsheet and enable the user to sort using combo box dropdowns. Ideally, the form would have a button titled RUN that will take all the data the user selects in the combos and filter the underlying spreadsheet. Can this be done?? If so....you will save my life! TIA, Chris Try this Add-in http://www.rondebruin.nl/easyfilter.htm -- Regards Ron de Bruin http://www.rondebruin.nl <ccfatzin@ibtco.com> wrote in message news:1122677766.648239.226910@z14g200...

filter for missing values in a range
I have a list in Col A ( about 2000) one to four digit numbers. I would like to ( for example) , in the 700's be able to filter and find out which of the numbers from 700 to 799 is NOT in the list. I know how to copy and paste to another col, etc. Thanks in advance for the wonderful help all of you give. One play .. Assume your source data runs in A2 down In B2: =IF(ROWS($1:1)+700-1>799,"",IF(ISNUMBER(MATCH(ROWS($1:1)+700-1,A:A,0)),"",ROWS($1:1)+700-1)) Copy B2 down by 100 rows to cover the full spread of numbers to be checked, ie # of nums from s...

Editing pdf invoices
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) I'd appreciate any advice for this problem. I have Adobe Pro 9, however, I have very rudimentary knowledge of how to operate it. My problem is this: My bookkeeper, who handles all of the invoicing for my business, has started to charge me for every "friendly reminder" or "Third Notice, Please Remit" that I have to send to clients. Basically, she just, somehow, adds a red square at the top right corner of the invoices, stating Reminder, or Please Remit, and the dates of the current and previous invoices. Because...