如何在win98中,使用API函数进行内码转换? ( 积分: 100 )

  • 主题发起人 主题发起人 xjiang
  • 开始时间 开始时间
X

xjiang

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在【 Win98 】中,使用API函数进行内码转换?<br>是否要调用“unicows.dll”?怎样调用?<br>如何用 LCMapString 函数把GBK繁体转为GBK简体?<br>希望写出详细的代码。谢谢!!<br>
 
如何在【 Win98 】中,使用API函数进行内码转换?<br>是否要调用“unicows.dll”?怎样调用?<br>如何用 LCMapString 函数把GBK繁体转为GBK简体?<br>希望写出详细的代码。谢谢!!<br>
 
unit CodeCn;<br><br>interface<br><br>uses<br> &nbsp;Windows;<br><br>const<br> &nbsp;CHINESE_SIMPLIFIED = 0;<br> &nbsp;CHINESE_TRADITIONAL = 1;<br><br>function Big52GB(const Source: string): string;<br>function Big52GBT(const Source: string): string;<br>function GB2Big5(const Source: string): string;<br>function GB2GBT(const Source: string): string;<br>function GBT2GB(const Source: string): string;<br><br>implementation<br><br>function MAKELANGID(usPrimaryLanguage, usSubLanguage: WORD): WORD;<br>begin<br> &nbsp;Result := (usSubLanguage shl 10) or usPrimaryLanguage;<br>end;<br><br>function MAKELCID(wLanguageID: WORD; wSortID: WORD = SORT_DEFAULT): LCID;<br>begin<br> &nbsp;Result := MakeLong(wLanguageID, wSortID);<br>end;<br><br>function ToUnicode(const Source: string; nEncoding: Integer): WideString;<br>var<br> &nbsp;nLength: Integer;<br> &nbsp;nLanguage: Integer;<br>begin<br> &nbsp;if nEncoding = CHINESE_SIMPLIFIED then<br> &nbsp; &nbsp;nLanguage := 936<br> &nbsp;else if nEncoding = CHINESE_TRADITIONAL then<br> &nbsp; &nbsp;nLanguage := 950<br> &nbsp;else<br> &nbsp; &nbsp;nLanguage := CP_ACP;<br><br> &nbsp;nLength := MultiByteToWideChar(nLanguage, 0, PChar(Source), Length(Source), nil, 0);<br> &nbsp;SetLength(Result, nLength);<br> &nbsp;MultiByteToWideChar(nLanguage, 0, PChar(Source), Length(Source), PWideChar(Result), nLength);<br>end;<br><br>function ToMultiByte(const Source: WideString; nEncoding: Integer): string;<br>var<br> &nbsp;nLength: Integer;<br> &nbsp;nLanguage: Integer;<br>begin<br> &nbsp;if nEncoding = CHINESE_SIMPLIFIED then<br> &nbsp; &nbsp;nLanguage := 936<br> &nbsp;else if nEncoding = CHINESE_TRADITIONAL then<br> &nbsp; &nbsp;nLanguage := 950<br> &nbsp;else<br> &nbsp; &nbsp;nLanguage := CP_ACP;<br><br> &nbsp;nLength := WideCharToMultiByte(nLanguage, 0, PWideChar(Source), Length(Source), nil, 0, nil, nil);<br><br> &nbsp;SetLength(Result, nLength);<br> &nbsp;WideCharToMultiByte(nLanguage, 0, PWideChar(Source), Length(Source), PChar(Result), nLength, nil, nil);<br>end;<br><br>function Big52GB(const Source: string): string;<br>begin<br> &nbsp;Result := Big52GBT(Source);<br> &nbsp;Result := GBT2GB(Result);<br>end;<br><br>function Big52GBT(const Source: string): string;<br>var<br> &nbsp;nLength: Integer;<br> &nbsp;WS: WideString;<br> &nbsp;nResultLength: Integer;<br>begin<br> &nbsp;nLength := MultiByteToWideChar(950, 0, PChar(Source), Length(Source), nil, 0);<br> &nbsp;SetLength(WS, nLength);<br> &nbsp;MultiByteToWideChar(950, 0, PChar(Source), Length(Source), PWideChar(WS), nLength);<br><br> &nbsp;nResultLength := WideCharToMultiByte(936, 0, PWideChar(WS), nLength, nil, 0, nil, nil);<br> &nbsp;SetLength(Result, nResultLength);<br> &nbsp;WideCharToMultiByte(936, 0, PWideChar(WS), nLength, PChar(Result), nResultLength, nil, nil);<br>end;<br><br>function GBT2GB(const Source: string): string;<br>var<br> &nbsp;dwLocale: LCID;<br> &nbsp;wLangID: Word;<br> &nbsp;nLength: Integer;<br>begin<br> &nbsp;wLangID := MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED);<br> &nbsp;dwLocale := MAKELCID(wLangID, SORT_CHINESE_PRC);<br> &nbsp;nLength := LCMapString(dwLocale, LCMAP_SIMPLIFIED_CHINESE, PChar(Source), Length(Source), nil, 0);<br> &nbsp;SetLength(Result, nLength);<br> &nbsp;LCMapString(dwLocale, LCMAP_SIMPLIFIED_CHINESE, PChar(Source), Length(Source), PChar(Result), nLength);<br>end;<br><br>function GB2Big5(const Source: string): string;<br>var<br> &nbsp;S: string;<br> &nbsp;nLength: Integer;<br> &nbsp;WS: WideString;<br> &nbsp;nResultLength: Integer;<br>begin<br> &nbsp;S := GB2GBT(Source);<br> &nbsp;nLength := MultiByteToWideChar(936, 0, PChar(S), Length(S), nil, 0);<br> &nbsp;SetLength(WS, nLength);<br> &nbsp;MultiByteToWideChar(936, 0, PChar(S), Length(S), PWideChar(WS), nLength);<br><br> &nbsp;nResultLength := WideCharToMultiByte(950, 0, PWideChar(WS), nLength, nil, 0, nil, nil);<br> &nbsp;SetLength(Result, nResultLength);<br> &nbsp;WideCharToMultiByte(950, 0, PWideChar(WS), nLength, PChar(Result), nResultLength, nil, nil);<br>end;<br><br>//将GB简体转换到GBT繁体<br>function GB2GBT(const Source: string): string;<br>var<br> &nbsp;dwLocale: LCID;<br> &nbsp;wLangID: Word;<br> &nbsp;nLength: Integer;<br>begin<br> &nbsp;wLangID := MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED);<br> &nbsp;dwLocale := MAKELCID(wLangID, SORT_CHINESE_PRC);<br> &nbsp;nLength := LCMapString(dwLocale, LCMAP_TRADITIONAL_CHINESE, PChar(Source), Length(Source), nil, 0);<br> &nbsp;SetLength(Result, nLength);<br> &nbsp;LCMapString(dwLocale, LCMAP_TRADITIONAL_CHINESE, PChar(Source), Length(Source), PChar(Result), nLength);<br>end;<br><br>end.<br>
 
首先谢谢 lichengbin 的回复。<br>我的系统是 WIN98 ,D7。<br>除了BIG5 能够成功转为 GBK 繁体外,其他的都显示为空白。<br>主要是 GBK 简体和 GBK 繁体之间转换有问题,显示为空白。<br><br>那位系统是WIN98的兄弟帮忙测试一下,看看能不能通过。<br><br>有人说在 WIN98 中用API转换内码要调用 unicows.dll 动态链接库,<br>具体怎么办?谁知道?<br>
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2960370
 
显示为空白的话,可能与你是否安装了相关字体文件、有否按指定字体显示有关吧。
 
3h<br>上面的代码你在 win98 中测试通过了吗?有没有使用链接库?<br><br><br>
 
我没有测试。
 
没人知道吗?<br>我看一些游戏修改器为了在win98 中使用繁体都调用了链接库。
 
后退
顶部