C
cxz9
Unregistered / Unconfirmed
GUEST, unregistred user!
用WM_GETTEXT取SkyPe中文的问题,只能取一部分
用GetWindowTextW,WideString也不行
取QQ的中文件英文都好好的
2008-1-15 下午 05:27:
测?
2008-1-15 下午 05:28:
[下午 04:52:07] 小笨笨 说?
2008-1-15 下午 05:39:
rwrewrew
下午 03:58:
Skype SMS is fun!
附完整代码:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, RichEdit;
type
TForm2 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
end;
var
Form2: TForm2;
ClassName1: array[0..255] of char;
implementation
{$R *.dfm}
function GetWndText(hWnd: HWND): string;
var
Ret: LongInt;
mText: PChar;
Buf: Integer;
begin
Ret := SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0) + 1;
GetMem(mText, Ret);
try
SendMessage(hWnd, WM_GETTEXT, Ret, LPARAM(mText));
Result := mText;
//WideCharToString(mText);
finally
FreeMem(mText, Ret);
end;
end;
{
function GetWndText(hWnd: HWND): WideString;
begin
// UNICODE &
HANDLE
//SetLength(Result, GetWindowTextLength(hWnd) + 1);
SetLength(Result, SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0) + 1);
GetWindowTextW(hWnd, PWideChar(Result), Length(Result));
SetLength(Result, Length(Result) - 1);
showmessage(Result);
end;
}
{function GetWndText(hWnd: HWND): string;
var
Ret: LongInt;
mText: PChar;
Buf: Integer;
begin
Ret := SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0) + 1;
GetMem(mText, 2 * Ret);
try
SendMessage(hWnd, WM_GETTEXT, 2*Ret, LPARAM(mText));
Result := mText;
//WideCharToString(mText);
finally
FreeMem(mText, Ret);
end;
end;
}
{function GetWndText(hWnd: HWND): string;
var
Ret: LongInt;
mText: PChar;
Buf: Integer;
CopyData: CopyDataStruct;
begin
Ret := SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0) + 1;
GetMem(mText, Ret);
try
//Buf := LongInt(mText);
CopyData.dwData := 0;
CopyData.lpData := nil;
CopyData.cbData := Ret;
//SendMessage(hWnd, WM_GETTEXT, Ret, Buf);
// SendMessage(hWnd, WM_COPYDATA, Ret, Buf);
PostMessage(hWnd, WM_COPYDATA, 0, LPARAM(@CopyData));
showmessage(IntToStr(CopyData.cbData ));
Result := StrPas(CopyData.lpData);
finally
FreeMem(mText, Ret);
end;
end;
}
function EnumProc(wnd: HWND;
lb2: TMemo): BOOL;
stdcall;
var
ClassName2: array[0..255] of char;
tt: TStringList;
begin
Result := True;
GetClassName(wnd, ClassName2, 255);
if (wnd <> 0) and (string(ClassName2) = 'TRichView') then
begin
tt := TStringList.Create;
try
lb2.Lines.Add(IntToHex(wnd, 6) + ':' + string(ClassName2));
tt.Text := GetWndText(wnd);
//lb2.Lines.Add(TT.AnsiStrings.Text);
lb2.Lines.AddStrings(tt);
//lb2.Lines.Add(GetWndText(wnd));
finally
tt.Free;
end;
end;
end;
function EnumWindowsProc(wHandle: HWND;
lb: TMemo): Bool;
stdcall;
export;
var
//Title: array[0..255] of char;
Title: string;
begin
Result := True;
GetClassName(wHandle, ClassName1, 255);
if wHandle <> 0 then
begin
//if string(ClassName1) <> 'CabinetWClass' then
// Title := GetWndText(wHandle);
// if (string(ClassName1) = '#32770') and (Pos('的对话', Title) > 0) then
//wHandle := findwindow('#32770', '鲁博【朋友】与qqeip的对话');
if (string(ClassName1) = 'TskMultiChatForm.UnicodeClass') then
begin
EnumChildWindows(wHandle, @EnumProc, Integer(lb));
end;
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
EnumWindows(@EnumWindowsProc, Integer(Memo1));
end;
end.
object Form2: TForm2
Left = 192
Top = 133
Width = 638
Height = 392
Caption = 'Form2'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 8
Top = 16
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object Memo1: TMemo
Left = 92
Top = 8
Width = 505
Height = 345
Lines.Strings = (
'')
TabOrder = 1
end
end
用GetWindowTextW,WideString也不行
取QQ的中文件英文都好好的
2008-1-15 下午 05:27:
测?
2008-1-15 下午 05:28:
[下午 04:52:07] 小笨笨 说?
2008-1-15 下午 05:39:
rwrewrew
下午 03:58:
Skype SMS is fun!
附完整代码:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, RichEdit;
type
TForm2 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
end;
var
Form2: TForm2;
ClassName1: array[0..255] of char;
implementation
{$R *.dfm}
function GetWndText(hWnd: HWND): string;
var
Ret: LongInt;
mText: PChar;
Buf: Integer;
begin
Ret := SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0) + 1;
GetMem(mText, Ret);
try
SendMessage(hWnd, WM_GETTEXT, Ret, LPARAM(mText));
Result := mText;
//WideCharToString(mText);
finally
FreeMem(mText, Ret);
end;
end;
{
function GetWndText(hWnd: HWND): WideString;
begin
// UNICODE &
HANDLE
//SetLength(Result, GetWindowTextLength(hWnd) + 1);
SetLength(Result, SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0) + 1);
GetWindowTextW(hWnd, PWideChar(Result), Length(Result));
SetLength(Result, Length(Result) - 1);
showmessage(Result);
end;
}
{function GetWndText(hWnd: HWND): string;
var
Ret: LongInt;
mText: PChar;
Buf: Integer;
begin
Ret := SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0) + 1;
GetMem(mText, 2 * Ret);
try
SendMessage(hWnd, WM_GETTEXT, 2*Ret, LPARAM(mText));
Result := mText;
//WideCharToString(mText);
finally
FreeMem(mText, Ret);
end;
end;
}
{function GetWndText(hWnd: HWND): string;
var
Ret: LongInt;
mText: PChar;
Buf: Integer;
CopyData: CopyDataStruct;
begin
Ret := SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0) + 1;
GetMem(mText, Ret);
try
//Buf := LongInt(mText);
CopyData.dwData := 0;
CopyData.lpData := nil;
CopyData.cbData := Ret;
//SendMessage(hWnd, WM_GETTEXT, Ret, Buf);
// SendMessage(hWnd, WM_COPYDATA, Ret, Buf);
PostMessage(hWnd, WM_COPYDATA, 0, LPARAM(@CopyData));
showmessage(IntToStr(CopyData.cbData ));
Result := StrPas(CopyData.lpData);
finally
FreeMem(mText, Ret);
end;
end;
}
function EnumProc(wnd: HWND;
lb2: TMemo): BOOL;
stdcall;
var
ClassName2: array[0..255] of char;
tt: TStringList;
begin
Result := True;
GetClassName(wnd, ClassName2, 255);
if (wnd <> 0) and (string(ClassName2) = 'TRichView') then
begin
tt := TStringList.Create;
try
lb2.Lines.Add(IntToHex(wnd, 6) + ':' + string(ClassName2));
tt.Text := GetWndText(wnd);
//lb2.Lines.Add(TT.AnsiStrings.Text);
lb2.Lines.AddStrings(tt);
//lb2.Lines.Add(GetWndText(wnd));
finally
tt.Free;
end;
end;
end;
function EnumWindowsProc(wHandle: HWND;
lb: TMemo): Bool;
stdcall;
export;
var
//Title: array[0..255] of char;
Title: string;
begin
Result := True;
GetClassName(wHandle, ClassName1, 255);
if wHandle <> 0 then
begin
//if string(ClassName1) <> 'CabinetWClass' then
// Title := GetWndText(wHandle);
// if (string(ClassName1) = '#32770') and (Pos('的对话', Title) > 0) then
//wHandle := findwindow('#32770', '鲁博【朋友】与qqeip的对话');
if (string(ClassName1) = 'TskMultiChatForm.UnicodeClass') then
begin
EnumChildWindows(wHandle, @EnumProc, Integer(lb));
end;
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
EnumWindows(@EnumWindowsProc, Integer(Memo1));
end;
end.
object Form2: TForm2
Left = 192
Top = 133
Width = 638
Height = 392
Caption = 'Form2'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 8
Top = 16
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object Memo1: TMemo
Left = 92
Top = 8
Width = 505
Height = 345
Lines.Strings = (
'')
TabOrder = 1
end
end