Copy/Pase in FormView dialogen (additional)
-
Hier noch die funktionen die es ermoeglichen bestimmten text aus einer editbox in der formview zu kopieren und zu pasten
Copy
// Get selected text and paste into the clipboard void CFormClass::OnCopy() { if(::GetFocus() == m_EditBox.m_hWnd) { // Get the whole text CString strText; m_EditBox.GetWindowText(strText); // extraxt the only selected area of the text int iStart = 0; int iEnd = 0; m_EditBox.GetSel(iStart, iEnd); strText = strText.Mid(iStart, strText.GetLength() - iEnd); // put to clipboard SetClipboardText(strText); } }Paste
// replace selected text with text from the clipboard void CFormClass::OnPaste() { if(::GetFocus()== m_EditBox.m_hWnd) { // Get the whole text CString strText; m_EditBox.GetWindowText(strText); // what should be added CString strNewText = GetClipboardText(); // remove selection from the text int iStart = 0; int iEnd = 0; m_EditBox.GetSel(iStart, iEnd); strText.Delete(iStart, strText.GetLength() - iEnd); // put the new text on the right position and show the text strText.Insert(iStart, strNewText); m_EditBox.SetWindowText(strText); // set the cursor int iCurPos = iStart + strNewText.GetLength(); //m_EditBox.SetSel(iStart, iCurPos); // the new pastet text is selected m_EditBox.SetSel(iCurPos, iCurPos); // cursor on the end of the pasted text } }
-
Danke!

Ich habs noch angehängt. Zusammenführen geht leider nicht.
-
wart ma, da ist noch n fehler drinn, behebs grad, paste dann den neuen code hier
-
Irgendwie bin ich heute zu schnell.

Kein Problem, ich kann ja ändern.
-
so, nun aber
Paste
void CFormDialog::OnPaste() { HWND focus = ::GetFocus(); CEdit *Element = NULL; if(focus == m_Edit.m_hWnd) Element = &m_Edit; // for additional edit boxes, simply ask and assign here if(Element) { // Get the whole text CString strText; Element->GetWindowText(strText); // Get clipboard text CString strNewText = GetClipboardText(); // Delete the selected area from the text int iStart = 0; int iEnd = 0; Element->GetSel(iStart, iEnd); strText.Delete(iStart, iEnd - iStart); // Add the new text inside strText.Insert(iStart, strNewText); // Set the new text and set the cursor after it Element->SetWindowText(strText); int iCurPos = iStart + strNewText.GetLength(); Element->SetSel(iCurPos, iCurPos); } }Copy
void CFormDialog::OnCopy() { HWND focus = ::GetFocus(); CEdit *Element = NULL; if(focus == m_Edit.m_hWnd) Element = &m_Edit; // for additional edit boxes, simply ask and assign here if(Element) { // Get the whole text CString strText; Element->GetWindowText(strText); // Get the selected area from the text int iStart = 0; int iEnd = 0; Element->GetSel(iStart, iEnd); strText = strText.Mid(iStart, iEnd - iStart); // Set the cplipboard text SetClipboardText(strText); } }
-
eventuell kannst du noch dazu schreiben dass
wenn SetClipboardText oder GetClipboardText als member einer klasse sind, muss
OpenClipboard ohne argumente aufgerufen werden
-
STRG+A (Select all)
void CFormDialog::OnSelectAll() { HWND focus = ::GetFocus(); CEdit *Element = NULL; if(focus == m_Edit.m_hWnd) Element = &m_Edit; // for additional edit boxes, simply ask and assign here if(Element) Element->SetSel(0, Element->GetWindowTextLength()); }
-
Ist auch alles dabei.

-
wunderpraechtig, habe ich nun auch mal was fuer die FAQ getan #gg {=