怎样让一窗口位于所有窗口之上

ltolll 2001-08-03 12:54:48

想做一程序中的某一窗体始终位于其它(不论本程序或程序之外的)窗体之上(就像网络蚂蚁的小窗口),该怎么做呢?
...全文
117 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
gameboy999 2001-08-07
  • 打赏
  • 举报
回复
to All:
人家题目中说:想做一程序中的某一窗体始终位于其它(不论本程序或程序之外的)窗体之上
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
说明他想使某个子窗体位于主窗体和所有其他程序窗体之上,但诸位给的代码都只能实现使某个程序的主窗体位于所以其他程序窗体之上。 也就是说只对主窗体有效。不信大家试试。

to mickeypeng(鹏) :

想实现子窗体也topmost的话,
可能先得用SetParent将其父窗体设为NULL才行。
wintenko 2001-08-04
  • 打赏
  • 举报
回复
来晚了
xxlroad 2001-08-04
  • 打赏
  • 举报
回复
Private 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 Sub Form_Load()
SetWindowPos Me.hwnd, -1, 0, 0, Screen.Width, Screen.Height, 0
End Sub
xxlroad 2001-08-04
  • 打赏
  • 举报
回复
'Form1.frm

Private Sub Form_Load()
'永远在最顶层
Call PutWindowOnTop(Me)
End Sub

'asd.bas

Option Explicit

Private 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
Const HWND_TOPMOST = -1
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1


Public Sub PutWindowOnTop(pFrm As Form) '永远在最顶层
Dim lngWindowPosition As Long
'函数成功则返回值为非零,失败则返回0
'可以调用GetLastError函数获得更多的错误信息
lngWindowPosition = SetWindowPos(pFrm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Sub
xxlroad 2001-08-04
  • 打赏
  • 举报
回复

Private 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

Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_SHOWWINDOW = &H40


Private Sub Command1_Click()
'使 窗 口 Always On Top用
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub

Private Sub Command2_Click()

'使 窗 口 取 消 Always On Top功 能 , 用
SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub


Private Sub Form_Load()
'使 窗 口 Always On Top用
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE

End Sub
xyjdn 2001-08-04
  • 打赏
  • 举报
回复
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, &H1 Or &H2 '使窗体位于最顶端
step 2001-08-03
  • 打赏
  • 举报
回复
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 Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const WM_GETMINMAXINFO = &H24

Private Sub SetWindowOnTop(frmIn As Form)
SetWindowPos frmIn.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Sub

Private Sub Form_Activate()
SetWindowOnTop Me
End Sub
leskey 2001-08-03
  • 打赏
  • 举报
回复
怎么还不给分
leskey 2001-08-03
  • 打赏
  • 举报
回复
Public 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
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_SHOWWINDOW = &H40
Public Const SWP_NOACTIVATE = &H10
Public Const HWND_NOTOPMOST = -2
Public Const HWND_TOPMOST = -1

Public Sub FormOnTop(Handle As Long, OnTop As Boolean)
Dim wFlags As Long, PosFlag As Long
wFlags = SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW Or SWP_NOACTIVATE
Select Case OnTop
Case True
PosFlag = HWND_TOPMOST
Case flae
PosFlag = HWND_NOTOPMOST
End Select
SetWindowPos Handle, PosFlag, 0, 0, 0, 0, wFlags
End Sub

'将Form1设置为最上层窗体
FormOnTop Form1.hwnd, True

'取消Form1为最上层窗体
FormOnTop Form1.hwnd, Flase
mickeypeng 2001-08-03
  • 打赏
  • 举报
回复
我试过,是不行啊,没有那种效果啊!
gameboy999 2001-08-03
  • 打赏
  • 举报
回复
这段代码并不是什么时候都有效,前提是frmIn的父窗体为NULL,也就是该窗体为程序主窗体。

不然,则只能达到这种效果——————某个子窗体永远在该程序的所以子窗体之上。

7,763

社区成员

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

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