操纵其他程序的SysDateTimePick32
procedure TForm1.Button1Click(Sender: TObject);var
Mwd,Cwd: LongInt;
st: TSystemTime;
pid,phd: thandle;
p: pointer;
l: dword;
b: boolean;
begin
Mwd := h;// (h是父窗口句柄,事先取不赘述)
GetWindowThreadProcessId(mwd, pid);
phd := openprocess(PROCESS_ALL_ACCESS, true, pid);
VirtualAllocEx(phd,p,sizeof(st), MEM_COMMIT, PAGE_READWRITE);
if p = nil then
begin
ShowMessage('error1');
exit;
end;
l:=0;
Cwd := FindWindowEx(Mwd, 0, 'SysDateTimePick32', nil);
DateTimeToSystemTime(Date-6, st);
b:=WriteProcessMemory(phd, p, @st, sizeof(st), l);
if (not b) and (l<>sizeof(st)) then
begin
ShowMessage('error2');
exit;
end;
PostMessage(cwd, DTM_SETSYSTEMTIME, GDT_VALID, longint(p));
CloseHandle(phd);// 这两行是重点,必须有
p := nil;
end;
说明:使用上面的代码操作时,一定不能动态申请内存,比如控件的hint之类,必须事先在全局变量中定义变量,让系统为变量事先分配内存,否则出错。
来源:http://www.slit.cn/bbs/forum.php?mod=viewthread&tid=494283 thank you! ^_^
页:
[1]