15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Cut-Copy-Paste not working with FormView

Bruce -- bmiller@geographix.com
Thursday, June 06, 1996

NT 3.51, VC++ 4.1
Dell Dimension XPS P90, 32MB RAM

My main view in my MDI app is a dialog-based FormView.  I thought that
the Cut/Copy/Paste commands would automatically be enabled and functional,
but they are not.  In sample apps, they work fine.  The only difference is 
my
view is dialog-based.  I don't know if I have to add this functionality 
myself, or if
a dialog property is not set correctly.  

Basically, the app-defined Cut/Copy/Paste menus are visible but disabled. I 
can 
highlight text in my view's edit box, but cannot cut or copy.

If I need to add this code, is it available on MSDN?

Bruce Miller
bmiller@geographix.com
Why isn't there mouse-flavored cat food?




Vincent Mascart -- 100425.1337@compuserve.com
Sunday, June 09, 1996

>From: 	"Miller, Bruce"
>Sent: 	samedi 8 juin 1996 21:38
>
>NT 3.51, VC++ 4.1
>Dell Dimension XPS P90, 32MB RAM
>
>My main view in my MDI app is a dialog-based FormView.  I thought that
>the Cut/Copy/Paste commands would automatically be enabled and functional,
>but they are not.  In sample apps, they work fine.  The only difference is 
>my
>view is dialog-based.  I don't know if I have to add this functionality 
>myself, or if
>a dialog property is not set correctly.  

You have to had it functionality youself

>Basically, the app-defined Cut/Copy/Paste menus are visible but disabled. I 
>can highlight text in my view's edit box, but cannot cut or copy.

Since you have to implement it yourself, it will not work ... until you
implement it

>If I need to add this code, is it available on MSDN?

I didn't find complete code on MSDN, but some articles helped me to implement
it.

You should read the following articles:
- Implementing the Cut, Copy, and Paste Commands in the Win32 SDK doc on the
VC++ CD
- Clipboard: Using the Windows Clipboard in the VC++ Books\MFC 4.0 doc (also on
the VC++ CD)

Here is some code I implemented in my CMainframe class to handle CF_TEXT format
Cut/Copy/Paste/ etc... It only handle operations for CEdit and CComboBox fields
in views, but I think its the most common usage of clipboard in a CFormView.

void CMainFrame::OnEditCopy() 
{
	CWnd* pWnd = GetFocus();

	if(pWnd!=NULL)
	{
		if(pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
		{
			((CEdit*)pWnd)->Copy();
		} else
		if(pWnd->IsKindOf(RUNTIME_CLASS(CComboBox)))
		{
			((CComboBox*)pWnd)->Copy();
		}
	}
}

void CMainFrame::OnEditCut() 
{
	CWnd* pWnd = GetFocus();

	if(pWnd!=NULL)
	{
		if(pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
		{
			((CEdit*)pWnd)->Cut();
		} else
		if(pWnd->IsKindOf(RUNTIME_CLASS(CComboBox)))
		{
			((CComboBox*)pWnd)->Cut();
		}
	}
}

void CMainFrame::OnEditClear() 
{
	CWnd* pWnd = GetFocus();

	if(pWnd!=NULL)
	{
		if(pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
		{
			((CEdit*)pWnd)->Clear();
		} else
		if(pWnd->IsKindOf(RUNTIME_CLASS(CComboBox)))
		{
			((CComboBox*)pWnd)->Clear();
		}
	}
}

void CMainFrame::OnEditPaste() 
{
	CWnd* pWnd = GetFocus();

	if(pWnd!=NULL)
	{
		if(pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
		{
			((CEdit*)pWnd)->Paste();
		} else
		if(pWnd->IsKindOf(RUNTIME_CLASS(CComboBox)))
		{
			((CComboBox*)pWnd)->Paste();
		}
	}
}

void CMainFrame::OnEditSelectAll() 
{
	CWnd* pWnd = GetFocus();

	if(pWnd!=NULL)
	{
		if(pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
		{
			((CEdit*)pWnd)->SetSel(0,-1);
		} else
		if(pWnd->IsKindOf(RUNTIME_CLASS(CComboBox)))
		{
			((CComboBox*)pWnd)->SetEditSel(0,-1);
		}
	}
}

void CMainFrame::OnEditUndo() 
{
	CWnd* pWnd = GetFocus();

	if(pWnd!=NULL)
	{
		if(pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
		{
			((CEdit*)pWnd)->Undo();
		}
	}
}

void CMainFrame::OnUpdateEditCopy(CCmdUI* pCmdUI) 
{
	int nStartSel, nEndSel;
	DWORD dw;
	CWnd* pWnd = GetFocus();

	if(pWnd!=NULL)
	{
		if(pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
		{
			((CEdit*)pWnd)->GetSel(nStartSel, nEndSel);
			pCmdUI->Enable(nStartSel!=nEndSel);
			return;
		} else
		if(pWnd->IsKindOf(RUNTIME_CLASS(CComboBox)))
		{
			dw = ((CComboBox*)pWnd)->GetEditSel();
			pCmdUI->Enable(HIWORD(dw)!=LOWORD(dw));
			return;
		}
	}
	pCmdUI->Enable(FALSE);
}

void CMainFrame::OnUpdateEditClear(CCmdUI* pCmdUI) 
{
	int nStartSel, nEndSel;
	DWORD dw;
	CWnd* pWnd = GetFocus();

	if(pWnd!=NULL)
	{
		if(pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
		{
			((CEdit*)pWnd)->GetSel(nStartSel, nEndSel);
			pCmdUI->Enable(nStartSel!=nEndSel);
			return;
		} else
		if(pWnd->IsKindOf(RUNTIME_CLASS(CComboBox)))
		{
			dw = ((CComboBox*)pWnd)->GetEditSel();
			pCmdUI->Enable(HIWORD(dw)!=LOWORD(dw));
			return;
		}
	}
	pCmdUI->Enable(FALSE);
}

void CMainFrame::OnUpdateEditCut(CCmdUI* pCmdUI) 
{
	int nStartSel, nEndSel;
	DWORD dw;
	CWnd* pWnd = GetFocus();

	if(pWnd!=NULL)
	{
		if(pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
		{
			((CEdit*)pWnd)->GetSel(nStartSel, nEndSel);
			pCmdUI->Enable(nStartSel!=nEndSel);
			return;
		} else
		if(pWnd->IsKindOf(RUNTIME_CLASS(CComboBox)))
		{
			dw = ((CComboBox*)pWnd)->GetEditSel();
			pCmdUI->Enable(HIWORD(dw)!=LOWORD(dw));
			return;
		}
	}
	pCmdUI->Enable(FALSE);
}

void CMainFrame::OnUpdateEditPaste(CCmdUI* pCmdUI) 
{
	CWnd* pWnd = GetFocus();

	if(pWnd!=NULL)
	{
		if(pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
		{
			pCmdUI->Enable(::IsClipboardFormatAvailable(CF_TEXT));
			return;
		} else
		if(pWnd->IsKindOf(RUNTIME_CLASS(CComboBox)))
		{
			pCmdUI->Enable(::IsClipboardFormatAvailable(CF_TEXT));
			return;
		}
	}
	pCmdUI->Enable(FALSE);
}

void CMainFrame::OnUpdateEditSelectAll(CCmdUI* pCmdUI) 
{
	char sz[2];
	CWnd* pWnd = GetFocus();

	if(pWnd!=NULL && pWnd->IsKindOf(RUNTIME_CLASS(CEdit))
				  || pWnd->IsKindOf(RUNTIME_CLASS(CComboBox)))
	{
		pCmdUI->Enable(pWnd->GetWindowText(sz,2));
		return;
	}
	pCmdUI->Enable(FALSE);
}

void CMainFrame::OnUpdateEditUndo(CCmdUI* pCmdUI) 
{
	CWnd* pWnd = GetFocus();

	if(pWnd!=NULL)
	{
		if(pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
		{
			pCmdUI->Enable(((CEdit*)pWnd)->CanUndo());
			return;
		}
	}
	pCmdUI->Enable(FALSE);
}

Vincent Mascart
100425.1337@compuserve.com






| Вернуться в корень Архива |