CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

求救!!! 取ie浏览器文字乱码问题,高分相赠!!!

楼主macrogu()2002-10-09 16:41:08 在 VC/MFC / 基础类 提问

我所写的一个程序中有这样一个功能:用户选取了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,请各位高人指点,一定高分相赠!!!  
  问题点数:100、回复次数:6Top

1 楼nuaazwg(潇湘浪客)回复于 2002-10-09 17:12:38 得分 10

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();  
  }  
   
  这样试试!Top

2 楼icansaymyabc(学习与进步)回复于 2002-10-09 17:14:23 得分 10

把你的程序改成这样看起来对了,你试试。  
      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();  
    }  
      }  
  Top

3 楼jiangsheng(蒋晟.Net[MVP])回复于 2002-10-09 17:19:25 得分 70

IMultiLanguage::ConvertStringFromUnicode   Method  
   
  --------------------------------------------------------------------------------  
   
  Translates   the   source   Unicode   string   to   the   specified   multibyte   code   page.    
   
  Syntax  
   
  HRESULT   ConvertStringFromUnicode(  
          DWORD   *pdwMode,  
          DWORD   dwEncoding,  
          WCHAR   *pSrcStr,  
          UINT   *pcSrcSize,  
          CHAR   *pDstStr,  
          UINT   *pcDstSize  
  );  
   
  Parameters  
   
  pdwMode  
  [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   Value  
   
  Returns   one   of   the   following   values:  
   
  S_OK   Success.      
  S_FALSE   The   specified   conversion   is   not   supported   on   the   system.      
  E_FAIL   An   error   occurred.      
   
  Remarks  
   
  Note   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   Also  
   
  IMultiLanguage2::ConvertStringFromUnicodeEx,   IMultiLanguage2::ConvertStringInIStream,   IMultiLanguage2::ConvertStringToUnicodeEx  
   
  --------------------------------------------------------------------------------  
   
  ©   2001   Microsoft   Corporation.   All   rights   reserved.   Terms   of   use.Top

4 楼icansaymyabc(学习与进步)回复于 2002-10-09 17:19:51 得分 10

nuaazwg(潇湘浪客)   是错的。Top

5 楼macrogu()回复于 2002-10-10 13:38:47 得分 0

多谢各位,好像还是不行,我在日文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);  
  给个例子好吗,谢谢!!!  
  Top

6 楼jiangsheng(蒋晟.Net[MVP])回复于 2002-10-12 01:57:15 得分 0

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).  
   
  Top

相关问题

  • 求救!!! 取ie浏览器文字乱码问题,高分相赠!!!
  • IE浏览器
  • IE浏览器的问题
  • IE浏览器的问题
  • IE浏览器的问题
  • 修改ie浏览器?
  • 有关IE浏览器
  • 一个关于浏览器乱码的问题?
  • 我的浏览器标题总是显示乱码
  • 关于IE浏览器的问题

关键词

  • .net
  • win32 api
  • 乱码
  • 文字
  • 中文
  • ie
  • unicode
  • null
  • dwencoding
  • 剪贴板

得分解答快速导航

  • 帖主:macrogu
  • nuaazwg
  • icansaymyabc
  • jiangsheng
  • icansaymyabc

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo