如果程序有两个或者两个以上的窗体,在非主窗体(启动窗体)中使用
SetWindowPos(Form2->Handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);
好像没有效果.但在主窗体中这样用可以,为什么?
其实重载Form的CreateParam函数,改变WndParent就可以了。这个
WndParent只要不是Application->Handle就可以了。
class TForm2 : public TForm
{
__published: // IDE-managed Components
private: // User declarations
protected:
void __fastcall CreateParams(TCreateParams&);
public: // User declarations
__fastcall TForm2(TComponent* Owner);
};
void __fastcall TForm2::CreateParams(TCreateParams& Params)
{
TForm* Form;
TForm::CreateParams(Params);
Form = dynamic_cast<TForm*>(Owner);
Params.WndParent = Form ? Form->Handle
: Application->MainForm->Handle;
}