delphi 判断程序是否运行、自定义消息显示程序运行界面

来源:互联网 发布:退货淘宝id是什么意思 编辑:程序博客网 时间:2024/05/21 17:51
view source中代码 引用windows类var  mymutex: THandle;begin  mymutex:=CreateMutex(nil,True,'Demo程序');  if GetLastError<>ERROR_ALREADY_EXISTS then  //判断是否运行  begin    Application.Initialize;    Application.MainFormOnTaskbar := false;    Application.CreateForm(TFrmDemo, FrmDemo);    Application.Run;  end else  begin    hPrevInst := FindWindow(PChar('TFrmDemo'), nil); //获取程序句柄    if (hPrevInst <> 0) then    begin      PostMessage(hPrevInst, WM_RESTOREWINDOW, 0, 0);  //给程序发送消息      Application.ShowMainForm := False;      Application.Terminate;      Exit;    end;  end;end.


程序主窗体接收显示消息代码

const  WM_RESTOREWINDOW = WM_USER+1209;  //自定义显示消息procedure FormRestoreWindow(var Message: TMessage); message WM_RESTOREWINDOW;  //定义消息接收方法procedure TFrmDemo.FormRestoreWindow(var Message: TMessage);begin  //显示程序界面  Visible := True;  Application.Restore;  Application.BringToFront;  Application.MainFormOnTaskbar := True;end;


自定义消息机制实现控制程序、达到的所想功能

0 0
原创粉丝点击