if(IsClipboardFormatAvailable(CF_TEXT))
{
CString strIsUrl;
strIsUrl = (CString)(char *)GetClipboardData(CF_TEXT);
AfxMessageBox(strIsUrl);
}
应该怎样取?

解决方案 »

  1.   

    最好这样:
    if(IsClipboardFormatAvailable(CF_TEXT))
    {
    CString strIsUrl;
                      HGLOBAL hglb=GetClipboardData(CF_TEXT);
    strIsUrl = (CString)(char *)GlobalLock(hglb);
                      GlobalUnlock(hglb);
    AfxMessageBox(strIsUrl);
    }
    不过你写的好像也行,因为在win32下,Global内存分配已经没有,所以GlobalAlloc返回的就已经是合法指针。msdn例子标准的方法
            hglb = GetClipboardData(CF_TEXT); 
            if (hglb != NULL) 
            { 
                lptstr = GlobalLock(hglb); 
                if (lptstr != NULL) 
                { 
                    // Call the application-defined ReplaceSelection 
                    // function to insert the text and repaint the 
                    // window. 
     
                    ReplaceSelection(hwndSelected, pbox, lptstr); 
                    GlobalUnlock(hglb); 
                } 
            } 
            CloseClipboard();