Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
The code below is which I used to create window resource.I found WM_RBUTTONDOWN respond but WM_CHAR and WM_KEYDOWN not.I also used CWnd::CreateEx and failed again.
CWnd::Create(NULL, _T("ReportCtrl"), dwStyle, rect, pParentWnd, nID);
Posted

This indicates that the windows in question does not have a keyboard focus. Further, it depends on a kind of window. If this is a control, if should be focusable and focused at the moment of key press. If this is a popup window having focusable controls in it, the focus can be grabbed by one of there controls. You can add keyboard handlers to each control or preview keyboard messages.

For more information, see http://msdn.microsoft.com/en-us/library/ms646267(v=vs.85).aspx[^].

—SA
 
Share this answer
 
v2
Comments
ITGrit 28-Mar-11 9:58am    
I find WM_SETFOCUS and WM_KILLFOCUS also don't respond when left button clicked on the window.
I tried using CWnd derived class in both CDialog and CMyView, but failed.
Thanks for more answer.
Sergey Alexandrovich Kryukov 28-Mar-11 10:36am    
Let's see what can be done... I need time to make a sample; normally I do not develop anything serious in C++. If and when I get some time, I will... You can should your relevant code; maybe, it's something simple.
--SA
ITGrit 28-Mar-11 11:03am    
Thanks a lot and hope for your solution. This problem has fastened on me for one day.
There are lots of possibilities here...

What I would do:

1. First check if the messages are being sent or not. You can do this using Spy++ (it comes with visual studio as an extra app).

2. Once you are sure that the messages are being sent:
- Ensure that you've placed the right message handlers in your code. Messages are "always" sent, so it is possible that you are not handling them.
- Check if any other window in your app is handling those messages, thus capturing them and then preventing your windows to handle them. Depending on the way the messages are handled they die at the handler function...

Hope this helps.
 
Share this answer
 
Comments
ITGrit 28-Mar-11 11:18am    
1.I know Spy++, but too little to use it to do something about check message.
2.The code about the message was bulit by vc6 IDE, so I think all the code is right.The function OnChar and OnKeyDown were not be called. And OnSetFocus wasn't be called when left button down.
I solved this problem. The solution is what SAKryukov had said, and why I couldn't do it is I used the wrong way to set the window focusable. WM_SETFOCUS is just a message to prove the window has focus but can't set the window focusalbe. To set one window has focus, the function SetFocus can do it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900