使程序窗口保持前端显示

来源:互联网 发布:数据同步解决方案 编辑:程序博客网 时间:2024/06/06 00:28
有些程序需要如暴风影音一样,始终保持前端。我们可以用API函数SetWindowsPos()来实现应用程序窗口哦那个在最前端显示。
BCB6.0环境
.h中
class TForm1 : public TForm
{
__published:// IDE-managed Components
        TImage *Image1;
        void __fastcall Form1OnCreate(TObject *Sender);
private:// User declarations
public:// User declarations
        __fastcall TForm1(TComponent* Owner);
    void __fastcall SystemMenuCommand(TWMMenuSelect &Msg);
    BEGIN_MESSAGE_MAP
    MESSAGE_HANDLER(WM_SYSCOMMAND,TWMMenuSelect,SystemMenuCommand);
    END_MESSAGE_MAP(TForm);
};


.cpp中

void __fastcall TForm1::Form1OnCreate(TObject *Sender)
{
  //设置系统菜单
  AppendMenu(GetSystemMenu(Handle,false),MF_SEPARATOR,0,"");
  AppendMenu(GetSystemMenu(Handle,false),MF_STRING,200,"最顶层显示(&A)");
}
void __fastcall TForm1::SystemMenuCommand(TWMMenuSelect &Msg)
{
    TForm::Dispatch(&Msg);
    if(Msg.IDItem==200)
    {
      if(Form1->FormStyle==fsNormal)
      {//将窗体设置为总在最顶层显示
       Form1->FormStyle=fsStayOnTop;
       //重新设置系统菜单
       AppendMenu(GetSystemMenu(Handle,false),MF_SEPARATOR,0,"");
       AppendMenu(GetSystemMenu(Handle,false),MF_STRING,200,"正常显示(&A)");
     }
      else
      {//将窗体设置为正常显示模式
       Form1->FormStyle=fsNormal;
       //重新设置系统菜单
       AppendMenu(GetSystemMenu(Handle,false),MF_SEPARATOR,0,"");
       AppendMenu(GetSystemMenu(Handle,false),MF_STRING,200,"最顶层显示(&A)");
      }
    }
}
原创粉丝点击