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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keydown event

Status
Not open for further replies.

dingels35

Programmer
Jan 8, 2002
2
US
I'm having problems finding an event for what i want to do. As a user enters information in a textbox, I want to check a database as they type to fill a box with possible completions. I know in VB there's an onKeyDown event, but I can't find anything similar in VC++. Dows anyone know how to do this???

THANK YOU!
 
Yep, right click your code to open the class wizard. Choose the class in the list to the left. Choose the WM_KEYDOWN on the list to the right. Click on the add function button. This will add a blank function to your code that will handle key down events.
Before you start adding loads of code to this function you may want to first check it works when and how you want by adding a single line such as :

Beep(10000,30); // Assuming you have sound on your PC

If your program beeps at the approriate time, you can write all your string checking code.

Hope this helps.
 
Thank you for the reply. I do still have a question though. I can't get the event to fire. I could only fine the WM_KEYDOWN for the dialog class. I put a message box in there and it never shows. Do you know why?

Thank you again.
 
Try using the EN_CHANGE message instead - it acts like the Change event in VB...

It should be available to textboxes, because I've just dropped one on a dialog to check...

Martin.
 
If its not to late, I think what you want to do is override PreTranslateMessage like so:
Code:
BOOL AmountDlg::PreTranslateMessage(MSG* pMsg) 
{
	if ((pMsg->message == WM_KEYDOWN) && 
	((pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_ESCAPE)))
	{
		if (pMsg->wParam == VK_RETURN)
			MessageBox("Hit Return");
		if (pMsg->wParam == VK_ESCAPE)
			MessageBox("Hit Cancle");
		return FALSE;
	}
	

	return CDialog::PreTranslateMessage(pMsg);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top