办法多的是:
1.创建Mutex来互斥
2.建立文件记录程序运行状态:一旦程序运行,则设一个值为1,退出时设为0,程序运行前,先看看这个标识就搞定了,呵呵~~
1.创建Mutex来互斥
2.建立文件记录程序运行状态:一旦程序运行,则设一个值为1,退出时设为0,程序运行前,先看看这个标识就搞定了,呵呵~~
解决方案 »
- 玫举类型的问题
- 我想问一下,SOCKET发送信息除了发送TEXT格式外,还有一种把数据封包发送的方法,
- 100分问,我想做一个和outlook写邮件类似的编辑器,可以插入图片和对文字操做的,问哪里有控件,或者怎么做
- 如何判断所写的判断语句是否正确?
- 急!!关于dbgrid多行显示的问题
- 用adoquery的那个方法能删除掉在dbgrid里指定的数据?或是删除指定的记录位置(第几个记录)的数据?
- 串口通讯
- 请问:我如何判断所输入的字符串是一个日期?
- 关于Delphi的网络传输编程
- 我的单机版已做好,怎样转成c/s模型??????
- 我的delphi6.0不能打补丁,为什么?已经是企业版了,z9j8-pum4n-c6gzq,rw2-7jw
- 请教:如何才能在QUICKREPORT中用CANVAS直接画图?
Var Ret:Integer;
begin
CreateMutex(nil,False,'aaaaaa');
Ret:=GetLastError;
if Ret = ERROR_ALREADY_EXISTS Then begin
Application.MessageBox('重复运行', '重复运行', MB_OK + MB_ICONEXCLAMATION);
Application.Terminate;
end;
end;
办法多的是:
1.创建Mutex来互斥
如WINAMP的TITILE是会改的啊,在任务栏上的名称是当前播放的歌名2.建立文件记录程序运行状态:一旦程序运行,则设一个值为1,退出时设为0,程序运行前,先看看这个标识就搞定了,呵呵~~
我也想这样做可是是不正常退出就不行了
unit MultInst;interfaceconst
MI_QUERYWINDOWHANDLE = 1;
MI_RESPONDWINDOWHANDLE = 2; MI_ERROR_NONE = 0;
MI_ERROR_FAILSUBCLASS = 1;
MI_ERROR_CREATINGMUTEX = 2;// Call this function to determine if error occurred in startup.
// Value will be one or more of the MI_ERROR_* error flags.
function GetMIError: Integer;implementationuses Forms, Windows, SysUtils;const
UniqueAppStr = 'DDG.I_am_the_Eggman!';var
MessageId: Integer;
WProc: TFNWndProc;
MutHandle: THandle;
MIError: Integer;function GetMIError: Integer;
begin
Result := MIError;
end;function NewWndProc(Handle: HWND; Msg: Integer; wParam, lParam: Longint):
Longint; stdcall;
begin
Result := 0;
// If this is the registered message...
if Msg = MessageID then
begin
case wParam of
MI_QUERYWINDOWHANDLE:
// A new instance is asking for main window handle in order
// to focus the main window, so normalize app and send back
// message with main window handle.
begin
if IsIconic(Application.Handle) then
begin
Application.MainForm.WindowState := wsNormal;
Application.Restore;
end;
PostMessage(HWND(lParam), MessageID, MI_RESPONDWINDOWHANDLE,
Application.MainForm.Handle);
end;
MI_RESPONDWINDOWHANDLE:
// The running instance has returned its main window handle,
// so we need to focus it and go away.
begin
SetForegroundWindow(HWND(lParam));
Application.Terminate;
end;
end;
end
// Otherwise, pass message on to old window proc
else
Result := CallWindowProc(WProc, Handle, Msg, wParam, lParam);
end;procedure SubClassApplication;
begin
// We subclass Application window procedure so that
// Application.OnMessage remains available for user.
WProc := TFNWndProc(SetWindowLong(Application.Handle, GWL_WNDPROC,
Longint(@NewWndProc)));
// Set appropriate error flag if error condition occurred
if WProc = nil then
MIError := MIError or MI_ERROR_FAILSUBCLASS;
end;procedure DoFirstInstance;
// This is called only for the first instance of the application
begin
// Create the mutex with the (hopefully) unique string
MutHandle := CreateMutex(nil, False, UniqueAppStr);
if MutHandle = 0 then
MIError := MIError or MI_ERROR_CREATINGMUTEX;
end;procedure BroadcastFocusMessage;
// This is called when there is already an instance running.
var
BSMRecipients: DWORD;
begin
// Prevent main form from flashing
Application.ShowMainForm := False;
// Post message to try to establish a dialogue with previous instance
BSMRecipients := BSM_APPLICATIONS;
BroadCastSystemMessage(BSF_IGNORECURRENTTASK or BSF_POSTMESSAGE,
@BSMRecipients, MessageID, MI_QUERYWINDOWHANDLE,
Application.Handle);
end;procedure InitInstance;
begin
SubClassApplication; // hook application message loop
MutHandle := OpenMutex(MUTEX_ALL_ACCESS, False, UniqueAppStr);
if MutHandle = 0 then
// Mutex object has not yet been created, meaning that no previous
// instance has been created.
DoFirstInstance
else
BroadcastFocusMessage;
end;initialization
MessageID := RegisterWindowMessage(UniqueAppStr);
InitInstance;
finalization
// Restore old application window procedure
if WProc <> Nil then
SetWindowLong(Application.Handle, GWL_WNDPROC, LongInt(WProc));
if MutHandle <> 0 then CloseHandle(MutHandle); // Free mutex
end.
结了贴吧
多谢CHECKY