怎么做到让程序窗口始终显示在桌面最上层,即始终掩盖在其他打开的窗口之上?(求C#实现代码)

怎么做到让程序窗口始终显示在桌面最上层,即始终掩盖在其他打开的窗口之上?(求C#实现代码),第1张

[DllImport("user32dll",
CharSet
=
CharSetAuto)]

private
static
extern
int
SetWindowPos(IntPtr
hWnd,
int
hWndInsertAfter,
int
x,
int
y,
int
Width,
int
Height,
int
flags);

///
<summary>

///
得到当前活动的窗口

///
</summary>

///
<returns></returns>

[DllImport("user32dll",
CharSet
=
CharSetAuto)]

private
static
extern
SystemIntPtr
GetForegroundWindow();
哪个窗体想要置顶,在Form_Load中加上
SetWindowPos(thisHandle,
-1,
0,
0,
0,
0,
1
|
2);
//最后参数也有用1
|
4 
具体说明,看API函数说明
如果是用点击一个按钮后d出新窗体,并置顶,则:

Form2
frm
=
new
Form2();

frmShow();

SetWindowPos(GetForegroundWindow(),
-1,
0,
0,
0,
0,
1
|
2);
这样,新打开的窗体就是置顶了。

void MainWindow::onBtnMenuMaxClicked(bool)
{
QRect deskTopRect = qApp->desktop()->availableGeometry();
if (max==true) {
int allw = deskTopRectwidth();
int allh = deskTopRectheight();
int unitw=allw/4;
int unith=allh/4;
this->resize(unitw2,unith2);
this->move(unitw,unith);
ui->pushButton_max->setToolTip(tr("最大化"));
}
if (max==false)
{
qDebug()<<"dataRecvSend rectApp= "<<deskTopRect;
this->setGeometry(deskTopRect);
ui->pushButton_max->setToolTip(tr("还原"));
}
max = !max;
}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13401063.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-29
下一篇 2023-07-29

发表评论

登录后才能评论

评论列表(0条)

保存