System - Zwischenablage mit Unicode



  • heiho,

    Ich habe hier ein kleines problem festgestellt
    und zwar habe ich ein splitter in den MainFrame und in den Splittern werden zwei FormView klassen angezeigt
    funktioniert alles wunderbar, nur ich habe eben gemerkt das Copy/Pase aus edit feldern in den beiden views nicht funktionieren,
    ich muss separat "ID_EDIT_COPY" fangen und verarbeiten, dann geht es
    was muss ich beachten damit es "standardmaessig" funktioniert ?
    bei einer reinen dialog anwendung geht es ja auch #gruebel



  • Das ist bei Formviews normal.
    Ich hab auch ne extra Funktion dafür.

    ..keine Ahnung wieso das nicht standardmäßig geht. 😕



  • shit,
    hast du rein zufaellig die funktion "GetClipboardText" da?
    "SetClipboardText" hatte ich eh schon machen muessen {unicode, also fuer alle sprachen inkl koreanisch, kann ich hier pasten wenn du magst}



  • Mr Evil schrieb:

    shit,
    hast du rein zufaellig die funktion "GetClipboardText" da?

    Sucht du das?

    CString strFromClipboard;
    
    	// get the text from clipboard
    	if(OpenClipboard()) {
    		HANDLE l_hData = GetClipboardData(CF_TEXT);
    		if(NULL == l_hData) {
    			return 0;
    		}
    
    		char *l_pBuffer = (char*)GlobalLock(l_hData);
    		if(NULL != l_pBuffer) {
    			strFromClipboard = l_pBuffer;
    		}
    
    		GlobalUnlock(l_hData);
    		CloseClipboard();
    	}
    

    "SetClipboardText" hatte ich eh schon machen muessen {unicode, also fuer alle sprachen inkl koreanisch, kann ich hier pasten wenn du magst}

    Das wäre doch was für die FAQ. 🙂



  • stimmt, vielen dank

    Hier die Unicode/Multibyte moeglichen copy paste funktionen von CStrings

    Paste a CString into the Clipboard

    BOOL SetClipboardText(CString strText)
    {
        BOOL bRet = FALSE;
        if (OpenClipboard(NULL))
        {
            EmptyClipboard();
            int iLength = strText.GetLength();
            TCHAR *lpszText = strText.GetBuffer();
            HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, (iLength + 1) * sizeof(TCHAR));
            if (hGlobal)
            {
                LPTSTR lpszData = (LPTSTR)GlobalLock(hGlobal);
                if(lpszData)
                {
                    memcpy(lpszData, lpszText, iLength * sizeof(TCHAR));
                    lpszData[iLength] = '\0';
                    GlobalUnlock(hGlobal);
                    if(SetClipboardData(CF_UNICODETEXT, hGlobal))
                        bRet = TRUE;
                }
            }
            CloseClipboard();
        }
        return bRet;
    }
    

    Get a CString from the Clipboard

    CString GetClipboardText()
    {
    	CString strFromClipboard;
    	if(OpenClipboard(NULL))
    	{
    		HANDLE l_hData = GetClipboardData(CF_UNICODETEXT);
    		if(NULL == l_hData)
    			return 0;
    
    		TCHAR *l_pBuffer = static_cast<TCHAR*>(GlobalLock(l_hData));
    		if(NULL != l_pBuffer)
    			strFromClipboard = l_pBuffer;
    
    		GlobalUnlock(l_hData);
    		CloseClipboard();
    	}
    	return strFromClipboard;
    }
    

    Getestet mit englischen und japanischen strings



  • Mr Evil schrieb:

    Hier noch die funktionen die es ermoeglichen bestimmten text aus einer editbox in der formview zu kopieren und zu pasten

    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);
    	}
    }
    

    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());
    }
    

    Mr Evil schrieb:

    eventuell kannst du noch dazu schreiben dass

    wenn SetClipboardText oder GetClipboardText als member einer klasse sind, muss
    OpenClipboard ohne argumente aufgerufen werden


Anmelden zum Antworten