无聊之中写了个小东西,可以修改系统里的窗口的内容。 (0分)

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

xeen

Unregistered / Unconfirmed
GUEST, unregistred user!
现在可以列出和修改其他进程中线程所创建的窗口的所有子窗口的一些属性,比如编辑框的内容.
不过我没修改成font,只能改成默认的。好象字体的句柄传递不过去,不明白。
另外可以修改窗口主菜单的的属性(如果有),
如是否[red]可用[/red].用menuitem enable/disable控制权限的人注意了,这样做不可靠.
有很多功能没有实现,烦了,毕竟是作着玩的,有兴趣的富翁可以接着做.
dfm文件:
object Form1: TForm1
Left = 198
Top = 107
Width = 696
Height = 480
Caption = '´°¿ÚÐÅÏ¢²éѯ'
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = 'ËÎÌå'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 12
object Label1: TLabel
Left = 26
Top = 44
Width = 48
Height = 12
Caption = '´°¿Ú±êÌâ'
end
object Label2: TLabel
Left = 32
Top = 96
Width = 66
Height = 12
Caption = '×Ó´°¿ÚÐÅÏ¢:'
end
object Button1: TButton
Left = 552
Top = 40
Width = 75
Height = 25
Caption = '²éÕÒ'
TabOrder = 0
OnClick = Button1Click
end
object WindowTitle: TEdit
Left = 88
Top = 41
Width = 441
Height = 20
TabOrder = 1
end
object PageControl1: TPageControl
Left = 24
Top = 120
Width = 633
Height = 313
ActivePage = TabSheet1
TabOrder = 2
object TabSheet1: TTabSheet
Caption = '×Ó´°¿ÚÐÅÏ¢'
object childwindowlist: TListView
Left = 0
Top = 0
Width = 625
Height = 286
Align = alClient
Columns = <
item
Caption = '±êÌâ'
Width = 200
end
item
Caption = 'ˈ̞'
Width = 250
end
item
Caption = '¾ä±ú'
end
item
Caption = 'ÓÐЧ'
end>
FlatScrollBars = True
GridLines = True
RowSelect = True
PopupMenu = PopupMenu1
TabOrder = 0
ViewStyle = vsReport
OnChange = childwindowlistChange
OnDblClick = childwindowlistDblClick
end
end
object TabSheet2: TTabSheet
Caption = '²Ëµ¥ÐÅÏ¢'
ImageIndex = 1
object menuitemlist: TListView
Left = 0
Top = 0
Width = 625
Height = 286
Align = alClient
Columns = <
item
Caption = '±êÌâ'
Width = 200
end
item
Caption = '×Ӳ˵¥'
Width = 100
end
item
Caption = '±êʶºÅ'
end
item
Caption = '¿ÉÓÃ'
end>
GridLines = True
PopupMenu = PopupMenu2
TabOrder = 0
ViewStyle = vsReport
end
end
end
object PopupMenu1: TPopupMenu
OnPopup = PopupMenu1Popup
Left = 192
Top = 80
object N1: TMenuItem
Caption = '¸Ä±ä×ÖÌå'
OnClick = N1Click
end
object N2: TMenuItem
Caption = '¸Ä±ä±³¾°ÑÕÉ«'
end
object N3: TMenuItem
Caption = 'ÆôÓÃ/½ûÓÃ'
OnClick = N3Click
end
end
object FontDialog1: TFontDialog
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
MinFontSize = 0
MaxFontSize = 0
Left = 264
Top = 80
end
object PopupMenu2: TPopupMenu
OnPopup = PopupMenu2Popup
Left = 344
Top = 72
object N4: TMenuItem
Caption = '½ûÓÃ/ÆôÓÃ'
OnClick = N4Click
end
end
end
pas文件
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, Menus,shellapi;

type
TForm1 = class(TForm)
Button1: TButton;
WindowTitle: TEdit;
Label1: TLabel;
Label2: TLabel;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
FontDialog1: TFontDialog;
N3: TMenuItem;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
childwindowlist: TListView;
TabSheet2: TTabSheet;
menuitemlist: TListView;
PopupMenu2: TPopupMenu;
N4: TMenuItem;
procedure Button1Click(Sender: TObject);
procedure childwindowlistDblClick(Sender: TObject);
procedure childwindowlistChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
procedure PopupMenu1Popup(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure PopupMenu2Popup(Sender: TObject);
procedure N4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
mywindowhandle:hwnd;
mymenuhandle:hwnd;
myfont:tfont;
implementation

{$R *.DFM}
function myEnumChildProc(HWND:hwnd;LPARAM:lParam):boolean;stdcall;
var i:integer;
WndCaption: array[0..254] of char;
WndClassName: array[0..254] of char;
s:string;
l:integer;
mylist:tlistitem;
begin
result := true;
GetWindowText(HWnd, @WndCaption, 254);
GetClassName(HWnd, @WndClassName, 254);
with form1.childwindowlist do
begin
mylist := Items.Add;
// mylist.Caption := strpas(wndclassname);
if (pos('edit',lowercase(strpas(wndclassname)))>0) or (pos('combobox',lowercase(strpas(wndclassname)))>0) then
begin
l := SendMessage(hwnd,WM_GETTEXTLENGTH,0,0)+1;
setlength(s,l);
SendMessage(hwnd,wm_gettext,l,longint(pchar(s)));
mylist.Caption := s;
end else
mylist.Caption := strpas(wndcaption);
mylist.SubItems.Add(strpas(wndclassname));
mylist.SubItems.Add(inttostr(hwnd));
if iswindowenabled(hwnd) then
mylist.SubItems.Add('ÊÇ')
else
mylist.SubItems.Add('·ñ');
// if lowercase(strpas(wndclassname))='edit' then
// Setwindowtext(HWnd,'aaa');
end;

end;
procedure TForm1.Button1Click(Sender: TObject);
var i,j,mymenuid:integer;
Current_child:hmenu;
temp_menu_info:tagMENUITEMINFO;
menucaption:string;
Buffer: array[0..79] of Char;
mymenulist:tlistitem;
mysubmenu:string;
begin
childwindowlist.Items.BeginUpdate;
menuitemlist.Items.BeginUpdate;
childwindowlist.Items.Clear;
menuitemlist.Items.Clear;
childwindowlist.OnChange := nil;
if trim(WindowTitle.text)='' then exit;
mywindowhandle := findwindow(nil,pchar(windowtitle.text));
if mywindowhandle <>0 then
begin
EnumChildWindows(mywindowhandle,@myEnumChildProc,0);


mymenuhandle := getmenu(mywindowhandle);
if mymenuhandle <>0 then
begin
menuitemlist.Items.Clear;
for i := 0 to getmenuitemcount(mymenuhandle)-1 do
begin
Current_child := getsubmenu(mymenuhandle,i);
temp_menu_info.cbSize:= sizeof(temp_menu_info);
temp_menu_info.fMask:=MIIM_STATE or MIIM_TYPE or MIIM_ID;
temp_menu_info.dwTypeData := Buffer;
temp_menu_info.cch := SizeOf(Buffer);
GetMenuItemInfo(mymenuhandle,i,true,temp_menu_info);
if temp_menu_info.fType = MFT_STRING then
mysubmenu := strpas(buffer);
for j :=0 to getmenuitemcount(Current_child)-1 do
begin
temp_menu_info.dwTypeData := Buffer;
temp_menu_info.cch := SizeOf(Buffer);
GetMenuItemInfo(Current_child,j,true,temp_menu_info);
mymenuid := temp_menu_info.wID;
if temp_menu_info.fType = MFT_STRING then
begin
menucaption := strpas(buffer);
mymenulist := menuitemlist.Items.Add ;
mymenulist.Caption := menucaption;
mymenulist.SubItems.Add(mysubmenu);
mymenulist.SubItems.Add(inttostr(mymenuid));
if temp_menu_info.fState = MFS_ENABLED then
mymenulist.SubItems.Add('ÊÇ')
else
mymenulist.SubItems.Add('·ñ')
end;
end;
end;
end;
end;
childWindowlist.OnChange := childwindowlistChange;
childwindowlist.Items.EndUpdate;
menuitemlist.Items.EndUpdate;
end;

procedure TForm1.childwindowlistDblClick(Sender: TObject);
var myhandle:hwnd;
begin
if childwindowlist.Items.Count>0 then
begin
myhandle := strtoint(childwindowlist.Selected.SubItems[1]);
if pos('button',lowercase(childwindowlist.Selected.SubItems[0]))>0 then
postmessage(myhandle,bm_click,0,0);
end;
end;

procedure TForm1.childwindowlistChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
var myhandle:hwnd;
begin
myhandle := strtoint(item.SubItems[1]);
if (pos('edit',lowercase(item.SubItems[0]))>0) or (pos('combobox',lowercase(item.SubItems[0]))>0) then
begin
sendmessage(myhandle,wm_settext,0,integer(pchar(item.Caption)))
end else
setwindowtext(myhandle,pchar(item.caption));
sendmessage(mywindowhandle,wm_paint,0,0);
sendmessage(mywindowhandle,wm_ncpaint,0,0);
end;

procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
if childwindowlist.Selected <> nil then
begin
n1.Enabled := true;
n2.Enabled := true;
n3.Enabled := true;
end else
begin
n1.Enabled := false;
n2.Enabled := false;
n3.Enabled := false;
end;
end;

procedure TForm1.N1Click(Sender: TObject);
var myhandle:hwnd;

begin
myhandle := strtoint(childwindowlist.Selected.SubItems[1]);
if fontdialog1.Execute then
begin
myfont := tfont.Create;
myfont.Assign(fontdialog1.font);
sendmessage(myhandle,wm_setfont,myfont.Handle,1);
freeandnil(myfont);
end;
end;

procedure TForm1.N3Click(Sender: TObject);
var myhandle:hwnd;
begin
myhandle := strtoint(childwindowlist.Selected.SubItems[1]);
enablewindow(myhandle,not(iswindowenabled(myhandle)));
if childwindowlist.Selected.SubItems[2]='ÊÇ' then
childwindowlist.Selected.SubItems[2] := '·ñ'
else
childwindowlist.Selected.SubItems[2] := 'ÊÇ'

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
windowtitle.Text := 'н¨Îı¾Îĵµ.txt - ¼Çʱ¾';
childwindowlist.Items.Clear;
menuitemlist.Items.Clear;
end;

procedure TForm1.PopupMenu2Popup(Sender: TObject);
begin
if menuitemlist.Selected <> nil then
begin
n4.Enabled := true;
end else
begin
n4.Enabled := false;
end;

end;

procedure TForm1.N4Click(Sender: TObject);
var temp_menu_info:tagMENUITEMINFO;
mymenuid:integer;
begin
mymenuid := strtoint(menuitemlist.Selected.SubItems[1]);
temp_menu_info.cbSize:= sizeof(temp_menu_info);
temp_menu_info.fMask:=MIIM_STATE or MIIM_ID;
getMenuItemInfo(mymenuhandle,mymenuid,false,temp_menu_info);
if temp_menu_info.fState = MFS_ENABLED then
temp_menu_info.fState := MFS_GRAYED
else
temp_menu_info.fState := MFS_ENABLED;
setMenuItemInfo(mymenuhandle,mymenuid,false,temp_menu_info);

end;

end.
 
太多了,有时间我来试试.[:D][:D]
 
把窗体文件也copy上来啊
 
接受答案了.
 
复制代码的时候应该把输入法窗口打开,这样粘贴出来代码里的中文就不会是乱码了。
 

Similar threads

I
回复
0
查看
487
import
I
S
回复
0
查看
751
SUNSTONE的Delphi笔记
S
I
回复
0
查看
739
import
I
后退
顶部