Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WM_KEYDOWN and controls,

Status
Not open for further replies.

minifiredragon

Programmer
Jun 29, 2003
68
US
How do you stop a control of intercepting the WM_KEYDOWN event??
 
What is your background? If your just starting out you need to use a tutorial or book or something. You can't learn C++ Windows programming by winging it in forums.

And what the heck does this mean?

>> I had a 3 controls in the dialog box.

from your previous post.

-pete
 
I have gone through 2 tutorial books on visual C++. I have written some java applets, coldfusion, html and plugins for Lightwave (Graphical design). I also have studied a great deal of MASM.

I am not all that familiar with MFC which is where I am having my problems. I was unaware that controls intercept key strokes. Which is why in my previous post I couldn't get the keydown to work. What do I mean by controls? I have 3 static text windows on the opening window. Each one I added a control and a string member variable to allow me to change the font size and type as well as what each window displays textwise.

I found on MS's website how to trap the WM_KEYDOWN event. But it is for dialog boxes and when I integrated (or tried to integrate) the steps into my application it complained because it was a View class and not a Dialog class, and I know all windows can be thought of as dialog boxes. I just need to examine the code more to see where I really need to change it.

So right now, the only road block I have is trying to grab the WM_KEYDOWN event. But I am considering just redesigning the application and using button driven prompts, since like I stated in my previous post, it is just for testing purposes. When I am finished, there will be no keyboard or mouse input for it.
 
>> it complained because it was a View class and not a Dialog class
>> trying to grab the WM_KEYDOWN event.

So you have an MFC CView derived class and you wish to capture the WM_KEYDOWN event. As i stated in my previous post it is simple to capture that event in a CView derived class. Use the Class Wizard to create a handler for WM_KEYDOWN... done. That's it.

You say you have gone through 2 tutorials on VC++. Did they cover building MFC apps and working with the Document/View framework? If they did not, you need a book that does. If they do then you may need to go back through the tutorials again. This is MFC 101 and it must be covered in a book that covers MFC for beginners.

-pete
 
Let me explain to you what exactly I did to build this application.

I used the Appwizard (exe)
I used Single Document option
I used Database with File Support option (MS Access database)
I used Winsock option

I added three static texts to the View Dialog (window C++ opens up after application is set up).

to each of the stat texts i added: (each with different names)
m_ctlWindow Control
m_strWindow String

Next I added code to alter the font size of the static boxes as well as code to change the text.

The above all works fine. Then I added a dialog box to the application, which also works (I used WM_LBUTTONDOWN) to test that.

I then added the WM_KEYDOWN through the class wizard. It doesn't work. Then I stumble across this little note in one of my books. "You cannot have any controls on your dialog box if you want to capture Mouse or Keyboard events because they are passed to the controls." (not word for word).

So I check this statement out. I removed all my Static texts and guess what! It worked! But I want the static text for message display. Which takes me back to how do I catch the WM_KEYDOWN event, since it is being passed right to my controls. If you want to see the code I can send it to you tonight.
 
>> Let me explain to you what exactly I did to build this application.

Well you still have not explained exactly what you did. So i will guess from your post that you do not have a CView derived class you have a CFormView derived class which means you have a Dialog Window. As you now know Dialog Windows behave differently.

Since your using a Dialog Window (if i guessed correctly), you need to read about Message Reflection. We just discussed this recently, here is a link to that thread: thread207-586634

-pete
 
Sorry, yes CFormView Class. What more can I give you to help me understand what I am doing wrong?
 
Thank you all for your insite into my problems.

palbano: the places you told me to look was of no help.

I considered using accelerated keys or the PreTranslate message. I settled with the final coding:

BOOL CICServerView::preTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_KEYDOWN && pMsg->wParam == 'I')
{

//Initialize InsertDlg window
CInsertDlg dlgInsertDlg;

//OPen Window
dlgInsertDlg.DoModal();
return 1;
}

return CFormView::preTranslateMessage(pMsg) ;
}


That worked like a charm. :)
Thanks again!
 
>> That worked like a charm. :)

Sure it does... so would writing a windows procedure function :)

I would have told you that at the start but i thought you were trying to figure out how to use the MFC architecture.

>> Thanks again!

Your welcome!

-pete
 
Yes, figure out how to use MFC architecture, but more gradually. This won't be the last time i use MFC. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top