This program is a great tool to have. It allows you to take control of
window controls and their handles. This is like Spy++ but free. Theres
a dll that allows you to control a window from a batch file just use
rundll32 with it like
rundll32 libwndhack.dll,CloseHWND search_query
rundll32 libwndhack.dll,ShowHWND search_query
rundll32 libwndhack.dll,ClickButton search_query
rundll32 libwndhack.dll,EnableHWND search_query
rundll32 libwndhack.dll,DisableHWND search_query
The search_query is the string that will be searched for.
Here’s a screenshot of the program:
More tools and apps avaliable at
unit wndhackUnit1; {$RESOURCE wndhack32.res} interface //Main window unit uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls, ExtCtrls,shellapi, ComCtrls, ScktComp, Spin; type TWNDHacker = class(TForm) Panel1: TPanel; Label1: TLabel; HWNDEdit: TEdit; Label2: TLabel; Button1: TButton; Label3: TLabel; cname: TEdit; WNDEn: TCheckBox; WNDV: TCheckBox; Label4: TLabel; WNDTxt: TMemo; MainMenu1: TMainMenu; UpdateList1: TMenuItem; HWNDIcon: TPaintBox; GroupBox1: TGroupBox; ComboBox1: TComboBox; Label5: TLabel; Label6: TLabel; Edit1: TEdit; Label7: TLabel; Edit2: TEdit; Button2: TButton; CheckBox1: TCheckBox; Button3: TButton; Label8: TLabel; Memo1: TMemo; Label9: TLabel; Edit3: TEdit; Label10: TLabel; Edit4: TEdit; ListBox1: TListBox; Label11: TLabel; Edit5: TEdit; Label12: TLabel; Edit6: TEdit; GroupBox2: TGroupBox; Label13: TLabel; ComboBox2: TComboBox; CheckBox2: TCheckBox; Button4: TButton; Help1: TMenuItem; AboutWindowHacker1: TMenuItem; HWNDP: TComboBox; ComboBox3: TComboBox; Label14: TLabel; Tools1: TMenuItem; FindWindow1: TMenuItem; FindDialog1: TFindDialog; OpenDialog1: TOpenDialog; MouseFollower1: TMenuItem; Timer1: TTimer; StatusBar1: TStatusBar; ViewAtomTable1: TMenuItem; PopupMenu1: TPopupMenu; SaveIcon1: TMenuItem; LoadIcon1: TMenuItem; Cancel1: TMenuItem; SaveDialog1: TSaveDialog; RestoreWindow1: TMenuItem; ShowWindow1: TMenuItem; GetWindowLong1: TMenuItem; Label15: TLabel; SpinEdit1: TSpinEdit; Label16: TLabel; SpinEdit2: TSpinEdit; Label17: TLabel; SpinEdit3: TSpinEdit; SpinEdit4: TSpinEdit; Label18: TLabel; Button5: TButton; CheckBox3: TCheckBox; FindWindowEx1: TMenuItem; procedure UpdateList1Click(Sender: TObject); procedure ListBox1Click(Sender: TObject); procedure HWNDIconPaint(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure WNDVClick(Sender: TObject); procedure WNDEnClick(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Label12Click(Sender: TObject); procedure ComboBox2Change(Sender: TObject); procedure Label2Click(Sender: TObject); procedure AboutWindowHacker1Click(Sender: TObject); procedure FindDialog1Find(Sender: TObject); procedure FindWindow1Click(Sender: TObject); procedure MouseFollower1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure ViewAtomTable1Click(Sender: TObject); procedure SaveIcon1Click(Sender: TObject); procedure HWNDIconClick(Sender: TObject); procedure RestoreWindow1Click(Sender: TObject); procedure LoadIcon1Click(Sender: TObject); procedure ShowWindow1Click(Sender: TObject); procedure GetWindowLong1Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure FindWindowEx1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; { THWNDPPacket=record Reserved for Remote controllu op:integer; Handle:hwnd; classname,windowname:array[0..255]of ansichar; msg,startms,cms:dword; wparam,lparam:lparam; Return:LRESULT; end; } function GetConsoleWindow:hwnd;stdcall;external 'kernel32.dll'; var WNDHacker: TWNDHacker; hico:hicon; nochange:boolean; searchres,msgs,winstyles,shows,gwl:tstringlist; childenum:tlist; implementation {$R *.DFM} uses wndhackunit2; function EnumHWND(hw:hwnd;lp:lparam):bool;stdcall; var cname,wtxt:array[0..1024] of char; pid:dword; begin getwindowtext(hw,wtxt,1025); getclassname(hw,cname,1025); result:=true; GEtWindowThreadProcessId(hw,@pid); if pid=getcurrentprocessid then exit; wndhacker.ListBox1.Items.AddObject(StrPas(CName)+','+strpas(wtxt),TObject(hw)); wndhacker.HWNDP.Items.Add('$'+inttohex(hw,0)); if lp=0 then enumchildwindows(hw,@enumhwnd,1); end; procedure TWNDHacker.UpdateList1Click(Sender: TObject); begin listbox1.Items.Clear; childenum.Clear; hwndp.Items.Clear; listbox1.Items.AddObject('HWND_DESKTOP',TObject(getdesktopwindow)); enumwindows(@enumhwnd,0); end; procedure AddConsts(combo:tcombobox; slConsts:tstringlist); var i:integer; begin for i:=0 to slConsts.Count-1 do if StrToInt64Def(slconsts.values[slconsts.names[i]],-1)>-1 then combo.Items.Add(slConsts.names[i]); end; procedure TWNDHacker.ListBox1Click(Sender: TObject); var classname:array[0..255] of char; windowtxt:pchar; wtlen:integer; r:trect; dwprocess:dword; begin nochange:=true; HWNDEdit.Text:='$'+IntToHex(HWnd(listbox1.items.objects[listbox1.ItemIndex]),0); hwndp.Text:='$'+inttohex(getparent(hwnd(listbox1.items.objects[listbox1.ItemIndex])),0); hico:=GetClassLong(hwnd(ListBox1.items.objects[listbox1.itemindex]),GCL_HICON); if hico=0 then hico:=GetClassLong(getparent(hwnd(listbox1.items.objects[listbox1.itemindex])), gcl_hicon); if hico=0then hico:=loadicon(0,IDI_APPLICATION); drawicon(hwndicon.canvas.handle,0,0,hico); edit5.Text:='$'+inttohex(globalfindatom(classname),4); edit3.Text:=inttostr(GetWindowThreadProcessID(strtoint(hwndedit.text), @dwprocess)); edit4.Text:=inttostr(dwprocess); edit6.Text:=IntTohex(getwindowlong(strtoint(hwndedit.text),gwl_style),8)+'-'+ inttohex(getwindowlong(strtoint(hwndedit.text),gwl_exstyle),8); getclassname(hwnd(listbox1.items.objects[listbox1.itemindex]),classname,256); cname.Text:=strpas(classname); Wtlen:=GetWindowTextLength(hwnd(listbox1.items.objects[listbox1.itemindex]))+1; windowtxt:=stralloc(wtlen); GetWindowText(hwnd(listbox1.items.objects[listbox1.itemindex]),windowtxt,wtlen); wnden.Checked:= iswindowenabled(hwnd(listbox1.items.objects[listbox1.ItemIndex])); wndv.Checked:= iswindowvisible(hwnd(listbox1.items.objects[listbox1.itemindex])); wndtxt.Text:=strpas(windowtxt); strdispose(windowtxt); getwindowrect(strtoint(hwndedit.text),r); spinedit1.Value:=r.Bottom; spinedit2.Value:=r.Right; spinedit3.Value:=r.Top; spinedit4.Value:=r.Left; nochange:=false; end; procedure TWNDHacker.HWNDIconPaint(Sender: TObject); begin drawicon(HWNDIcon.Canvas.handle,0,0,hico); end; procedure TWNDHacker.FormCreate(Sender: TObject); var i:integer; msgr:tresourcestream; stylesr,showr,gwlr:tresourcestream; begin searchres:=tstringlist.Create; shows:=tstringlist.Create; showr:=tresourcestream.Create(hinstance,'SHOW','TXT'); shows.LoadFromStream(showr); showr.Free; gwlr:=tresourcestream.Create(hinstance,'GWL','TXT'); gwl:=tstringlist.Create; gwl.LoadFromStream(gwlr); gwlr.Free; childenum:=tlist.Create; combobox3.ItemIndex:=0; hico:=loadicon(0,IDI_APPLICATION); msgr:=tresourcestream.Create(hinstance,'MESSAGES','TXT'); msgs:=tstringlist.Create; msgs.LoadFromStream(msgr); msgr.Free; stylesr:=tresourcestream.Create(hinstance,'WINSTYLES','TXT'); winstyles:=tstringlist.Create; winstyles.LoadFromStream(stylesr); stylesr.Free; addconsts(combobox2,winstyles); for i:= 0 to msgs.Count-1 do if(msgs.Names[i]<>'') and(strscan(pchar(msgs[i]),'{')=nil) then combobox1.Items.Add(msgs.Names[i]); application.Title:=caption; UpdateList1.Click; end; procedure TWNDHacker.Button1Click(Sender: TObject); begin windows.SetParent(strtoint(hwndedit.text),strtoint(hwndp.text)); end; procedure MyWndMsgProc(hw:hwnd;msg:uint;Startms:DWORD;lres:lresult);stdcall; begin wndhacker.Memo1.Lines.Add(IntToHex(hw,0)+' replied within '+inttostr( gettickcount-startms)+'ms, returned '+inttohex(lres,0)); end; procedure TWNDHacker.Button2Click(Sender: TObject); var b:boolean; hw:hwnd; res:lresult; begin b:=true; res:=0; memo1.Clear; if not checkbox1.Checked then hw:=strtoint(hwndedit.text)else hw:=hwnd_broadcast; case combobox3.ItemIndex of 0:b:=sendmessagecallback(hw,strtointdef(msgs.values[combobox1.text], registerwindowmessage(pchar(combobox1.text))),strtoint(edit1.text), strtoint(edit2.text),@mywndmsgproc,gettickcount); 1:b:=PostMessage(hw,strtointdef(msgs.values[combobox1.text], registerwindowmessage(pchar(combobox1.text))),strtoint(edit1.text), strtoint(edit2.text)); 2:res:=defwindowproc(hw,strtointdef(msgs.values[combobox1.text], registerwindowmessage(pchar(combobox1.text))),strtoint(edit1.text),strtoint( edit2.text)); 3:res:=sendmessage(hw,strtointdef(msgs.values[combobox1.text], registerwindowmessage(pchar(combobox1.text))),strtoint(edit1.text),strtoint( edit2.text)); end; if not b then messagebox(handle,pchar(syserrormessage(getlasterror)),'Window Hacker',mb_iconerror); if res<>0 then memo1.Text :='Returned with '+inttohex(res,0); end; procedure TWNDHacker.WNDVClick(Sender: TObject); begin if nochange then exit; if wndv.Checked then showwindow(strtoint(hwndedit.text),sw_show)else showwindow(strtoint(hwndedit.Text),sw_hide); end; procedure TWNDHacker.WNDEnClick(Sender: TObject); begin if nochange then exit; enablewindow(strtoint(hwndedit.text),wnden.checked); end; procedure TWNDHacker.Button3Click(Sender: TObject); begin setwindowtext(strtoint(hwndedit.text),pchar(wndtxt.text)); end; procedure TWNDHacker.Button4Click(Sender: TObject); var hw:hwnd; x:integer; begin hw:=strtoint(hwndedit.text); if winstyles.Values[combobox2.Text]<>''then x:=Strtoint(winstyles.values[combobox2.text])else x:=strtoint(combobox2.text); if pos('_EX_',Uppercase(combobox2.text))>0 then begin if checkbox2.Checked then setwindowlong(hw,gwl_exstyle,getwindowlong(hw,gwl_exstyle) or x)else setwindowlong(hw,gwl_exstyle,getwindowlong(hw,gwl_exstyle) and(not x)); end else begin if checkbox2.Checked then setwindowlong(hw,gwl_exstyle,getwindowlong(hw,gwl_exstyle) or x)else setwindowlong(hw,gwl_exstyle,getwindowlong(hw,gwl_exstyle) and(not x)); end; end; procedure TWNDHacker.Label12Click(Sender: TObject); var s:string; I,x:integer; y:longint; begin s:='The window has the following styles set:'+#13#10; for i:=0to combobox2.Items.Count-1 do begin if pos('_EX_',combobox2.Items[i])>0 then x:= gwl_exstyle else x:=gwl_style; y:= strtoint(winstyles.values[ combobox2.items[i]]); if y and GetWindowLong(StrToInt(hwndedit.text),x)=y then s:=s+combobox2.Items[i]+#13#10; end; Messagebox(handle,pchar(s),'Window Hacker',0); end; procedure TWNDHacker.ComboBox2Change(Sender: TObject); var x:integer; begin if strtoint64def(Combobox2.text,-1)>-1 then x:=strtoint(combobox2.text) else if combobox2.Items.IndexOf(combobox2.text)>-1 then x:=strtoint(winstyles.values[combobox2.Text]); if pos('_EX_',Uppercase(combobox2.text))=0 then checkbox2.Checked:=(GetWindowLong(strtoint(hwndedit.Text),gwl_style) and x=x)else checkbox2.Checked:=(GetWindowLong(strtoint(hwndedit.Text),gwl_exstyle) and x=x); end; procedure TWNDHacker.Label2Click(Sender: TObject); var classn:array[0..1024]of char; wtxt:pchar; wtxtlen:integer; begin wtxtlen:=1+getwindowtextlength(strtoint(hwndp.Text)); wtxt:=stralloc(wtxtlen); getwindowtext(strtoint(hwndp.text),wtxt,wtxtlen); getclassname(strtoint(hwndp.text),classn,1025); messagebox(handle,PChar('Window Text: '+strpas(wtxt)+#13#10+ 'Class Name: '+strpas(classn)), 'Window Hacker',0); strdispose(wtxt); end; procedure TWNDHacker.AboutWindowHacker1Click(Sender: TObject); var hexe:thandle; compiletime:tfiletime; t:tdatetime; st:tsystemtime; begin hexe:=createfile(PChar(application.exename),generic_read,file_share_read or file_share_write,nil,open_existing,file_attribute_normal,0); getfiletime(hexe,nil,nil,@compiletime); closehandle(hexe); filetimetosystemtime(compiletime,st); t:=encodedate(st.wyear,st.wmonth,st.wday)+encodetime(st.whour,st.wminute,st.wsecond,0); messagebox(handle,pchar('Window Hacker v1.0 By Justin Roeder'+#13#10+ 'Compiled on: '+DateTimeToStr(t)) ,'About Window Hacker',0); end; procedure TWNDHacker.FindDialog1Find(Sender: TObject); var i:integer; q:string; begin allocconsole; findwindow1.enabled:=false; bringwindowtotop(getconsolewindow); finddialog1.CloseDialog; for i:=0 to listbox1.Items.Count-1 do if (pos(uppercase(finddialog1.findtext),uppercase(listbox1.items[i]))>0)or ('$'+inttohex(hwnd(listbox1.items.objects[i]),0)=uppercase(finddialog1.findtext)) or ('$'+inttohex(getparent(hwnd(listbox1.items.objects[i])),0)=uppercase( finddialog1.findtext))then searchres.Add(listbox1.items[i]); if searchres.Count=0 then begin writeln('Nothing found, press enter to continue...'); readln(q); findwindow1.Enabled:=true; freeconsole; exit; end; for i:=0 to searchres.Count-1 do writeln(i,'.',searchres[i]); write('Enter your choice or hit enter to cancel: '); readln(q); if q<>'' then begin listbox1.ItemIndex:=listbox1.Items.IndexOf(searchres[strtointdef(q,0)]); wndhacker.ListBox1Click(nil); end; findwindow1.Enabled:=true; freeconsole; end; procedure TWNDHacker.FindWindow1Click(Sender: TObject); begin finddialog1.Execute; end; procedure TWNDHacker.MouseFollower1Click(Sender: TObject); begin timer1.Enabled:=not timer1.Enabled; end; procedure TWNDHacker.Timer1Timer(Sender: TObject); var hw:hwnd; mouse:tpoint; desktopdc:hdc; s:String; cn,wtxt:array[0..255]of char; begin getcursorpos(mouse); hw:= windowfrompoint(mouse); if listbox1.Items.IndexOfObject(TObject(hw))>-1 then begin listbox1.ItemIndex:=listbox1.Items.IndexOfObject(tobject(hw)); listbox1click(nil); end; desktopdc:=getwindowdc(getdesktopwindow); getclassname(hw,cn,256); GetWindowText(hw,wtxt,256); s:=Format('Classname:%s WindowText:%s Handle:%x Parent:%x',[cn,wtxt,hw, getparent(hw)]); textout(desktopdc,0,0,pchar(s),length(s)); releasedc(getdesktopwindow,desktopdc); end; procedure TWNDHacker.ViewAtomTable1Click(Sender: TObject); var a:atom; aname:array[0..255]of char; hf:thandle; sherr,bwrite:dword; l:uint; s:String; cs:tstringlist; begin cs:=tstringlist.Create; hf:=CreateFile('ATOMTABL.CSV',generic_write,0,nil,create_always, file_attribute_normal,0); if hf=INVALID_HANDLE_VALUE then begin messagebox(handle,PChar(syserrormessage(getlasterror)),'Window Hacker(Create)', mb_iconerror); exit; end; s:=''; for a:=1 to $FFFF do begin l:= globalgetatomname(a,aname,256); if l>0 then begin cs.Add('0x'+inttohex(a,4)); cs.Add(aname); s:=cs.CommaText+#13#10; if not writefile(hf,s[1],length(s),bwrite,nil) then begin messagebox(handle,pchar(syserrormessage(getlasterror)),'Window Hacker(write)', mb_iconerror); exit; end; end; cs.Clear; end; closehandle(hf); cs.Free; sherr:=33; if shellexecute(0,nil,'ATOMTABL.CSV',nil,nil,sw_show)<33 then sherr:=shellexecute(0,nil,'notepad.exe','ATOMTABL.CSV',nil,sw_show); if sherr<33 then messagebox(handle,PChar(syserrormessage(sherr)), 'Window Hacker(shell)',mb_iconerror); end; procedure TWNDHacker.SaveIcon1Click(Sender: TObject); var ico:ticon; begin if not savedialog1.Execute then exit; ico:=ticon.Create; ico.Handle:=hico; ico.SaveToFile(savedialog1.filename); ico.Free; end; procedure TWNDHacker.HWNDIconClick(Sender: TObject); var poin:tpoint; begin getcursorpos(poin); restorewindow1.Enabled:=isiconic(strtoint(hwndedit.text)); popupmenu1.Popup(poin.x,poin.y); end; procedure TWNDHacker.RestoreWindow1Click(Sender: TObject); begin showwindow(strtoint(hwndedit.text),sw_show); if not openicon(strtoint(hwndedit.text)) then messagebox(handle,pchar(syserrormessage(getlasterror)),'Window Hacker', mb_iconerror); end; procedure TWNDHacker.LoadIcon1Click(Sender: TObject); var hins:hinst; ind:dword; begin if not opendialog1.Execute then exit; ind:=StrTointdef(inputbox('Icon Index#','Enter Icon Index Number','0'),0); hins:=getclasslong(strtoint(hwndedit.text),GCL_HMODULE); setclasslong(strtoint(hwndedit.text),GCL_HICON,ExtractIcon(hins,pchar( opendialog1.FileName),ind)); end; procedure TWNDHacker.ShowWindow1Click(Sender: TObject); var sw:integer; hw:hwnd; s:string; begin hw:=strtoint(hwndedit.text); s:=inputbox('ShowWindow','Enter SW_ Constant','SW_SHOWNA'); if pos('SW_',uppercase(s))=1 then sw:=StrToInt(shows.values[s])else sw:=Strtointdef(s,sw_showna); showwindow(hw,sw); end; procedure TWNDHacker.GetWindowLong1Click(Sender: TObject); var ind:integer; hw:hwnd; s:string; begin hw:=strtoint(hwndedit.text); s:=InputBox('GetWindowLong','Enter GWL Constant:','GWL_STYLE'); if strscan(pchar(s),'_')=nil then ind:=strtointdef(s,gwl_style) else ind:=strtoint(gwl.values[s]); s:=Format('Index %x equals %x',[ind,GetWindowLong(hw,ind)]); messagebox(handle,PChar(s),'Window Hacker',0); end; procedure TWNDHacker.Button5Click(Sender: TObject); begin setwindowpos(strtoint(hwndedit.text),0,spinedit3.value,spinedit4.value, spinedit2.Value,spinedit1.Value,swp_noactivate or (Byte(checkbox3.checked)*SWP_NOSENDCHANGING)); end; procedure TWNDHacker.FindWindowEx1Click(Sender: TObject); begin findwndex.Visible:=true; findwndex.BringToFront; end; end.
unit wndhackunit2; //Find Window Unit interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TFindWNDEx = class(TForm) Label1: TLabel; Edit1: TEdit; Label2: TLabel; Memo1: TMemo; Button1: TButton; Button2: TButton; Label3: TLabel; Edit2: TEdit; Button3: TButton; CheckBox1: TCheckBox; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var FindWNDEx: TFindWNDEx; childaf:hwnd; implementation {$R *.DFM} uses wndhackunit1; procedure TFindWNDEx.Button1Click(Sender: TObject); var hw:hwnd; begin if checkbox1.Checked then childaf:=0; if memo1.Text='' then hw:=findwindowex(strtointdef(edit2.text,0),childaf,pchar(edit1.text),nil)else hw:=findwindowex(strtointdef(edit2.text,0),childaf,pchar(edit1.text),pchar( memo1.text)); childaf:=hw; checkbox1.Checked:=false; if hw=0 then exit; if wndhacker.ListBox1.Items.IndexOfObject(tobject(hw))=-1 then wndhacker.UpdateList1.Click; wndhacker.ListBox1.ItemIndex:=wndhacker.ListBox1.Items.IndexOfObject(tobject(hw)); wndhacker.ListBox1Click(nil); end; procedure TFindWNDEx.Button3Click(Sender: TObject); begin edit2.text:=wndhacker.HWNDEdit.Text end; end.
library libwndhack; //API Library for Window Hacker uses SysUtils,windows,messages, Classes; {$RESOURCE wndhackdll.res} type THWNDCommand=record Opcode:byte; etc,ret,found:integer; hwnds:tlist; query:pchar; end; PHWNDCommand=^THWNDCommand; function GetConsoleWindow:HWND;stdcall;external 'kernel32.dll'; var lasterr:pchar=nil; def_cmd:thwndcommand; dc:hdc; function WNDGetLastError:pchar;stdcall; begin result:=lasterr; end; function MyWNDEnum(hw:hwnd;var lp:thwndcommand):bool;stdcall; var wtxt,cn:array[0..255]of char; begin getclassname(hw,cn,256); getwindowtext(hw,wtxt,256); result:=true; if (strpos(cn,lp.query)<>nil)or(strpos(wtxt,lp.query)<>nil)then begin lp.found:=lp.found+1; case lp.Opcode of 1:lp.ret:= Integer(ShowWindow(hw,lp.etc)); 2:lp.ret:= integer(EnableWindow(hw,(lp.etc=1))); 3:lp.ret:= sendmessage(hw,bm_Click,0,0 ); 4:lp.ret:=sendmessage(hw,wm_destroy,0,0); 5:lp.ret:=sendmessage(hw,wm_close,0,0); 6:lp.ret:=setparent(hw,lp.etc); end; lp.hwnds.Add(Pointer(hw)); end; if not enumchildwindows(hw,@mywndenum,integer(@lp))then lasterr:='EnumChildWindows failed'; end; function ShowHWND(hwnderr:hwnd;reserved:dword;lpQuery:pchar;nshow:integer):POINTER;stdcall; var cmd:phwndcommand; begin new(cmd); cmd.query:=lpquery; cmd.found:=0; cmd.Opcode:=1; cmd.etc:=nshow; cmd.hwnds:=tlist.Create; if not enumwindows(@mywndenum,Integer(cmd))then if reserved>0 then begin messagebox(hwnderr,'EnumWindows Failed',nil,mb_iconerror); exitprocess(0); end else lasterr:='EnumWindows failed'; if reserved>0 then exitprocess(cmd.found); result:=cmd; end; function ClickButton(hwnderr:hwnd;reserved:dword;lpQuery:pchar; nshow:integer):POINTER;stdcall; var cmd:phwndcommand; begin new(cmd); cmd.query:=lpquery; cmd.found:=0; cmd.Opcode:=3; cmd.etc:=0; cmd.hwnds:=tlist.Create; if not enumwindows(@mywndenum,Integer(cmd))then if reserved>0 then begin messagebox(hwnderr,'EnumWindows Failed',nil,mb_iconerror); exitprocess(0); end else lasterr:='EnumWindows failed'; if reserved>0 then exitprocess(cmd.found); result:=cmd; end; function GetFoundWindowCount(var lpHWNDCMD:THWNDCommand):integer;stdcall; begin result:=lphwndcmd.found; end; function GetWNDReturnValue(var lpWND:THWNDCommand):integer;stdcall; begin result:=lpWND.ret; end; function HWNDPop(lpWND:pHWNDCommand):hwnd;stdcall; begin result:=0; try result:=hwnd(lpwnd.hwnds[0]); lpwnd.hwnds.Delete(0); except on e:exception do lasterr:=PChar(e.message); end; end; procedure WNDHackFree(p:phwndcommand);stdcall; begin if p.hwnds<>nil then p.hwnds.Free; dispose(p); end; procedure WNDResetError;stdcall; begin lasterr:=nil; end; function DestroyHWND(hwnderr:hwnd;reserved:dword;lpQuery:pchar; nshow:integer):POINTER;stdcall; var cmd:phwndcommand; begin new(cmd); cmd.query:=lpquery; cmd.found:=0; cmd.Opcode:=4; cmd.hwnds:=tlist.Create; if not enumwindows(@mywndenum,Integer(cmd))then if reserved>0 then begin messagebox(hwnderr,'EnumWindows Failed',nil,mb_iconerror); exitprocess(0); end else lasterr:='EnumWindows failed'; if reserved>0 then exitprocess(cmd.found); result:=cmd; end; function CloseHWND(hwnderr:hwnd;reserved:dword;lpQuery:pchar; nshow:integer):POINTER;stdcall; var cmd:phwndcommand; begin new(cmd); cmd.query:=lpquery; cmd.found:=0; cmd.Opcode:=5; cmd.hwnds:=tlist.Create; if not enumwindows(@mywndenum,Integer(cmd))then if reserved>0 then begin messagebox(hwnderr,'EnumWindows Failed',nil,mb_iconerror); exitprocess(0); end else lasterr:='EnumWindows failed'; if reserved>0 then exitprocess(cmd.found); result:=cmd; end; procedure ScreenSaverBox(hwn:hwnd;inst:hinst;lpscrfile:pchar;nshow:integer);stdcall; begin allocconsole; setconsoletitle(lpscrfile); if winexec(pchar(strpas(lpscrfile)+' /P '+inttostr(getconsolewindow)),sw_show)>31 then while true do asm NOP end; MessageBox(hwn,'Error opening screensaver','Window Hacker',mb_iconerror); end; function CreateBox(shw:hwnd;resered:dword;lpQuery:PCHAR;nshow:integer):bool;stdcall; var cmd:phwndcommand; hw:hwnd; i:integer; S,q:string; begin result:=allocconsole; setconsoletitle('WNDHackerBox'); setclasslong(getconsolewindow,gcl_hicon,loadicon(getmodulehandle('libwndhack.dll'), 'WNDMAN')); writeln('Box for ',lpquery); writeln('Box handle is $',inttohex(getconsolewindow,0)); new(cmd); cmd.Opcode:=6; cmd.etc:= Integer(Getconsolewindow); cmd.found:=0; cmd.query:=lpquery; cmd.hwnds:=tlist.Create; enumwindows(@mywndenum,Integer(cmd)); writeln(cmd.found,' windows has joined this box'); hw:=HWNDPop(cmd); while hw<>0 do begin writeln('Window Handle $',inttohex(hw,0),' has joined this box');hw:=hwndpop(cmd); end; while true do begin write('WNDHack>'); readln(s); s:=trim(s); if Uppercase(s)='HELP' then begin writeln('Commands Avaliable:'); writeln('ADD searches for a window objects and adds them to this box'); writeln('CLOSE Sends WM_CLOSE message to all window objects that are apart of this box'); end; if uppercase(s)='ADD' then begin write('WindowName/Classname:'); readln(q); cmd.query:=PChar(q); enumwindows(@mywndenum,Integer(cmd)); end; if Uppercase(s)='CLOSE' then for i:= 0 to cmd.hwnds.count-1do sendmessage(HWND(CMD.hwnds[i]),wm_close,0,0); end; end; function EnableHWND(hwnderr:hwnd;reserved:dword;lpQuery:pchar; nshow:integer):POINTER;stdcall; var cmd:phwndcommand; begin new(cmd); cmd.query:=lpquery; cmd.found:=0; cmd.Opcode:=2; cmd.etc:=1; cmd.hwnds:=tlist.Create; if not enumwindows(@mywndenum,Integer(cmd))then if reserved>0 then begin messagebox(hwnderr,'EnumWindows Failed',nil,mb_iconerror); exitprocess(0); end else lasterr:='EnumWindows failed'; if reserved>0 then exitprocess(cmd.found); result:=cmd; end; function DisableHWND(hwnderr:hwnd;reserved:dword;lpQuery:pchar; nshow:integer):POINTER;stdcall; var cmd:phwndcommand; begin new(cmd); cmd.query:=lpquery; cmd.found:=0; cmd.Opcode:=2; cmd.etc:=0; cmd.hwnds:=tlist.Create; if not enumwindows(@mywndenum,Integer(cmd))then if reserved>0 then begin messagebox(hwnderr,'EnumWindows Failed',nil,mb_iconerror); exitprocess(0); end else lasterr:='EnumWindows failed'; if reserved>0 then exitprocess(cmd.found); result:=cmd; end; function WindowSearch(lpQuery:pchar):phwndcommand;stdcall; begin new(result); result.Opcode:=0; result.hwnds:=tlist.Create; result.found:=0; if not enumwindows(@mywndenum,integer(result)) then lasterr:='EnumWindows failed'; end; function ChangeParent(hwnderr:hwnd;reserved:dword;lpQuery:pchar; nshow:integer):POINTER;stdcall; var cmd:phwndcommand; sl:tstringlist; begin sl:=tstringlist.Create; sl.CommaText:=strpas(lpQuery); new(cmd); cmd.query:=PChar(sl[0]); cmd.found:=0; cmd.Opcode:=6; cmd.etc:=strtointdef(sl[1],getdesktopwindow); cmd.hwnds:=tlist.Create; sl.Free; if not enumwindows(@mywndenum,Integer(cmd))then if reserved>0 then begin messagebox(hwnderr,'EnumWindows Failed',nil,mb_iconerror); exitprocess(0); end else lasterr:='EnumWindows failed'; if reserved>0 then exitprocess(cmd.found); result:=cmd; end; function WNDHackSize(var wnddata:thwndcommand):integer;stdcall; begin result:=sizeof(wnddata); end; procedure QueryFirstWindow(hw:hwnd;inst:hinst;lpQuery:pchar;nShow:integer);stdcall; var cmd:phwndcommand; begin new(cmd); cmd.Opcode:=0; cmd.query:=lpquery; cmd.found:=0; cmd.hwnds:=tlist.Create; enumwindows(@mywndenum,integer(cmd)); if cmd.found=0 then exitprocess(0); exitprocess(hwndpop(cmd)); end; exports WNDGetLastError,ShowHWND,HWNDPop,WNDHackFree,GetWNDReturnValue,CreateBox, GetFoundWindowCount,WNDResetError,ClickButton,CloseHWND,DestroyHWND,DisableHWND, EnableHWND,WindowSearch,ChangeParent,WNDHackSize,QueryFirstWindow,ScreenSaverBox; begin end.