CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: onChar

  1. #1
    Join Date
    Dec 2005
    Posts
    21

    onChar

    Hi,

    within a dialog, which has several edit boxes and buttons, I have defined a message handler for WM_CHAR using the class wizard. This creates

    void CKeyFromSource::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    int i;
    i = 1; // break here
    CDialog::OnChar(nChar, nRepCnt, nFlags);
    }

    I have a break on the i=1 line;

    This break is never hit...

    Do I have to do something to cause these messages to be passed along?
    Is there something which inhibits these messages?
    I am using Visual C++ 6.0

    Thanks for all help.
    Last edited by phild; December 14th, 2005 at 07:53 PM.

  2. #2
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: onChar

    My guess is the dialog box procedure doesn't translate WM_KEYDOWN for simple character key strokes and it may be eating those.

    I suspect you want to handle typing inside the edit box ? If so, please subclass the edit to your own CEdit derived class and handle WM_CHAR in that class and not the dialog class.

  3. #3
    Join Date
    Dec 2005
    Posts
    21

    Re: onChar

    Kirants,

    thanks for the reply.

    Actually no, I want to be able to catch 'return key', 'numerical pad return key', 'tab' keys etc, from anywhere. For example, if a button is focused and return id pressed, i want to be able to catch it.

    Any ideas?

  4. #4
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: onChar

    In that case you are looking at WM_KEYDOWN. BTW, just curious, is the default dialog box behavior with keys not good for you ? Reason being, typical windows users would not like anything which goes against the normal. You may be having a reason though..

  5. #5
    Join Date
    Dec 2005
    Posts
    21

    Re: onChar

    Kirants,

    Thanks again. I have tried the WM_KEYDOWN message with a similar result to WM_CHAR.... ie nothing.

    No, I need to do more than the default dialog box behavior.

    Do you think there is a way to get at these messages in a dialog?

  6. #6
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: onChar

    Hm.. I know why. It is because all those messages are targeted to the window which has focus ( in your case probably a button or edit or such ).

    Please read this article:
    http://www.codeguru.com/Cpp/W-D/disl...cle.php/c4965/

  7. #7
    Join Date
    Dec 2005
    Posts
    1

    Re: onChar

    Hi,

    Not sure if you have already solved this..
    Certain Windows messages are difficult to trap in a dialog box because they are either processed by the Windows internal dialog procedure or sent to the control instead of the dialog box. There are several ways to do this, but they usually involve subclassing all the controls in the dialog box or using a Windows hook function. The idea is to override the MFC preinstalled hook function, ProcessMessageFilter(), to trap the messages before they get to the dialog box.

    In case you need an example, do let me know.

    Cheers
    Sun

  8. #8
    Join Date
    Dec 2005
    Posts
    21

    Re: onChar

    Yes, please, an example would be really helpful :-)

    I will PM you with my email address.

    Thanks Sun_raman
    Phil

  9. #9
    Join Date
    Dec 2005
    Posts
    21

    Re: onChar

    Sun_raman, I don't seem to be able to PM you, if you can, email me or post the example on line.

    Kirants, thank you, I read in detail the link you sent and the sublinks... so it can be done, but if I can get an example that would be really helpful

    Thanks again
    Phil

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured