高分求:如何将窗口放在最顶层?

cometome 2005-11-17 09:48:46
如何将窗口放在最顶层?点其他窗口时该窗口也在最顶层,只是焦点不在上面。
...全文
166 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
cometome 2005-11-17
  • 打赏
  • 举报
回复
感动ing,还是VB版比较温暖啊,这么多人这么快回复,rainstormmaster(暴风雨 v2.0)和bbhere(阿忠(baby,i'll be just here waiting for you)) 兄都写的对,但rainstormmaster的答案最好(怎么好法,自己试一下就知道了),因此给他的分多点。派分了,谢谢!
rainstormmaster 2005-11-17
  • 打赏
  • 举报
回复
另一种方法是用setwindowlong修改窗口风格,为其附加WS_EX_TOPMOST风格
bbhere 2005-11-17
  • 打赏
  • 举报
回复
Declare Function SetWindowPos Lib"user"(Byval h%,Byval hb%,Byval x%,Byval y%,By

val cx%,Byval cy%,Byval f%)As Integer

Global Const SWP_NOMOVE=2

Global Const SWP_NOSIZE=1

Global Const HWND_TOPMOST= 1

Global Const HWND_NOTOPMOST=2

Global Const FLAGS=SWP_NOMOVE Or SWP_NOSIZE

(2)假设要把窗体frmExample设置成总在最前面的窗口,只要在frmExample窗体的Form_Load过程里加入以下代码:

Dim success%

success=SetWindowPos(frmExample.hWnd,HWND_TOPMOST,0,0,0,0,FLAGS)

如果要取消总在最前面的特性,则可以执行如下的代码:

success=SetWindowPos(frmExample.hWnd,HWND_NOTOPMOST,0,0,0,0,FLAGS)

success不等于0表示SetWindowPos执行成功。
winehero 2005-11-17
  • 打赏
  • 举报
回复
点其他窗口时该窗口也在最顶层,只是焦点不在上面。
——————————————————————————————

楼上的,你那个是模态窗体,要看清楚LZ的问题(如上),呵呵。。。
winehero 2005-11-17
  • 打赏
  • 举报
回复
来晚了,蹭分。。。
bbhere 2005-11-17
  • 打赏
  • 举报
回复
不用这么麻烦吧,假设要Form1始终在前
Form1.show ,Me
rainstormmaster 2005-11-17
  • 打赏
  • 举报
回复
呵呵,楼上的可行,不过没必要调用3次SetWindowPos吧:
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)

Private Sub Form_Activate()
'Set the window position to topmost
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
weiweiplay 2005-11-17
  • 打赏
  • 举报
回复
Declare Function SetWindowPos Lib "user32" ( ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

SetWindowPos me.hWnd,WND_TOPMOST,0,0,0,0, SWP_NOMOVE
SetWindowPos me.hWnd,WND_TOPMOST,0,0,0,0, SWP_NOSIZE
SetWindowPos me.hWnd,WND_TOPMOST,0,0,0,0, HWND_TOPMOST
cometome 2005-11-17
  • 打赏
  • 举报
回复
顶一顶

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧