启动一个程序,该程序启动时发现当前已经运行本程序一个实例时,自动将已运行的实例最大化。请问有什么好的处理方式,我曾经想过用网络组件来联系两个实例,但是视乎太笨了,是否有更好的方式?
解决方案 »
- 上传文件问题 服务器端怎么接收???
- boss提了个需求,直接傻了。。
- delphi中有计算矩阵的函数(比如求逆矩阵)和求指数的函数吗?
- 关于RICHEDIT的问题,大哥们救命!
- SELECT * FROM :Tname; 如何将Tname参数传递给SQL
- 通过BDE连接ORACLE在程序中设定密码的问题????在线给分。(user name/password)
- 控制 edit 的输入。只需输入数字。如何实现?在线等
- adotable1.create(nil) 和 adotable1:=TADOTable.create(nil)的区别是什么?
- 一个Delphi新手求助:MDI+登陆窗体 的问题!!
- delphi的帮助应该怎么阅读?我怎么找不到头绪,另外sdk什么意思??
- Delphi7中ADOQuery结果集
- 我有个idea 高手都来看看
myMutex:HWND;begin
myMutex:=CreateMutex(nil,false,'hkOneCopy');
if WaitForSingleObject(myMutex,0) = wait_TimeOut then
begin
Application.MessageBox('Programme is running','Duplicate');
halt;
end;
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.
procedure TMainFrm.OpenForm(FormClass: TFormClass; var FormInstance; AOwner: TComponent);
var
i: integer;
alived: boolean;
begin
alived:= false;
for i := 0 to Screen.FormCount - 1 do
if screen.Forms[i].Owner = Aowner then exit else
if Screen.Forms[i].ClassType = FormClass then alived:= true;
if not alived then
Application.CreateForm(FormClass,FormInstance);
ShowWindow(TForm(FormInstance).Handle,SW_SHOWMINIMIZED);
ShowWindow(TForm(FormInstance).Handle,SW_SHOWMAXIMIZED);
end;//执行
// OpenForm(TForm1,Form1,MainFrm);
program Project1;uses
Forms,
Windows,
Messages,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}var
hMutex: THandle;
h: HWND;
const
NameMutex = 'Global\ABCMutex';begin
if OpenMutex(MUTEX_ALL_ACCESS, False, NameMutex) <> 0 then
begin
MessageBox(0, '有了', '提示', MB_OK);
h:= FindWindow('TForm1','Form1');
SendMessage(h, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
Application.Terminate;
end else
begin
hMutex := CreateMutex(nil, False, NameMutex);
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
CloseHandle(hMutex);
end;
end.