1,183
社区成员
发帖
与我相关
我的任务
分享
unit HexDecBinInt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
cScaleChar = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function IntPower(Base, Exponent: Integer): Integer;
function DigitToInt(mDigit: string; mScale: Byte): Integer;
function IntToDigit(mNumber: Integer; mScale: Byte;
mLength: Integer = 0): string;
implementation
//------------------------------------------------------------------------------
function IntPower(Base, Exponent: Integer): Integer; { 返回Base的Exponent次方 }
var
I: Integer;
begin
Result := 1;
for I := 1 to Exponent do
Result := Result * Base;
end; { IntPower }
//------------------------------------------------------------------------------
function DigitToInt(mDigit: string; mScale: Byte): Integer;
{ 返回进制表示转换成整数;mScale指定多少进制 }
var
I: Byte;
L: Integer;
begin
Result := 0;
mDigit := UpperCase(mDigit);
L := Length(mDigit);
for I := 1 to L do
Result := Result + (Pos(mDigit[L - I + 1], cScaleChar) - 1) *
IntPower(mScale, I - 1);
end; { DigitToInt }
//------------------------------------------------------------------------------
function IntToDigit(mNumber: Integer; mScale: Byte;
mLength: Integer = 0): string;
{ 返回整数的进制表示;mScale指定多少进制;mLength指定长度,长度不足时向前补0 }
var
I, J: Integer;
begin
Result := '';
I := mNumber;
while (I >= mScale) and (mScale > 1) do begin
J := I mod mScale;
I := I div mScale;
Result := cScaleChar[J + 1] + Result;
end;
Result := cScaleChar[I + 1] + Result;
for I := 1 to mLength - Length(Result) do Result := '0' + Result;
end; { IntToDigit }
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, HexDecBinInt;
type
TForm1 = class(TForm)
lst1: TListBox;
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//------------------------------------------------------------------------------
//回调函数
//------------------------------------------------------------------------------
function EnumChildWindowsProc(hWnd:HWND;lparam:LPARAM):Boolean;stdcall;
var
ssText:array[0..254] of Char;
id:Integer;
begin
GetWindowText(hWnd,ssText,255);
id:=GetDlgCtrlID(hWnd);
if Trim(StrPas(sstext)) <> '' then
Form1.lst1.Items.Add(' ------>' + ssText + '---->' + IntToDigit(id,16,0));
result:=True;
end;
//------------------------------------------------------------------------------
function EnumwindowsProc(hWnd:HWND;lparam:LPARAM):Boolean;stdcall;
var
sText:array[0..254] of Char;
id:Integer;
begin
GetWindowText(hWnd,sText,255);
id:=GetDlgCtrlID(hWnd);
if Trim(StrPas(sText)) <> '' then
begin
Form1.lst1.Items.Add(Trim(StrPas(sText)) + '---->' + IntToStr(id));;
EnumChildWindows(hWnd,@EnumChildWindowsProc,0);
end;
result:=True;
end;
//------------------------------------------------------------------------------
procedure TForm1.btn1Click(Sender: TObject);
begin
lst1.Clear;
EnumWindows(@EnumwindowsProc,0);
end;
function EnumWinProc(Wnd : HWND; form1 : TForm1) : Boolean; Export; {$IFDEF Win32}StdCall;{$ENDIF}
var
WinText : Array[0..255] of Char;
begin
GetWindowText(Wnd, WinText, 255);
Result := True;
if (StrPas(WinText)<>'') then
Form1.ListBox1.Items.Add(StrPas(WinText));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EnumWindows(@EnumWinProc, LongInt(Self));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
h: HWnd;
p: array[0..254] of char;
begin
h := GetWindow(Handle, GW_HWNDFIRST);
while h <> 0 do
begin
if GetWindowText(h, p, 255) > 0 then Memo1.Lines.Add(p);
h := GetWindow(h, GW_HWNDNEXT);
end;
end;