补充一下,我用createprocess来打开应用程序的,processinfo.hProcess返回的是不是就是应用程序的hwnd?
解决方案 »
- 在线求教:如何将DELPHI关键字定义为类属性?
- 请大虾 bluesun 进来领分,有哪位大虾可以解决-DBGRIDEH复制粘贴的问题也请进来领 分,谢谢!
- delphi中dbgrid输入新数据时判断是否与以前内容重复的问题
- mediaplayer
- 如何为excel的单元格的数据格式定义为"2005-1-25"的格式?
- 如何用ADO连接有密码的ACESS数据库
- [Forward]BDNradio interviews with Borland's R&D staff for Delphi 2005 and JBuilder 2005
- 该句adocommand.commandtext中类型转换的错误
- delphi 调用 C# web services 出现异常:The operation timed out....
- 在delphi中如何实现拖动功能
- 求救:在Delphi中怎样操作 XML 文件?
- 求清除Access97密码的程序代码?
var
st:TStartUpInfo;
pp:TProcessInformation;
ppp:Thandle;
begin
FillChar(st,sizeof(st),#0);
with st do
begin
cb:=sizeof(st);
dwFlags:=StartF_UsesTDHandles or STARTF_USESHOWWINDOW;
lptitle:=nil;
wShowWindow:=SW_Show;
end;
CreateProcess(PChar('c:\notepad.exe'),
nil,nil,nil,true,DETACHED_PROCESS,nil,nil,st,pp);
//关闭进程
{ ppp:=OpenProcess(PROCESS_ALL_ACCESS, FALSE,pp.dwProcessId );
TerminateProcess(ppp,0);}
end;
因为CreateProcess提供了更多的对进程控制unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
st:TStartUpInfo;
pp:TProcessInformation;
ppp:Thandle;
begin
FillChar(st,sizeof(st),#0);
with st do
begin
cb:=sizeof(st);
dwFlags:=StartF_UsesTDHandles or STARTF_USESHOWWINDOW;
lptitle:=nil;
wShowWindow:=SW_Show;
end;
CreateProcess(PChar('c:\program files\microsoft office\office\winword.exe'),
nil,nil,nil,true,DETACHED_PROCESS,nil,nil,st,pp);
//关闭进程
{ ppp:=OpenProcess(PROCESS_ALL_ACCESS, FALSE,pp.dwProcessId );
TerminateProcess(ppp,0);}
end;procedure TForm1.FormCreate(Sender: TObject);
begin
//setwindowlong(handle , GWL_STYLE, getwindowlong(handle, GWL_STYLE) and (not WS_CAPTION or WS_BORDER) or WS_Popup);
end;end.
Liu JZX (2000-1-14 17:58:00)
创建进程
CreateProcess(PChar('c:\program files\microsoft office\office\winword.exe'),
nil,nil,nil,true,DETACHED_PROCESS,nil,nil,st,pp);关闭进程
ppp:=OpenProcess(PROCESS_ALL_ACCESS, FALSE,pp.dwProcessId );
TerminateProcess(ppp,0);}
Windows系统负责维持,它能保证其中的每个原子都是唯一的,管理其引用计数,
并且当该全局原子的引用计数为0时,从内存中清除。我们用GlobalAddAtom函数
向全局原子添加一个255个字节以内的字符串,用GlobalFindAtom来检查是否已
经存在该全局原子,最后在程序结束时用GlobalDeleteAtom函数删除添加的全局
原子。示例如下: Uses Windows
const iAtom=‘SingleApp’;
begin
if GlobalFindAtom(iAtom)=0 then
begin
GlobalAddAtom(iAtom);
...... //需要单一实例的部分
GlobalDeleteAtom(GlobalFindAtom(iAtom));
end
else
MessageBox(0,‘You can not run a second copy of this App’,’,mb_OK);
//写你可以写的代码,比如激活窗口
end.
var hnd:thandle;
begin
hnd:=findwindow(nil,'未定标题 - 记事本');
if hnd<>0 then
begin
showwindow(hnd,sw_normal);
bringwindowtotop(hnd);
end
else
shellexecute(handle,'open','notepad',nil,nil,sw_normal);
end;
win32api帮助
hnd:=findwindow(nil,'未定标题 - 记事本');当中的'未定标题 - 记事本'可能用函数来得到吗?
hwd:=findwindow('Notepad',nil);通过类名查找
再继续请教下(不好意思,我有点上瘾了),如果得到刚执行完createprocess的当前焦点窗体的句柄是不是也一样的,要想得到当前焦点窗体的句柄又该怎么做呢?
这种方法很不科学。
要么使用原子,要么使用互斥量。