有些程序需要如暴风影音一样,始终保持前端。我们可以用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)");
}
}
}