那位大虾能帮小弟一个忙,把我的一段delphi代码生成类库给我啊,或翻译成C#代码,就散分呀 procedure TForm1.Button1Click(Sender: TObject); var Mwd,Cwd :LongInt ; st : TSystemTime; pid,phd:thandle; p:pointer; l:dword; b:boolean; nm:NMHDR; tg:tagNMDATETIMECHANGE; begin Mwd :=FindWindow(nil,'TEST3'); if (mwd=0) then begin ShowMessage('error1'); exit; end; Cwd :=FindWindowEx(Mwd,0,'TDateTimePicker',nil); if(cwd=0) then begin ShowMessage('error2'); exit; end; GetWindowThreadProcessId(mwd,pid); phd:=openprocess(PROCESS_ALL_ACCESS,false,pid); p:=VirtualAllocEx(phd,nil,sizeof(tg), MEM_COMMIT, PAGE_EXECUTE_READWRITE); if (p=nil) then begin ShowMessage('error3'); CloseHandle(phd); exit; end; l:=0; DateTimeToSystemTime(Date-2, st); nm.hwndFrom:=cwd; nm.idFrom:=0; nm.code:=DTN_DATETIMECHANGE; tg.nmhdr:=nm; tg.dwFlags:=GDT_VALID; tg.st:=st; b:=WriteProcessMemory(phd,p,@tg,sizeof(tg),l); if ((not b )or (l<>sizeof(tg)) )then begin ShowMessage('error4'); CloseHandle(phd); exit; end; Postmessage(cwd, WM_NOTIFY,0, Longint(p)); //cwd也可为mwd Sleep(100); //不能马上释放内存,因为目标还未收到 if ( VirtualFreeEx(phd,p,0, MEM_RELEASE))=nil then begin Showmessage('error5'); end; CloseHandle(phd); end;
不过对具体的例子应该有可能用win api来处理。
procedure TForm1.Button1Click(Sender: TObject);
var
Mwd,Cwd :LongInt ;
st : TSystemTime;
pid,phd:thandle;
p:pointer;
l:dword;
b:boolean;
nm:NMHDR;
tg:tagNMDATETIMECHANGE;
begin
Mwd :=FindWindow(nil,'TEST3');
if (mwd=0) then
begin
ShowMessage('error1');
exit;
end;
Cwd :=FindWindowEx(Mwd,0,'TDateTimePicker',nil);
if(cwd=0) then
begin
ShowMessage('error2');
exit;
end;
GetWindowThreadProcessId(mwd,pid);
phd:=openprocess(PROCESS_ALL_ACCESS,false,pid);
p:=VirtualAllocEx(phd,nil,sizeof(tg), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (p=nil) then
begin
ShowMessage('error3');
CloseHandle(phd);
exit;
end;
l:=0;
DateTimeToSystemTime(Date-2, st);
nm.hwndFrom:=cwd;
nm.idFrom:=0;
nm.code:=DTN_DATETIMECHANGE;
tg.nmhdr:=nm;
tg.dwFlags:=GDT_VALID;
tg.st:=st;
b:=WriteProcessMemory(phd,p,@tg,sizeof(tg),l);
if ((not b )or (l<>sizeof(tg)) )then
begin
ShowMessage('error4');
CloseHandle(phd);
exit;
end;
Postmessage(cwd, WM_NOTIFY,0, Longint(p)); //cwd也可为mwd
Sleep(100); //不能马上释放内存,因为目标还未收到
if ( VirtualFreeEx(phd,p,0, MEM_RELEASE))=nil then
begin
Showmessage('error5');
end;
CloseHandle(phd);
end;