Click here to Skip to main content
15,891,136 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralLinker Error Pin
suresh_sathya26-Jan-03 21:53
suresh_sathya26-Jan-03 21:53 
GeneralRe: Linker Error Pin
Daniel Strigl26-Jan-03 22:32
Daniel Strigl26-Jan-03 22:32 
GeneralRe: Linker Error Pin
Mike Nordell27-Jan-03 9:44
Mike Nordell27-Jan-03 9:44 
GeneralMetafile playing(URGENT) Pin
satyavasu26-Jan-03 21:50
satyavasu26-Jan-03 21:50 
GeneralQuestion about thread and TLS Pin
George226-Jan-03 21:40
George226-Jan-03 21:40 
GeneralRe: Question about thread and TLS Pin
George226-Jan-03 21:41
George226-Jan-03 21:41 
GeneralContext menu and Dialog names Pin
Rage26-Jan-03 21:21
professionalRage26-Jan-03 21:21 
GeneralRe: Context menu and Dialog names Pin
KaЯl27-Jan-03 0:23
KaЯl27-Jan-03 0:23 
1) I would derivate a new class CMyRichEditCtrl from CRichEditCtrl, adding these functionnalities

void CMyRichEditCtrl::OnRButtonDown(UINT nFlags, CPoint point) <br />
{<br />
	CPoint local = point;<br />
	ClientToScreen(&point);<br />
	GetParent()->SendMessage(WM_CONTEXTMENU, (WPARAM) GetParent()->GetSafeHwnd(), <br />
		MAKELPARAM(point.x, point.y));<br />
	CRichEditCtrl::OnRButtonDown(nFlags, local);<br />
}<br />
<br />
LRESULT CMyRichEditCtrl::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) <br />
{<br />
	// TODO: Add your specialized code here and/or call the base class<br />
	<br />
	if(message == WM_CONTEXTMENU){<br />
		GetParent()->SendMessage(WM_CONTEXTMENU, wParam, lParam);<br />
		return(0);<br />
	}<br />
	else<br />
		return CRichEditCtrl::DefWindowProc(message, wParam, lParam);<br />
}



The dialog class then implements the answer to the "Context Menu" message (m_RichEdit is an instance of CMyRichEditCtrl):


void CMyDialog::OnContextMenu(CWnd* pWnd, CPoint point) <br />
{<br />
	if (point.x == -1 && point.y == -1){<br />
		//keystroke invocation<br />
		CRect rect;<br />
		m_RichEdit.GetClientRect(rect);<br />
		m_RichEdit.ClientToScreen(rect);<br />
        point = rect.TopLeft();<br />
		point.Offset(5, 5);<br />
	}else{<br />
		CRect codeWindowRect;<br />
<br />
		m_RichEdit.GetWindowRect(&codeWindowRect);<br />
		if(!codeWindowRect.PtInRect(point))<br />
			return;<br />
	}<br />
<br />
<br />
	// load the menu from the resources<br />
	CMenu menu;<br />
	VERIFY(menu.LoadMenu(IDR_CONTEXT_MENU));<br />
<br />
	// loads the sub-menu<br />
	CMenu *pPopup = menu.GetSubMenu(SUB_CCODE);<br />
	ASSERT(pPopup);<br />
<br />
	long lStart, lEnd;<br />
	// according selection, set sensitivity<br />
	m_RichEdit.GetSel(lStart, lEnd);<br />
	pPopup->EnableMenuItem(IDC_COPY, <br />
		MF_BYCOMMAND | ((lStart != lEnd) ? MF_ENABLED : MF_DISABLED | MF_GRAYED));<br />
	pPopup->EnableMenuItem(IDC_CUT, <br />
		MF_BYCOMMAND | ((lStart != lEnd) ? MF_ENABLED : MF_DISABLED | MF_GRAYED));<br />
	pPopup->EnableMenuItem(IDC_PASTE, <br />
		MF_BYCOMMAND | ((m_RichEdit.CanPaste()) ? MF_ENABLED : MF_DISABLED | MF_GRAYED));<br />
	pPopup->EnableMenuItem(IDC_CLEAR, <br />
		MF_BYCOMMAND | ((lStart != lEnd) ? MF_ENABLED : MF_DISABLED | MF_GRAYED));<br />
	pPopup->EnableMenuItem(IDC_UNDO, <br />
		MF_BYCOMMAND | ((m_RichEdit.CanUndo()) ? MF_ENABLED : MF_DISABLED | MF_GRAYED));<br />
<br />
	pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);<br />
}


The dialog class implements also the code for the different menu items.

2) A variation could be to do the "SetWindowText" in the CPropertyPage::OnInitDialog, where the Property Page has a valid HWND.

HTH,

K.




Angels banished from heaven have no choice but to become demons

Cowboy Bebop

GeneralRe: Context menu and Dialog names Pin
Rage27-Jan-03 0:45
professionalRage27-Jan-03 0:45 
Generale-mail client Pin
Anonymous26-Jan-03 21:02
Anonymous26-Jan-03 21:02 
GeneralRe: e-mail client Pin
benjymous27-Jan-03 0:00
benjymous27-Jan-03 0:00 
GeneralRe: e-mail client Pin
Anonymous27-Jan-03 2:40
Anonymous27-Jan-03 2:40 
GeneralRe: e-mail client Pin
Anonymous28-Jan-03 3:58
Anonymous28-Jan-03 3:58 
GeneralEthernet MAC Address, SNMP method Pin
Rok26-Jan-03 20:53
Rok26-Jan-03 20:53 
GeneralScroll to the end of a MFC RichEditCtrl Pin
p8337026-Jan-03 19:51
p8337026-Jan-03 19:51 
GeneralRe: Scroll to the end of a MFC RichEditCtrl Pin
Joerg Wiedenmann26-Jan-03 21:10
Joerg Wiedenmann26-Jan-03 21:10 
GeneralRe: Scroll to the end of a MFC RichEditCtrl Pin
p8337026-Jan-03 21:14
p8337026-Jan-03 21:14 
GeneralRe: Scroll to the end of a MFC RichEditCtrl Pin
Joerg Wiedenmann27-Jan-03 2:44
Joerg Wiedenmann27-Jan-03 2:44 
GeneralMFC linking issues Pin
Anonymous26-Jan-03 19:37
Anonymous26-Jan-03 19:37 
GeneralRe: MFC linking issues Pin
Chris Losinger26-Jan-03 19:44
professionalChris Losinger26-Jan-03 19:44 
GeneralError in OMF type. Pin
73Zeppelin26-Jan-03 18:42
73Zeppelin26-Jan-03 18:42 
GeneralRe: Error in OMF type. Pin
Chris Losinger26-Jan-03 19:43
professionalChris Losinger26-Jan-03 19:43 
GeneralRe: Error in OMF type. Pin
73Zeppelin27-Jan-03 2:12
73Zeppelin27-Jan-03 2:12 
GeneralRe: Error in OMF type. Pin
Chris Losinger27-Jan-03 5:04
professionalChris Losinger27-Jan-03 5:04 
GeneralDWORD, WORD Pin
r i s h a b h s26-Jan-03 17:32
r i s h a b h s26-Jan-03 17:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.