CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2009
    Posts
    16

    CEdit - capture message....

    ugh I've been trying to get this to work for the past 2 days.

    using GUI builder in Visual Studio 2008, I drag & dropped CEdit control on my single dialog application.
    Then I added a variable to it - m_adrbox (not sure if I needed it)

    At the top of the myDialogDlg.cpp source I modified my message map:

    Code:
    BEGIN_MESSAGE_MAP(CrsClientDlg, CDialog)
    ON_BN_CLICKED(IDC_BUTTON1, &CrsClientDlg::OnBnClickedButton1)
                  ON_WM_CHAR(IDC_EDIT1, &CrsClientDlg::OnChar)
    END_MESSAGE_MAP()
    I have onChar method and the code compiles fine. But the CEdit does not respond to OnChar messages.

    what is the problem?

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: CEdit - capture message....

    What do you mean doesn't respond? You put a breakpoint in CrsClientDlg::OnChar and it's not getting hit?

  3. #3
    Join Date
    May 2009
    Posts
    16

    Re: CEdit - capture message....

    my WM_CHAR void contains:

    messagebox("it works!");


    I never get that message. So the code never gets executed.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: CEdit - capture message....

    What's a WM_CHAR void?

    Please answer questions as they're asked and post real code.

  5. #5
    Join Date
    May 2009
    Posts
    16

    Re: CEdit - capture message....

    ok, first I changed my message map as I mentioned in the first post.
    As I understand, from now on when CEdit control receives WM_CHAR message, it will let OnChar void to deal with it.

    This is my OnChar void as it was referenced in the message map:

    Code:
    void CrsClientDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    	// TODO: Add your message handler code here and/or call default
    	MessageBox(L"OnChar message captured!");
    }

    no matter what happens. I never get the messagebox to appear which means that CEdit is not capturing WM_CHar message.
    Why?

    What did I do wrong?

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: CEdit - capture message....

    With what you've posted, I don't see anything. Try cleaning your project and do a full rebuild.

  7. #7
    Join Date
    May 2009
    Posts
    16

    Re: CEdit - capture message....

    ok, here is what I did:

    I created another message for CEdit:

    Code:
    ON_EN_CHANGE(IDC_EDIT1, &CrsClientDlg::OnEnChangeEdit1)
    ....
    void CrsClientDlg::OnEnChangeEdit1()
    {
    	// TODO:  Add your control notification handler code here
    	MessageBox(L"onchange message captured!");
    }
    guess what? It works!

    Every message that does not involve capturing keys works.

    Why KeyDown and OnChar don't work?
    I remember in Visual Basic 6 you had to set KeyPreview = true before the application can capture keys.

    How would I capture key events in C++?

  8. #8
    Join Date
    Dec 2008
    Posts
    29

    Re: CEdit - capture message....

    Each control has special messages/Notification, you should always use those Notifications related to that control, check it in MSDN. WM_KEYDOWN will be posted to windows and you may receive it if you want to get clicks from client area or other sections of that window (except other control sections inside it)

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