Click to See Complete Forum and Search --> : CTRL + X


kjmac
May 23rd, 1999, 11:52 AM
I am very new to C++ in a Visual environment. Does anyone have a suggestion how to implement CTRL + X into a dialog to exit the
program. Have tried various combinations to no avail, if someone can help, it would be much appreciated.

kj

pdewitte
May 23rd, 1999, 01:50 PM
I don't think it's possible in the context of your dialog.
Supposedly, what you are trying to do can only be done in a dialog
with no controls on it, such as painting with a mouse.
Methinks Darren expects the impossible, or at least something
he hasn't explained yet.

See my posting - OnKeyDown -
The code there works if you create a form with nothing else on it.

Pete.

Dan Haddix
May 23rd, 1999, 02:53 PM
Yes it can be done, it just takes a little ingenuity!! Try this

1) Create a new accelerator resource, and make and entry for Ctrl+X who's ID is mapped to IDCANCLE

2) Create a member variable in your dialog class like this

HACCEL m_hAccel;



3) Initialize the variable in the dialogs constructor, and load the accelerator into the dialog like so

m_hAccel = ::LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1));



3) Overload the PreTranslateMessage handler in the dialog like so

BOOL CYourtDlg::PreTranslateMessage(MSG* pMsg)
{
if (m_hAccel != NULL)
if(::TranslateAccelerator(m_hWnd, m_hAccel, pMsg))
return TRUE;

return CDialog::PreTranslateMessage(pMsg);
}



That all there is to it!!!

mxu
June 22nd, 1999, 10:36 AM
Hi,

I'd like to define hot keys for edit box in my dialog. One of the hot keys is like "Ctrl+Alt+A" which ideally could insert "ALPHA" in Edit box when it gets pressed. I've tried the method you posted and it failed on "::TranslateAccelerator(m_hWnd, m_hAccel, pMsg)". (the returned value is 0. When I tried to capture the error code with GetLastError, it returned 0.) What might be wrong? Please help. Also do you other ways that I can use? Thank you very much for your time.

mxu

MXu