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;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)