发信人: mrcloud() 
整理人: wenbobo(2002-12-06 22:33:17), 站内信件
 | 
 
 
【 在 lifelover (阿北) 的大作中提到: 】
 : 我编了一个基于对话框的程序,想在程序一启动就隐藏窗口。
 : 如果用ShowWindow函数该在哪里加入代码呢?我试过在OnInitDialog()
 : 中是不行的。请大家帮帮我。
 
 在BCB中是这样的:
 
 TaskBar:
 WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
 {
  try
  {
   Application->Initialize();
   Application->CreateForm(__classid(TForm1), &Form1);
   ShowWindow(Application->Handle,SW_HIDE); 
   Application->ShowMainForm=false;
   Application->Run();
  }
  catch(Exception &exception)
  {
   Application->ShowException(&exception);
  }
  return 0;
  }
 }
 要显示时:
 ShowWindow(Application->Handle,SW_SHOW);
 Visible=true;
 要再隐藏:
 ShowWindow(Application->Handle,SW_HIDE);
 Visible=false;
 
 TaskManager:
 //------------Header file------------------------------
 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();
 };
 //-----------CPP file------------------------------
 #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_SERVI CE);
   FreeLibrary(hKernelLib);
  }
 }
 //-------------------------------------------------
 Note: RegisterServiceProcess 在 Windows NT 中无效。
 
 
  -- ...我的征途是星辰大海...
  ※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.101.63.121]
  | 
 
 
 |