我所写的一个程序中有这样一个功能:用户选取了ie浏览器中的一段文字copy到剪贴板,我的程序从剪贴板中取出文字并显示在edit框中,这在中文系统下没有任何问题,而当程序运行在英文日文98下时,ie中的中文字符从剪贴板中取后在edit框中显示为
乱码,edit框已设了MS Song体,能正确显示gb2312编码的汉字,估计ie中的中文为unicode什么的,我就想把它转为ascii码,但试了很多方法都不行.if(OpenClipboard())
{
   if(IsClipboardFormatAvailable (CF_UNICODETEXT))
  {
    WCHAR *s;
    CString string;
    HANDLE handle=GetClipboardData(CF_UNICODETEXT);
    s=(WCHAR*)handle;
    string=s;
    string.TrimLeft();
    string.TrimRight();
    if(string!="")
   {
     char dest[256];
     len=string.GetLength();
     int len = WideCharToMultiByte(CP_ACP,0,s,len,dest,256,NULL,NULL);
     GetDlgItem(IDC_EDIT1)->SetWindowText(dest);//显示乱码
   }
   EmptyClipboard();
   CloseClipboard();
}到底ie中的中文字符是什么编码,怎样转成gb2312,请各位高人指点,一定高分相赠!!!

解决方案 »

  1.   

    if(OpenClipboard())
    {
       if(IsClipboardFormatAvailable (CF_UNICODETEXT))
      {
        TCHAR *s;
        CString string;
        HANDLE handle=GetClipboardData(CF_UNICODETEXT);
        s=(TCHAR*)handle;
        string=s;
        string.TrimLeft();
        string.TrimRight();
        
    GetDlgItem(IDC_EDIT1)->SetWindowText(s);
       
       EmptyClipboard();
       CloseClipboard();
    }这样试试!
      

  2.   

    把你的程序改成这样看起来对了,你试试。
      if(OpenClipboard(NULL))
      {
         if(IsClipboardFormatAvailable (CF_OEMTEXT))
     {
           char *s;
           CString string;
           HANDLE handle=GetClipboardData(CF_OEMTEXT);
           s=(char *)handle;
           string=s;
           string.TrimLeft();
           string.TrimRight();
           if(string!="")
       {
             MessageBox(0,string,"ansi",MB_OK);//显示乱码
       }
     //      EmptyClipboard();
           CloseClipboard();
     }
      }
      

  3.   

    IMultiLanguage::ConvertStringFromUnicode Method--------------------------------------------------------------------------------Translates the source Unicode string to the specified multibyte code page. SyntaxHRESULT ConvertStringFromUnicode(
        DWORD *pdwMode,
        DWORD dwEncoding,
        WCHAR *pSrcStr,
        UINT *pcSrcSize,
        CHAR *pDstStr,
        UINT *pcDstSize
    );ParameterspdwMode
    [in, out] Storage for conversion context. A calling function should only provide storage that is initialized with zero at the first call to the method. The caller should not modify the value. 
    dwEncoding
    [in] Code page identifier value for the destination multibyte string. This value is equivalent to the uiCodePage member of the MIMECPINFO structure assigned to dwEncoding. 
    pSrcStr
    [in] Address of the Unicode string that is to be converted. 
    pcSrcSize
    [in, out] Address of the buffer that stores the length of the source string, in character counts. If this is NULL, or if -1 is specified as the length, the API assumes pSrcStr is null-terminated. When conversion is successful, the method returns the number of characters processed to this buffer. 
    pDstStr
    [in] Address of the string buffer where the conversion result will be stored. 
    pcDstSize
    [in, out] Address of the buffer that stores the length of pDstStr, in byte counts. When conversion is successful, the method returns the number of bytes copied to pDstStr to this buffer. 
    Return ValueReturns one of the following values:S_OK Success.  
    S_FALSE The specified conversion is not supported on the system.  
    E_FAIL An error occurred.  ResNote that the size of the Unicode string to be converted is specified with a character count, while the size of the multibyte string returned is given in bytes. See AlsoIMultiLanguage2::ConvertStringFromUnicodeEx, IMultiLanguage2::ConvertStringInIStream, IMultiLanguage2::ConvertStringToUnicodeEx--------------------------------------------------------------------------------© 2001 Microsoft Corporation. All rights reserved. Terms of use.
      

  4.   

    nuaazwg(潇湘浪客) 是错的。
      

  5.   

    多谢各位,好像还是不行,我在日文98下.
     jiangsheng(蒋晟.Net): 
    IMultiLanguage2::ConvertStringFromUnicode好像是用在Windows CE,.Net下,MFC能用吗?我这样写好像编译通不过.#include "Mlang.h"CHAR dest[256];
    DWORD pdwMode;
    DWORD dwEncoding;
    UINT  pcSrcSize=string.GetLength();
    UINT  pcDstSize=256;
    IMultiLanguage::ConvertStringFromUnicode(&pdwMode,dwEncoding,s,&pcSrcSize,dest,&pcDstSize);
    给个例子好吗,谢谢!!!
      

  6.   

    http://www.batutis.com/i18n/papers/mlang/
    Using IMultiLanguage2
     To access the methods provided by IMultiLanguage2, a program must instantiate a MultiLanguage object and request the IMultiLanguage2 interface. This is can be done via the COM API CoCreateInstance. For example:    hr = CoCreateInstance(                           CLSID_CMultiLanguage, //Class identifier (CLSID) of the object                           NULL,                                              //Pointer to controlling IUnknown                           CLSCTX_INPROC_SERVER,   //Context for running executable code                           IID_IMultiLanguage2 ,                  //Reference to the identifier of the interface                           (void**) &pMultiLanguage2               //Address of output variable that receives                                                                               // the interface pointer requested in riid                           ); This call will return the address of the IMultiLanguage2 interface in pMultiLanguage2. Note that if you are using Microsoft Visual C++ (MSVC) to create an IMultiLanguage2 client you will need to install a recent version of the Microsoft Platform SDK (the April 2000 version is sufficient). The Mlang.h and UUID.LIB that are supplied with MSVC itself do not support IMultiLanguage2. Once the program has retrieved the interface pointer, it can then make calls into the IMultiLanguage2 API methods. For example:     pMultiLanguage2->ConvertString(            pdwMode,                                                            1252,                                                            437,                                                            pSrcStr,                                                            pcSrcSize,                                                            pDstStr,                                                            pcDstSize                                                            ); This call copies characters from the source buffer to the destination buffer while doing an encoding conversion from code page 1252 to code page 437. One might wonder why Microsoft created this API when there’s a pair of perfectly good Win32 APIs that can be used to do the same thing: MultibyteToWideChar and WideCharToMultibyte. Not only can this pair of calls do what IMultiLanguage2::ConvertString can do, but also you can supply a number of additional options in the Win32 APIs to control the conversion more completely. In addition, the Win32 APIs return more useful error codes.  One reason might be the apparent inability of MultibyteToWideChar and WideCharToMultibyte to support popular Internet encodings like EUC‑KR and ISO‑2022‑JP on Windows NT 4 and Windows 95/98 even with the appropriate language pack installed. (There is no such limitation on Windows 2000.) Perhaps the Windows and IE development teams are finally in synch in this respect. However, at this writing, there are some useful options available via the MLang Converter object that are not available via the Win32 APIs (see below).