2)如何用VC显示gb18030的4字节编码所表示的汉字?
1)为什么发贴不让给分呢?只能加0分先给0分,等我有权利了补上。

解决方案 »

  1.   

    http://www.microsoft.com/downloads/details.aspx?familyid=FC02E2E3-14BB-46C1-AFEE-3732D6249647&displaylang=zh-cn下载支持包,安装后有接口函数
      

  2.   

    我给贴子加了100分,似乎只能加100分。 crybird 
    寒号鸟我已经下载了支持包,并使用最新的ExtTextoutL函数进行输出,但是还是出现乱码。
      

  3.   

    const   int   GB18030_CP   =   54936;
    typedef BOOL (__stdcall * MyExtTextOutL)(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc, LPCSTR lpString, UINT cbCount, CONST INT *lpDx );typedef int ( __stdcall * MyMessageBoxL)(
    HWND        hWnd,       // handle to owner window
    LPCSTR      lpText,     // text in message box
    LPCSTR      lpCaption,  // message box title
    UINT        uType       // message box style
    );/*
    BOOL ExtTextOutL(
    HDC         hdc,        // handle to DC
    int         X,          // x-coordinate of reference point
    int         Y,          // y-coordinate of reference point
    UINT        fuOptions,  // text-output options
    CONST RECT* lprc,       // optional dimensions
    LPCSTR      lpString,   // string
    UINT        cbCount,    // number of characters in string
    CONST INT*  lpDx        // array of spacing values
    );
    BOOL GetTextExtentExPointL(
    HDC         hdc,        // handle to DC
    LPCSTR      lpszStr,    // character string
    int         cchString,  // number of characters
    int         nMaxExtent, // maximum width of formatted string
    LPINT       lpnFit,     // maximum number of characters
    LPINT       alpDx,      // array of partial string widths
    LPSIZE      lpSize      // string dimensions
    );
    BOOL GetTextExtentPoint32L(
    HDC         hdc,        // handle to DC
    LPCSTR      lpString,   // text string
    int         cbString,   // characters in string
    LPSIZE      lpSize      // string size
    );
    Int MessageBoxL(
    HWND        hWnd,       // handle to owner window
    LPCSTR      lpText,     // text in message box
    LPCSTR      lpCaption,  // message box title
    UINT        uType       // message box style
    );
    Int MessageBoxExL(
    HWND        hWnd,       // handle to owner window
    LPCSTR      lpText,     // text in message box
    LPCSTR      lpCaption,  // message box title
    UINT        uType,      // message box style
    WORD        wLanguageId // language identifier
    );
    BOOL TextOutL(
    HDC         hdc,        // handle to DC
    int         nXStart,    // x-coordinate of starting position
    int         nYStart,    // y-coordinate of starting position
    LPCSTR      lpString,   // character string
    int         cbString    // number of characters
    );*/
    void CGB18030Dlg::OnButton1() 
    {
    if( IsValidCodePage( GB18030_CP ) )
    {
    CPINFO cpinfo;
    if( GetCPInfo( GB18030_CP, &cpinfo ) )
    {
    CClientDC dc( this );
    CFont font;
    font.CreateFont( 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, _T( "宋体") );
    CFont *p = dc.SelectObject( &font ); unsigned char aa[ 10 ] = { 0x81, 0x32, 0xe8, 0x36, 0 };
    WCHAR wstr[ 100 ] = L"";
    char bb[ 100 ] = ""; MultiByteToWideChar( GB18030_CP, 0, ( char * )aa, 4, wstr, 100 );
    WideCharToMultiByte( CP_OEMCP, 0, wstr, 2, bb, 100, NULL, NULL ); HMODULE h;
    h = LoadLibrary( "ms4bsp.dll" );
    if( !h )
    {
    AfxMessageBox( "no dll" );
    }
    else
    {
    MyExtTextOutL t = (MyExtTextOutL)GetProcAddress( h, "ExtTextOutL" );
    if( !t )
    {
    AfxMessageBox( "no ExtTextOutL" );
    FreeLibrary( h );
    return;
    }
    MyMessageBoxL l = (MyMessageBoxL)GetProcAddress( h, "MessageBoxL" );
    if( !l )
    {
    AfxMessageBox( "no MessageBoxL" );
    FreeLibrary( h );
    return;
    }
    l( NULL, ( LPCSTR )aa, NULL, 0 );
    l( NULL, ( LPCSTR )bb, NULL, 0 );
    l( NULL, ( LPCSTR )wstr, NULL, 0 );
    t( dc.GetSafeHdc(), 200, 100, 0, NULL, ( char * )bb, 1, NULL );
    FreeLibrary( h );
    }
    dc.SelectObject( p );
    }
    else
    {
    AfxMessageBox( "GetCPInfo( GB18030_CP, &cpinfo )" );
    }
    }
    else
    {
    AfxMessageBox( "IsValidCodePage( GB18030_CP )" );
    }
    }这是我的测试程序,工程是vc6的,没有unicode选项。
      

  4.   

    1、确定有对应的语言包
    2、设置下dc的font
      

  5.   


    void CTtDlg::OnButton1() 
    {
    //{0x4db5} = {0x82, 0x35, 0x87, 0x38} char bufA[] = {0x82, 0x35, 0x87, 0x38, 0, 0, 0, 0};
    wchar_t bufW[2] = {0};
    MultiByteToWideChar(GB18030_CP, 0, bufA, -1, bufW, 1); //error
    //MessageBox(bufA);
    //MessageBoxW(0, bufW, 0, 0); CClientDC dc(this);
    CFont font;
    font.CreateFont( 20, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, _T( "宋体-18030") );
    CFont* ofont = dc.SelectObject(&font); CRect rcA(50, 50, 300, 100);
    CRect rcW(50, 100, 300, 150); ::DrawTextA(dc.m_hDC, bufA, -1, &rcA, DT_SINGLELINE);//error
    ::DrawTextW(dc.m_hDC, bufW, -1, &rcW, DT_SINGLELINE);//ok HMODULE h = LoadLibrary(_T("ms4bsp.dll"));
    if (h)
    {
    MyExtTextOutL t = (MyExtTextOutL)GetProcAddress(h, _T("ExtTextOutL"));
    if(t)
    {
    t(dc.m_hDC, 50, 150, 0, NULL, bufA, 4, NULL);//ok
    }
    MyMessageBoxL m = (MyMessageBoxL)GetProcAddress(h, _T("MessageBoxL"));
    if(m)
    {
    m(NULL, bufA, bufA, 0);//error
    } FreeLibrary(h);
    } dc.SelectObject(ofont);
    }
    -----------------------------------------
    我测试的结果:所有的对话框都是乱码,设置好字体和转码正确后,文本输出正确
      

  6.   

    好像还要SetThreadAcp什么的,不然也会因为环境线程环境不正确而有乱码。
      

  7.   

    谢谢crybird ,俺后来也有了进展,你的功劳大大的。