GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Sep-2004, 07:57
Yuri Yuri is offline
New Member
 
Join Date: Sep 2004
Posts: 2
Yuri is on a distinguished road

How to let Enter-key-press message goes to ActiveX control on dialog


I have next problem,

I have dialog and Grid (ActiveX control) on it. But when I edit
some cell and then press Enter, dialog closes.
To not do this, I redefine CDialog::OnOK() in my dialog-class,
and make this function empty. So, when I press Enter this time,
nothing (!) happens. Neither dialog closes nor Grid act like
he must.

What I have to do that Grig will be react on Enter key press (like he
react correct on other keys, like F2)

Thank you,
sorry for my English
Yura
  #2  
Old 08-Sep-2004, 03:29
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 960
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
I don't have much experience with ActiveX controls....
However, with standard MFC controls, all you have to do is implement the KEYDOWN event for the respective control, and then check if the key that you are interested in has been pressed. This is a simple example of catching the pressing of the Delete key inside the list control:

CPP / C++ / C Code:
void CAddSignalDialog::OnKeydownSignalList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;

	if ( pLVKeyDow->wVKey == VK_DELETE)
	{
		int nItem = m_signalList.GetSelectionMark();
		m_signalList.DeleteItem(nItem);
		if ( nItem != m_signalList.GetItemCount() )
		{
			m_signalList.SetItemState(nItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
			m_signalList.SetFocus();
		}
		else
		{
			m_signalList.SetItemState(nItem - 1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
			m_signalList.SetFocus();
		}
		this->configChanged = 1;
	}
			
	
	*pResult = 0;
}

However, you probably know all this, so my post may not fix your problem :-(
Tell me if it helps, though....

Best regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #3  
Old 08-Sep-2004, 05:28
Yuri Yuri is offline
New Member
 
Join Date: Sep 2004
Posts: 2
Yuri is on a distinguished road

ThankZ


Thank you, Luci, for answering!
You see, that grid knows how to react on the such keys like Enter or F2, the problem is to correctly translate the Enter-key press to this control, because dialog "want" to press a default key on pressing enter and so on. If I use an empty redefined OnOK() function, dialog not closes (because CDialog::OnOK() not called at all), but grid also "don't know" that I press Enter key. Bad, but a little helpful solution is:
-----------------------------------------------------------------
Code:
BOOL GroupsFirmsDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN) { return CWnd::PreTranslateMessage(pMsg); } else { return CDialog::PreTranslateMessage(pMsg); }; }
-----------------------------------------------------------------

this cause that effect that I want, but surprisingly it doesn't work when dialog is situated on Tab of CTabCtrl

This connected with MFC mechanism of Message translation. I don't know how to manage with that on that minute, but I planned to research how do that works and find out solution.

If you have some information or ideas, please write.

Thank you, Yura.
Last edited by JdS : 08-Sep-2004 at 09:20. Reason: Please insert your example codes between [code] and [/code] tags
  #4  
Old 08-Sep-2004, 08:40
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 960
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by Yuri
Thank you, Luci, for answering!
You see, that grid knows how to react on the such keys like Enter or F2, the problem is to correctly translate the Enter-key press to this control, because dialog "want" to press a default key on pressing enter and so on.

Did you add the KeyPress Stock Event?

Quote:
Originally Posted by Yuri
this cause that effect that I want, but surprisingly it doesn't work when dialog is situated on Tab of CTabCtrl

This connected with MFC mechanism of Message translation.

Yes, the CTabCtrl sends the notification messages to it's parent and needs it to handle them....
Please read this article:
http://www.codeguru.com/Cpp/W-D/disl...cle.php/c4965/

Regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
 
 

Recent GIDBlogUS Elections and the ?Voter?s Responsibility? by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:40.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.