Best Approach to process KeyStrokes in Rich Edit
-
Hi, I am looking for the best approach to process KeyStroked My code is MFC using Message using message mapping macros I have a number of questions 1) what would the message be for a Keystrokes 2) is the message directed to the Dialog Box that contains the rich edit or is better to have the rich edit process to message 3) if I wrap the CDialog with a CWinThread I can use the ::Run command to process the key strokes
int CWinthread::Run()
{ ASSERT_VALID(this);
MSG m_msgCur;
for tracking the idle time state
if (!flags.is_connected)
return TRUE;
BOOL bIdle = TRUE;
LONG lIdleCount = 0;
// acquire and dispatch messages until a WM_QUIT message is received.
for (;;)
{ phase1: // check to see if we can do idle work
while (bIdle && !::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
{ // call OnIdle while in bIdle state
if (!OnIdle(lIdleCount++))
bIdle = FALSE; // assume "no idle" state
} // phase2: pump messages while available
do { // pump message, but quit on WM_QUIT
if (!PumpMessage())
return ExitInstance();
// reset "no idle" state after pumping "normal" message
if (IsIdleMessage(&m_msgCur)) {
bIdle = TRUE;
lIdleCount = 0;}
} while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
}
ASSERT(FALSE); // not reachable
}thanks for youe help
-
Hi, I am looking for the best approach to process KeyStroked My code is MFC using Message using message mapping macros I have a number of questions 1) what would the message be for a Keystrokes 2) is the message directed to the Dialog Box that contains the rich edit or is better to have the rich edit process to message 3) if I wrap the CDialog with a CWinThread I can use the ::Run command to process the key strokes
int CWinthread::Run()
{ ASSERT_VALID(this);
MSG m_msgCur;
for tracking the idle time state
if (!flags.is_connected)
return TRUE;
BOOL bIdle = TRUE;
LONG lIdleCount = 0;
// acquire and dispatch messages until a WM_QUIT message is received.
for (;;)
{ phase1: // check to see if we can do idle work
while (bIdle && !::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
{ // call OnIdle while in bIdle state
if (!OnIdle(lIdleCount++))
bIdle = FALSE; // assume "no idle" state
} // phase2: pump messages while available
do { // pump message, but quit on WM_QUIT
if (!PumpMessage())
return ExitInstance();
// reset "no idle" state after pumping "normal" message
if (IsIdleMessage(&m_msgCur)) {
bIdle = TRUE;
lIdleCount = 0;}
} while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
}
ASSERT(FALSE); // not reachable
}thanks for youe help
The messages for keystrokes are
WM_KEYDOWN
andWM_KEYUP
. These are directed to the parent dialog containing the control. To have the message directed to the control in MFC, you have to create a class derived fromCRichEditCtrl
and then subclass the control from theInitDialog
function of the dialog class using the SubclassDlgItem[^] method.«_Superman_» _I love work. It gives me something to do between weekends.
-
The messages for keystrokes are
WM_KEYDOWN
andWM_KEYUP
. These are directed to the parent dialog containing the control. To have the message directed to the control in MFC, you have to create a class derived fromCRichEditCtrl
and then subclass the control from theInitDialog
function of the dialog class using the SubclassDlgItem[^] method.«_Superman_» _I love work. It gives me something to do between weekends.
Superman: I respectfully disagree. quote: "The messages for keystrokes are WM_KEYDOWN and WM_KEYUP These are directed to the parent dialog containing the control." Unless dialog does not contain any controls, dialog window never gets focus, hence WN_KEYDOWN and WM_KEYUP messages are not sent to a dialog. quote: "and then subclass the control from the InitDialog function of the dialog class using the SubclassDlgItem method." It is possible to use SubclassDlgItem or SubclassWindow but it would be much easier to let the wizard do subclassing, by simply add variable of the CRichEditCtrl and later replace it with the derived class type. ForNow: Depending what is exactly you are trying to achieve, I think the best way to handle special keys is creating accelerators and add handlers to a CRichEditCtrl derived class.
JohnCz
-
The messages for keystrokes are
WM_KEYDOWN
andWM_KEYUP
. These are directed to the parent dialog containing the control. To have the message directed to the control in MFC, you have to create a class derived fromCRichEditCtrl
and then subclass the control from theInitDialog
function of the dialog class using the SubclassDlgItem[^] method.«_Superman_» _I love work. It gives me something to do between weekends.