Click to See Complete Forum and Search --> : OnKeyDown


pdewitte
May 23rd, 1999, 11:10 AM
As a beginner and a Visual C++ student, I have been asked to create a
dialog with various controls on it, i.e. RadioButtons and Edit boxes.
Part of my assignment was to write code to detect a key combination of
CTRL and X in order to escape from the dialog. From what I have read,
OnKeyDown will only work in a dialog with no controls on it. It would seem
that from my current dialog, I would first have to call up a dialog with no
controls on it, and from the new dialog run any code associated with "CTRL X",
which seems to be contrary to the aims of being able to escape from a dialog
with controls by pressing the key combination of CTRL and X.

Is it possible to detect CTRL and X by some other means, or is it possible
to use the following code in some modified form?
void CExamDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(::GetKeyState(VK_CONTROL)<0)
{
char lsChar;
lsChar = char(nChar);
if (lsChar == 'X')
OnOK();
}
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}



Thanks. PdW.

Dan Haddix
May 23rd, 1999, 03:04 PM
I answered this exact quesition in another thread (proably the same one you read). See

http://www.codeguru.net/bbs/wt/showpost.pl?Board=vc&Number=11815&page=0&view=collapsed&sb=5#Post11815

If for some reason that link doesn't work look for a post with the subject CTRL+X