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?
Re: CEdit - capture message....
What do you mean doesn't respond? You put a breakpoint in CrsClientDlg::OnChar and it's not getting hit?
Re: CEdit - capture message....
my WM_CHAR void contains:
messagebox("it works!");
I never get that message. So the code never gets executed.
Re: CEdit - capture message....
What's a WM_CHAR void?
Please answer questions as they're asked and post real code.
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?
Re: CEdit - capture message....
With what you've posted, I don't see anything. Try cleaning your project and do a full rebuild.
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++?
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)