Windows 95/98 判斷是否在「關閉程式」對話框(Ctrl+Alt+Del)顯示應用程式,依據是主視窗是否有標題。若主視窗無標題,系統便不會列入清單。最佳清除時機在 WinMain 中:
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try {
Application->Title = ""; // 關鍵:設為空字串
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception) {
Application->ShowException(&exception);
}
return 0;
}
RegisterServiceProcess 是 Kernel32.dll 中未公開的函數,MS SDK 標頭檔無原型,但 Borland C++ Builder 的匯入庫有定義。其主要用途是建立服務模式進程,副作用是將程式從 Ctrl+Alt+Del 清單隱藏。
標頭檔:
typedef DWORD (__stdcall *pRegFunction)(DWORD, DWORD);
class TForm1 : public TForm {
__published:
TButton *Button1;
private:
HINSTANCE hKernelLib;
pRegFunction RegisterServiceProcess;
public:
__fastcall TForm1(TComponent* Owner);
__fastcall ~TForm1();
};
實作檔:
#include "Unit1.h"
#define RSP_SIMPLE_SERVICE 1
#define RSP_UNREGISTER_SERVICE 0
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
hKernelLib = LoadLibrary("kernel32.dll");
if (hKernelLib) {
RegisterServiceProcess = (pRegFunction)GetProcAddress(hKernelLib, "RegisterServiceProcess");
if (RegisterServiceProcess)
RegisterServiceProcess(GetCurrentProcessId(), RSP_SIMPLE_SERVICE);
}
}
__fastcall TForm1::~TForm1()
{
if (hKernelLib) {
if (RegisterServiceProcess)
RegisterServiceProcess(GetCurrentProcessId(), RSP_UNREGISTER_SERVICE);
FreeLibrary(hKernelLib);
}
}
常數說明: RSP_SIMPLE_SERVICE (1) 註冊為簡易服務,RSP_UNREGISTER_SERVICE (0) 註銷。