Link to home
Start Free TrialLog in
Avatar of r2far
r2far

asked on

Supress CEdit System beep

I have a CEdit derived class that i made called 'CPassiveEntry'.  The purpose of this class is to serve as an entry box for a table.  There is only one instance of the class made, and it is moved to the cell where it is needed.  The specialization of th class is to algorithmically allow certain keystrokes to pass through to it's parent (int this case CView).

I have the window moving properly, and entering and storing info in the table.

The tab/enter keys are used to move the focus from cell to cell in the table, but whenever the focus moves, you get a system ding or beep or whatever you wanna call it.

The control works, but the beep is very annoying and must be gotten rid of.
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

How do you decide if a character needs to be passed through to the parent? Is the control supposed to beep when the user enters an invalid character? Can you show some code?
Avatar of r2far
r2far

ASKER

> How do you decide if a character needs to be passed through to the parent

- The CPassiveEntry window WILL contain a 'mask'.  If the character fits the mask at the current position, it is not sent to the parent.  
- Right now, for trial, I am just sending anything non-numeric to the parent.
- As well, back space, delete, and arrow keys are not sent to the parent. (just arrows so far)

The two keys that are always sent to the parent are enter and tab.


> Is the control supposed to beep when the user enters an invalid character

As of yet, there is nothing in my code (anywhere in the app for that matter) that generates any sounds.  So the sound must be coming from an MFC derived object (Like CEdit)


> Can you show some code?


void CPassiveEntry::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    if( isdigit(nChar) )
    {
        if( nRepCnt==1 )
        {
            CEdit::OnChar(nChar, nRepCnt, nFlags);
            return;
        }
    }

    switch( nChar )
    {
    case VK_UP:
    case VK_DOWN:
    case VK_RIGHT:
    case VK_LEFT:
        {
            CEdit::OnChar(nChar, nRepCnt, nFlags);
        }break;

    default:
        {
            GetParent()->PostMessage( WM_KEYDOWN,nChar,nRepCnt|(nFlags<<16) );
        }break;
    }
}


* There is no error checking yet
Is it possible that the parent control beeps when it receives the Tab or Return key code? You can verify this by sending a message with the correct nCHar, nRepCnt and nFLags values to the parent without opening your dialog.
Avatar of r2far

ASKER

> without opening your dialog.

Which dialog, there is no dialog.  If you mean the CEdit derived class as a dialog style item then I shall try your suggestion, but as I said above, there is no code in the app anywhere that tells the program to play anysound explicitly (including beeps).

> Is it possible that the parent control beeps when it receives the Tab or Return key code

It is possible, but I tried posting the WM_KEYDOWN event from within the view and it made no sounds.  I am pretty sure the sound is coming from the CPassiveEntry control.


I believe the CEdit::OnKeyDown is getting called by the framework, is there a way to prevent this from happening.  I now believe that what is happening is that the beep is coming from CEdit::OnKeyDown automatically receiving the message and proccessing the enter and tab keys as invalid.

So I think I need to control when the CEdit implementation of the WM_KEYDOWN event is called.  But I can't be changing the way all the CEdit controls act.

Question just got more complex, Increasing point value
ASKER CERTIFIED SOLUTION
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of r2far

ASKER

> What happens if you disable all special processing in OnKeyDown

Actually, When I do nothing in my CPassiveEntry control, it still manages to proccess the key strokes (just doesn't send messages to parent)... This is done even when I comment out CEdit::OnKeyDown().  So the framework must be calling it.


http://www.codeproject.com/miscctrl/gridctrl.asp

I have downloaded and am looking at the code.  Interesting project, however I can't see anything that would explain why CEdit::OnKeyDown() is still called even though I have the message handler in my derived class and do not call the base class implementation in it.



Extra info that may (or may not) have a bearing on the question:

-  The CPassiveEntry object is created in a CView class with 'new CPassiveEntry'
-  The control exists as long as the CView exists
-  When not in use, the entry window is hidden and it's area is zero'd.


m_ctlEntry = new CPassiveEntry;
m_ctlEntry->Create(WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL,CRect(-1,-1,-1,-1),this,ID_PENTRY);


Thank You for the responses, and your patience     8-)
I am running out of ideas. Sorry.

Can you explain, why you need this passive edit control? I don't understand why you only want to relay some keyboard events, but others are handled in the edit control.
Avatar of r2far

ASKER

The edit control needs to trap ascii, and send tab/enter to parent so the parent window can proccess navigational commands between cells in the table.
Avatar of r2far

ASKER

I have figured the answer out on my own...

I used PreTranslateMessage() in the derived class to catch the desired events and send them to the parent window without cending them to the edit box.

In all fairness I'll give you the points khkremer for the time you spent trying to help... thank you... (besides, I do not know how to refund the points  :)    )
You can post a request in Community Support and have them refund the points.
Avatar of r2far

ASKER

to late... it is a thanx for the time   :)
Avatar of r2far

ASKER

but I know for next time, thanx