Discussion:
Hitting the Enter Key While in Edit Boxes..
(too old to reply)
k***@gmail.com
2006-08-30 19:39:04 UTC
Permalink
I have a tab control with a property sheet for each tab control. When
switching between tabs the property sheets show and hide according to
which tab the user clicks on. Whenever I put the cursor in an edit box
and press enter, the property sheet goes blank.. anyone know of a good
solution for this?

Frank B.
AliR
2006-08-30 19:58:45 UTC
Permalink
Set the ES_WANTRETURN flag of the Edit control. I think the OnOK handler of
the dialog is getting called, and hiding or closing the inner dialog.

AliR.
Post by k***@gmail.com
I have a tab control with a property sheet for each tab control. When
switching between tabs the property sheets show and hide according to
which tab the user clicks on. Whenever I put the cursor in an edit box
and press enter, the property sheet goes blank.. anyone know of a good
solution for this?
Frank B.
k***@gmail.com
2006-08-30 20:27:39 UTC
Permalink
What would the lines of code look like to set the ES_WANTRETURN flag?

Frank B.
Post by AliR
Set the ES_WANTRETURN flag of the Edit control. I think the OnOK handler of
the dialog is getting called, and hiding or closing the inner dialog.
AliR.
Post by k***@gmail.com
I have a tab control with a property sheet for each tab control. When
switching between tabs the property sheets show and hide according to
which tab the user clicks on. Whenever I put the cursor in an edit box
and press enter, the property sheet goes blank.. anyone know of a good
solution for this?
Frank B.
AliR
2006-08-30 20:47:44 UTC
Permalink
You can set that in the resource editor, select the edit control and set the
Want Return flag to true.

Or m_Edit.ModifyStyle(0,ES_WANTRETURN);

AliR.
Post by k***@gmail.com
What would the lines of code look like to set the ES_WANTRETURN flag?
Frank B.
Post by AliR
Set the ES_WANTRETURN flag of the Edit control. I think the OnOK handler of
the dialog is getting called, and hiding or closing the inner dialog.
AliR.
Post by k***@gmail.com
I have a tab control with a property sheet for each tab control. When
switching between tabs the property sheets show and hide according to
which tab the user clicks on. Whenever I put the cursor in an edit box
and press enter, the property sheet goes blank.. anyone know of a good
solution for this?
Frank B.
k***@gmail.com
2006-08-30 21:01:06 UTC
Permalink
I set the flag in the resource editor, but the property sheet still
disappears after i hit enter when in the box. If I click on another
tab, and then back to the one I was just on, then the tab reappears.
Is there a way to direct the enter key to a button instead?

Frank B.
Post by AliR
You can set that in the resource editor, select the edit control and set the
Want Return flag to true.
Or m_Edit.ModifyStyle(0,ES_WANTRETURN);
AliR.
Post by k***@gmail.com
What would the lines of code look like to set the ES_WANTRETURN flag?
Frank B.
Post by AliR
Set the ES_WANTRETURN flag of the Edit control. I think the OnOK
handler of
Post by k***@gmail.com
Post by AliR
the dialog is getting called, and hiding or closing the inner dialog.
AliR.
Post by k***@gmail.com
I have a tab control with a property sheet for each tab control. When
switching between tabs the property sheets show and hide according to
which tab the user clicks on. Whenever I put the cursor in an edit
box
Post by k***@gmail.com
Post by AliR
Post by k***@gmail.com
and press enter, the property sheet goes blank.. anyone know of a
good
Post by k***@gmail.com
Post by AliR
Post by k***@gmail.com
solution for this?
Frank B.
AliR
2006-08-30 21:11:07 UTC
Permalink
Forget everything I said so far. I had a brain fart. I had to write a
sample app to realize that. I am not really sure why it's behaving like
that.

AliR.
Post by k***@gmail.com
I set the flag in the resource editor, but the property sheet still
disappears after i hit enter when in the box. If I click on another
tab, and then back to the one I was just on, then the tab reappears.
Is there a way to direct the enter key to a button instead?
Frank B.
Post by AliR
You can set that in the resource editor, select the edit control and set the
Want Return flag to true.
Or m_Edit.ModifyStyle(0,ES_WANTRETURN);
AliR.
Post by k***@gmail.com
What would the lines of code look like to set the ES_WANTRETURN flag?
Frank B.
Post by AliR
Set the ES_WANTRETURN flag of the Edit control. I think the OnOK
handler of
Post by k***@gmail.com
Post by AliR
the dialog is getting called, and hiding or closing the inner dialog.
AliR.
Post by k***@gmail.com
I have a tab control with a property sheet for each tab control.
When
Post by k***@gmail.com
Post by AliR
Post by k***@gmail.com
Post by AliR
Post by k***@gmail.com
switching between tabs the property sheets show and hide according to
which tab the user clicks on. Whenever I put the cursor in an edit
box
Post by k***@gmail.com
Post by AliR
Post by k***@gmail.com
and press enter, the property sheet goes blank.. anyone know of a
good
Post by k***@gmail.com
Post by AliR
Post by k***@gmail.com
solution for this?
Frank B.
AliR
2006-08-30 21:15:50 UTC
Permalink
But this seems to do the trick in my sample app

BOOL CSheet::PreTranslateMessage(MSG *pMsg)

{

if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)

{

return TRUE;

}

return CPropertySheet::PreTranslateMessage(pMsg);

}

BOOL CPage::PreTranslateMessage(MSG *pMsg)

{

if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)

{

return TRUE;

}

return CPropertyPage::PreTranslateMessage(pMsg);

}



AliR.
Post by k***@gmail.com
I have a tab control with a property sheet for each tab control. When
switching between tabs the property sheets show and hide according to
which tab the user clicks on. Whenever I put the cursor in an edit box
and press enter, the property sheet goes blank.. anyone know of a good
solution for this?
Frank B.
k***@gmail.com
2006-08-30 21:28:06 UTC
Permalink
Do I need to put anything in my MESSAGE MAP in order to direct to this
code? How does the dialog box know when to call PreTranslateMessage?
Post by AliR
But this seems to do the trick in my sample app
BOOL CSheet::PreTranslateMessage(MSG *pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
return TRUE;
}
return CPropertySheet::PreTranslateMessage(pMsg);
}
BOOL CPage::PreTranslateMessage(MSG *pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
return TRUE;
}
return CPropertyPage::PreTranslateMessage(pMsg);
}
AliR.
Post by k***@gmail.com
I have a tab control with a property sheet for each tab control. When
switching between tabs the property sheets show and hide according to
which tab the user clicks on. Whenever I put the cursor in an edit box
and press enter, the property sheet goes blank.. anyone know of a good
solution for this?
Frank B.
k***@gmail.com
2006-08-30 21:41:36 UTC
Permalink
Jesus on ice skates.. it worked. Is there a place where I can look up
all of these afx_msg functions?
Post by AliR
But this seems to do the trick in my sample app
BOOL CSheet::PreTranslateMessage(MSG *pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
return TRUE;
}
return CPropertySheet::PreTranslateMessage(pMsg);
}
BOOL CPage::PreTranslateMessage(MSG *pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
return TRUE;
}
return CPropertyPage::PreTranslateMessage(pMsg);
}
AliR.
Post by k***@gmail.com
I have a tab control with a property sheet for each tab control. When
switching between tabs the property sheets show and hide according to
which tab the user clicks on. Whenever I put the cursor in an edit box
and press enter, the property sheet goes blank.. anyone know of a good
solution for this?
Frank B.
AliR
2006-08-30 21:45:24 UTC
Permalink
Post by k***@gmail.com
Do I need to put anything in my MESSAGE MAP in order to direct to this
code? How does the dialog box know when to call PreTranslateMessage?
Actually PreTranslateMessage is a virtual method of CWnd.

All you have to do is put this in the h file

virtual BOOL PreTranslateMessage(MSG *pMsg);
Post by k***@gmail.com
Jesus on ice skates.. it worked. Is there a place where I can look up
all of these afx_msg functions?
Look at the overridables and message handler method of CWnd for the general
ones.

AliR.
Tom Serface
2006-08-30 21:59:25 UTC
Permalink
Look here:

http://msdn2.microsoft.com/en-us/library/b5wzwdk7.aspx

"Jesus on ice skates"??? There's one I haven't heard before :o)

Tom
Post by k***@gmail.com
Jesus on ice skates.. it worked. Is there a place where I can look up
all of these afx_msg functions?
Post by AliR
But this seems to do the trick in my sample app
Joseph M. Newcomer
2006-08-30 21:55:51 UTC
Permalink
Which will work until there is a multiline edit control in one of the pages...

I would be inclined to add virtual methods OnOK and OnCancel and give them empty bodies.
joe
Post by AliR
But this seems to do the trick in my sample app
BOOL CSheet::PreTranslateMessage(MSG *pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
return TRUE;
}
return CPropertySheet::PreTranslateMessage(pMsg);
}
BOOL CPage::PreTranslateMessage(MSG *pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
return TRUE;
}
return CPropertyPage::PreTranslateMessage(pMsg);
}
AliR.
Post by k***@gmail.com
I have a tab control with a property sheet for each tab control. When
switching between tabs the property sheets show and hide according to
which tab the user clicks on. Whenever I put the cursor in an edit box
and press enter, the property sheet goes blank.. anyone know of a good
solution for this?
Frank B.
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
AliR
2006-08-31 14:26:54 UTC
Permalink
The problem is that CPropertySheet inherits from CWnd and OnOK and OnCancel
are not implemented. Seems like CPropertySheet does something with
VK_RETURN in its winproc.

The one in CPropretyPage is really not needed. So if he ever wants to put a
multiline edit control in there all he has to do is get rid of the one in
CPropertyPage derived class.

AliR.
Post by Joseph M. Newcomer
Which will work until there is a multiline edit control in one of the pages...
I would be inclined to add virtual methods OnOK and OnCancel and give them empty bodies.
joe
Post by AliR
But this seems to do the trick in my sample app
BOOL CSheet::PreTranslateMessage(MSG *pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
return TRUE;
}
return CPropertySheet::PreTranslateMessage(pMsg);
}
BOOL CPage::PreTranslateMessage(MSG *pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
return TRUE;
}
return CPropertyPage::PreTranslateMessage(pMsg);
}
AliR.
Post by k***@gmail.com
I have a tab control with a property sheet for each tab control. When
switching between tabs the property sheets show and hide according to
which tab the user clicks on. Whenever I put the cursor in an edit box
and press enter, the property sheet goes blank.. anyone know of a good
solution for this?
Frank B.
Joseph M. Newcomer [MVP]
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer
2006-09-01 19:02:47 UTC
Permalink
There are some fascinating bugs involved in, say, editing a label in a tree control in a
property page, which require using a PreTranslateMessage handler.

In this code, the PreTranslateMessage handler checks for the ES_WANTRETURN style. In
fact, what it does is check the class of the window; only if it is an edit control is
anything ever checked. It also checks for the WM_GETDLGCODE returns from the control. So
it can be made robust, but a raw test just for VK_RETURN won't generalize.
joe
Post by AliR
The problem is that CPropertySheet inherits from CWnd and OnOK and OnCancel
are not implemented. Seems like CPropertySheet does something with
VK_RETURN in its winproc.
The one in CPropretyPage is really not needed. So if he ever wants to put a
multiline edit control in there all he has to do is get rid of the one in
CPropertyPage derived class.
AliR.
Post by Joseph M. Newcomer
Which will work until there is a multiline edit control in one of the
pages...
Post by Joseph M. Newcomer
I would be inclined to add virtual methods OnOK and OnCancel and give them
empty bodies.
Post by Joseph M. Newcomer
joe
Post by AliR
But this seems to do the trick in my sample app
BOOL CSheet::PreTranslateMessage(MSG *pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
return TRUE;
}
return CPropertySheet::PreTranslateMessage(pMsg);
}
BOOL CPage::PreTranslateMessage(MSG *pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
return TRUE;
}
return CPropertyPage::PreTranslateMessage(pMsg);
}
AliR.
Post by k***@gmail.com
I have a tab control with a property sheet for each tab control. When
switching between tabs the property sheets show and hide according to
which tab the user clicks on. Whenever I put the cursor in an edit box
and press enter, the property sheet goes blank.. anyone know of a good
solution for this?
Frank B.
Joseph M. Newcomer [MVP]
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Continue reading on narkive:
Loading...