Posted on 2007-12-25 15:06
江边之鸟 阅读(998)
评论(0) 编辑 收藏 引用 所属分类:
c++
在《C++Builder深度历险》这本书中有很详细的说明
以下工程.H文件:可以实现已运行的程序在最小化时再运行第二个时还原第一个程序。。。。。
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", Form1);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
HWND AppWnd=FindWindow("TApplication","Shally Title");
if(AppWnd)
{
if(IsIconic(AppWnd))
{
ShowWindow(AppWnd,SW_RESTORE);
}
else
{
SetForegroundWindow(AppWnd);
}
return 0;
}
try
{
Application->Initialize();
Application->Title="Shally Title";
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------Top
4 楼binbin(破坏分子)回复于 2002-12-27 22:21:40 得分 0
findwindow
互斥量
注册热键
...Top
5 楼HUANG_JH(保卫钓鱼岛)回复于 2002-12-27 22:27:59 得分 10
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
HANDLE hMutexHandle = CreateMutex(NULL,true,"Application Already Run!");
if (GetLastError()!=ERROR_ALREADY_EXISTS)
{
try
{
Application->Initialize();
.......
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
else
{
Application->MessageBox("Application Already Run!","Warnning", MB_OK|MB_ICONWARNING);
}
ReleaseMutex(hMutexHandle);
CloseHandle(hMutexHandle);
return 0;
}
Top
6 楼penu(懒猫·子在川上之再上征程·杀人无心之寓怒于静)回复于 2003-01-07 11:35:39 得分 0
有个最简单的方法:
在CB6的Examples中有个控件:在\Controls\SingleInst目录下。
打开包编译并安装,在组件面板中会增加一个控件SingleInst,把它拉到你的Form中,设为有效就行了。