Einzelnen Beitrag anzeigen

Benutzerbild von sirius
sirius

Registriert seit: 3. Jan 2007
Ort: Dresden
3.443 Beiträge
 
Delphi 7 Enterprise
 
#6

Re: MinValue einer fremden SpinEdit ändern

  Alt 6. Feb 2008, 17:41
Ui, das war doch etwas umständlicher als ich dachte.

Delphi-Quellcode:
uses typinfo;

function getwindowLongEx(hProcess:THandle;wnd:hwnd):cardinal;
const Procsize=200;
type PPThread=^TPThread;
     TPThread=packed record
       Proc:array[0..Procsize-1] of char;
       wndproc:cardinal;
       wnd:hwnd;
       getWindowLong:function(wnd:hwnd;param:integer):cardinal;stdcall;
     end;
  function RemoteThread(param:PPThread):integer;stdcall;
  begin
    param^.wndproc:=param^.getWindowLong(param^.wnd,gwl_wndproc);
    result:=0;
  end;
  procedure dispRT;
  asm nop end;

var lib:hmodule;
    PThread:TPThread;
    mThread:PPThread;
    source:pointer;
    ThreadID,temp:cardinal;
    hThread:THandle;
begin
  source:=@RemoteThread;
  move(source^,PThread.Proc[0],integer(@dispRT)-integer(source));
  lib:=getmodulehandle('user32.dll');
  PThread.getWindowLong:=getprocaddress(lib,'GetWindowLongA');
  Pthread.wnd:=wnd;
  PThread.wndproc:=0;
  mThread:=virtualallocEx(hProcess,nil,sizeof(TPThread),MEM_Commit or MEM_Reserve,Page_Execute_READWrite);
  writeprocessmemory(hProcess,mThread,@PThread,sizeof(TPThread),temp);
  hThread:=createremotethread(hProcess,nil,0,mThread,mThread,0,ThreadID);
  if waitforsingleobject(hThread,2000)=Wait_Object_0 then
  begin
    readprocessmemory(hProcess,mThread,@PThread,sizeof(TPThread),temp);
    result:=PThread.wndproc;
    closehandle(hThread);
    virtualfreeEx(hProcess,mThread,0,Mem_Release);
  end else
    result:=0;
end;


function changeProperty(wnd:hwnd;AClass:TClass;PropName:string;Value:Integer):boolean;
type TSetProc=packed record
       case Boolean of
         TRUE:(SetProc:Pointer);
         FALSE:(Pos:word; Ident:Word);
     end;
var wndproc:cardinal;
    obj,inst:pointer;
    setp:TSetProc;
    hProcess:Thandle;
    PID,temp:Cardinal;
begin
  getwindowthreadProcessID(wnd,PID);
  try
    hProcess:=openprocess(Process_ALL_ACCESS,false,PID);
    if hProcess<>0 then
    begin
      try
        wndProc:=getwindowlongEx(hProcess,wnd);
        obj:=pointer(wndproc+9);
        setp.SetProc:=getpropinfo(AClass,PropName).SetProc;
        if setp.ident<>$FF00 then setp.SetProc:=getpropinfo(AClass,PropName).GetProc;
        if setp.ident=$FF00 then
        begin
          if readprocessmemory(hProcess,obj,@inst,4,temp) then
          begin
            inst:=pointer(cardinal(inst)+setp.Pos);
            result:=writeProcessMemory(hProcess,inst,@value,4,temp);
          end else
            result:=false;
        end else
          result:=false;
      finally
        closehandle(hProcess);
      end;
    end else
      result:=false;
  except
    result:=false;
  end;
end;
Keine Garantie, dass das funktioniert!

Damit kannst du in einem anderen Delphiprogramm ein published 32bit-Property eines TWincontrols (oder deren Nachfahre) ändern, wenn entweder der Getter oder der Setter keine Methoden sind (was für MinValue und MaxValue von TSpinEdit zutrifft).

Anwendung (für deinen Fall):
Delphi-Quellcode:
changeProperty(wnd,TSpinEdit,'MinValue',0);
//0 ist der neue Wert
Dieser Beitrag ist für Jugendliche unter 18 Jahren nicht geeignet.
  Mit Zitat antworten Zitat