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!

Visual C++ keydown in View Class

Status
Not open for further replies.

minifiredragon

Programmer
Jun 29, 2003
68
US
First off, I am farely new to C++ programming. Now, for my problem. I am developing a small application that requires no user intereaction (no keyboard or mouse), But I want to run some tests to emulate the hardware before I shell out $3000 on the needed equipment. The program accesses a database and keeps track of user information. I created an SDI application with support for database and winsock. Now I start writing my code and controls and I run into this teeny tiny problem. In the view class, I set an WM_KEYDOWN command and have it check if it was the letter "I". When I compile the code and press I, it does a system ding. I get the same response for all the keys. What in the world have I done wrong?? I used the Classwizard to add my WM_KEYDOWN event by right clicking on my opening window (which is a view class). Here is the chunk of code.


void CICServerView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default

char lsChar; //Character being pressed
HCURSOR lhCursor;


//Convert key pressed to character
lsChar = char(nChar);

//Is Keypress "I"?
if (lsChar == 'I'){

lhCursor = AfxGetApp()->LoadStandardCursor(IDC_WAIT);
//Initialize InsertDlg window
CInsertDlg dlgInsertDlg;

//OPen Window
dlgInsertDlg.DoModal();

}




CRecordView::OnKeyDown(nChar, nRepCnt, nFlags);
}

It was suppose to open up a dailog box, but I thought maybe I didn't set up the dialog box right. So I set it to change the cursor. It doesn't work, and it compiles and opens up just fine.

Any one experience this before??

Thanks for any help.
 
Most likely the condition ( if (lsChar == 'I')) is not evaluating to true

-pete
 
I tried running it without the check and it still didn't respond. Here is a code I tried within the event.

HCURSOR lhCursor;

lhCursor = AfxGetApp()->LoadStandardCursor(IDC_WAIT);
 
I really don't get what is happening. I added a WM_LEFTBUTTONUP command and that works, but not my keystroke. Is there a bug or something in Visual C++ that screws up the keydown function?
 
>> Is there a bug or something in Visual C++ that
>> screws up the keydown function?

I can't tell what your problem is from your posts. I can tell you that when i create a new VC++ SDI application and add a WM_KEYDOWN handler in the CView derived class that looks like this:
Code:
void CSdiRndView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: Add your message handler code here and/or call default
	TRACE("OnKeyDown\r\n");

	CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

When i run the application in DEBUG mode and click in the view and press a key, i see the message in the Output window as expected.

-pete
 
Sorry folks, I found m answer. :(

I had a 3 controls in the dialog box. :(

How do I get the controls to ignore wm_keydown??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top