中国开发网: 论坛: 程序员情感CBD: 贴子 509414
leeming
麻烦一下懂C的朋友。帮我将里面的代码转成Delphi的。
#include <windows.h>
#include <locale.h>

#include "..\str.h"
DWORD AnsiToUni( char* c )
{
wchar_t wc;
mbtowc( &wc, c, 2 );
return (unsigned)wc;
}
void InsertWindowString( HWND hWnd, char* str )
{
DWORD w = 0;
if( IsWindowUnicode( hWnd ) )
{

while( *str != 0 )
{
if( IsDBCSLeadByte(*str) )
w = AnsiToUni(str++);
else
w = *str;
str ++;
SendMessageW( hWnd, WM_IME_CHAR, w, 1 );
}
}
else
{
while( *str != 0 )
{
w = (unsigned char)*str++;
SendMessage( hWnd, WM_CHAR, w, 1 );
}

}
}

void InsertWindowString2( HWND hWnd, CStr& str )
{
DWORD w = 0;
if( IsWindowUnicode( hWnd ) )
{
for(int i=0;i<str.length();i++)
{
w = (DWORD)str[i];
SendMessageW( hWnd, WM_IME_CHAR, w, 1 );
}
}
else
{
char* p = (char*)str;
while( *p != 0 )
{
w = (unsigned char)*p++;
SendMessage( hWnd, WM_CHAR, w, 1 );
}

}
}

int main(int argc, char* argv[])
{
setlocale( LC_ALL, "chinese" );

char* str = "°&reg;aa\r";
CStr str2 = L"&ordm;&THORN;aa\r";
HWND hWnd1 = (HWND)0x004C02B4;
HWND hWnd2 = (HWND)0x000C03E6;
InsertWindowString( hWnd1, str );
InsertWindowString( hWnd2, str );
InsertWindowString2( hWnd1, str2 );
InsertWindowString2( hWnd2, str2 );
return 0;
}

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录