Click here to Skip to main content
15,923,789 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MSControl on ATL dialog Pin
30-May-01 10:43
suss30-May-01 10:43 
GeneralRe: MSControl on ATL dialog Pin
Matt Philmon30-May-01 17:24
Matt Philmon30-May-01 17:24 
GeneralRe: MSControl on ATL dialog Pin
Matt Philmon30-May-01 17:41
Matt Philmon30-May-01 17:41 
GeneralRe: MSControl on ATL dialog Pin
30-May-01 19:04
suss30-May-01 19:04 
GeneralRe: MSControl on ATL dialog Pin
Matt Philmon31-May-01 4:07
Matt Philmon31-May-01 4:07 
GeneralRe: MSControl on ATL dialog Pin
31-May-01 4:20
suss31-May-01 4:20 
GeneralRe: MSControl on ATL dialog Pin
Matt Philmon31-May-01 10:23
Matt Philmon31-May-01 10:23 
GeneralUnicode Clipboard Pin
29-May-01 13:41
suss29-May-01 13:41 
I'm trying to make Chris's grid control support Unicode copy / paste operations. I've got paste working fine but I can't figure out the copy... The relevant function is below with the parts I've modified in the #ifdef, #endif blocks... It copies the first part of a string but then gets garbeled. Also, if I copy from multiple cells, everything is pasted into a single cell. Where am I going wrong here (I'm guessing I'm not converting between ANSI / Unicode somewhere and mixing the two in the same buffer - but where)

Changing the CacheGlobalData() parameter from UNICODETEXT to just TEXT fixs the formatting problems, but isn't what I'm looking for (for obvious reasons). I'm pasting between my app and Excel and vice versa using Arial Unicode MS font...

Any help much appreciated...

COleDataSource* CGridCtrl::CopyTextFromGrid()
{
    USES_CONVERSION;

    CCellRange Selection = GetSelectedCellRange();
    if (!IsValid(Selection))
        return NULL;

    if (GetVirtualMode())
        SendCacheHintToParent(Selection);

    // Write to shared file (REMEBER: CF_TEXT is ANSI, not UNICODE, so we need to convert)
    CSharedFile sf(GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT);

    // Get a tab delimited string to copy to cache
    CString str;
    CGridCellBase *pCell;
    for (int row = Selection.GetMinRow(); row <= Selection.GetMaxRow(); row++)
    {
        // don't copy hidden cells
        if( m_arRowHeights[row] <= 0 )
            continue;

        str.Empty();
        for (int col = Selection.GetMinCol(); col <= Selection.GetMaxCol(); col++)
        {
            // don't copy hidden cells
            if( m_arColWidths[col] <= 0 )
                continue;

            pCell = GetCell(row, col);
            if (pCell &&(pCell->GetState() & GVIS_SELECTED))
                str += pCell->GetText();

            if (col != Selection.GetMaxCol()) 
                str += _T("\t");
        }
        if (row != Selection.GetMaxRow()) 
            str += _T("\n");

#ifdef _UNICODE
		sf.Write( str, str.GetLength() );
#else
        sf.Write(T2A(str.GetBuffer(1)), str.GetLength());
        str.ReleaseBuffer();
#endif
    }
    
    //char c = '\0';
	TCHAR c = '\0';
    sf.Write(&c, 1);

    if (GetVirtualMode())
        SendCacheHintToParent(CCellRange(-1,-1,-1,-1));

    DWORD dwLen = (DWORD) sf.GetLength();
    HGLOBAL hMem = sf.Detach();
    if (!hMem)
        return NULL;

    hMem = ::GlobalReAlloc(hMem, dwLen, GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT);
    if (!hMem)
        return NULL;

    // Cache data
    COleDataSource* pSource = new COleDataSource();
#ifdef _UNICODE
	pSource->CacheGlobalData(CF_UNICODETEXT, hMem);
#else
	pSource->CacheGlobalData(CF_TEXT, hMem);
#endif

    return pSource;
}

GeneralRe: Unicode Clipboard Pin
Tim Deveaux30-May-01 7:36
Tim Deveaux30-May-01 7:36 
GeneralRe: Unicode Clipboard Pin
30-May-01 13:22
suss30-May-01 13:22 
GeneralImporting existing Dialog interfaces into a new SDI application. Pin
Kimball M. Rudeen29-May-01 13:05
Kimball M. Rudeen29-May-01 13:05 
GeneralRe: Importing existing Dialog interfaces into a new SDI application. Pin
Christian Graus29-May-01 13:12
protectorChristian Graus29-May-01 13:12 
GeneralTimer in a Dialog Box Pin
RobJones29-May-01 12:54
RobJones29-May-01 12:54 
GeneralRe: Timer in a Dialog Box Pin
Christian Graus29-May-01 13:07
protectorChristian Graus29-May-01 13:07 
GeneralRe: Timer in a Dialog Box Pin
RobJones29-May-01 13:30
RobJones29-May-01 13:30 
GeneralRe: Timer in a Dialog Box Pin
Christian Graus29-May-01 13:47
protectorChristian Graus29-May-01 13:47 
GeneralRe: Timer in a Dialog Box Pin
29-May-01 14:43
suss29-May-01 14:43 
GeneralRe: Timer in a Dialog Box Pin
Christian Graus29-May-01 14:53
protectorChristian Graus29-May-01 14:53 
GeneralRe: Timer in a Dialog Box Pin
RobJones30-May-01 6:03
RobJones30-May-01 6:03 
GeneralRe: Timer in a Dialog Box Pin
RobJones30-May-01 8:53
RobJones30-May-01 8:53 
General"Preloading" a driver Pin
29-May-01 12:12
suss29-May-01 12:12 
General'default' button Pin
29-May-01 11:03
suss29-May-01 11:03 
GeneralRe: 'default' button Pin
Hesham Desouky29-May-01 20:26
Hesham Desouky29-May-01 20:26 
GeneralMFC custom control with child Pin
Kayan29-May-01 10:17
Kayan29-May-01 10:17 
GeneralRe: MFC custom control with child Pin
Michael A Barnhart30-May-01 12:02
Michael A Barnhart30-May-01 12:02 

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.