vb.net中窗口至顶 vb如何让窗口置顶
VB 让窗口强行置顶
Option
创新互联"三网合一"的企业建站思路。企业可建设拥有电脑版、微信版、手机版的企业网站。实现跨屏营销,产品发布一步更新,电脑网络+移动网络一网打尽,满足企业的营销需求!创新互联具备承接各种类型的网站设计、成都网站制作项目的能力。经过10多年的努力的开拓,为不同行业的企事业单位提供了优质的服务,并获得了客户的一致好评。
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
Private
Const
HWND_TOPMOST
=
-1
'
将窗口置于列表顶部,并位于任何最顶部窗口的前面
Private
Const
SWP_NOSIZE
=
H1
'
保持窗口大小
Private
Const
SWP_NOMOVE
=
H2
'
保持窗口位置
Private
Sub
Form_Load()
SetWindowPos
Me.hwnd,
HWND_TOPMOST,
0,
0,
0,
0,
SWP_NOMOVE
Or
SWP_NOSIZE
'
将窗口设为总在最前
End
Sub
'其实和楼上的一样,
不过这个置顶的是
加载的窗口,
你要置顶哪窗口就把代码放哪个里边
,另外MSGBOX
的置顶是4096
系统强制返回;全部应用程序都被挂起,直到用户对消息框作出响应才继续工作。
VB 窗口置顶
你说的是保持在最前面吧!你再说明白点!
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)
Private Sub Form_Load()
Call SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)
'其它代码
End Sub
将下面的代码复制到记事本中,并将其保持为Form1.frm
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 0 'None
ClientHeight = 4695
ClientLeft = 0
ClientTop = 0
ClientWidth = 6975
LinkTopic = "Form1"
ScaleHeight = 4695
ScaleWidth = 6975
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.Shape Shape3
BackColor = H000080FF
BackStyle = 1 'Opaque
BorderStyle = 0 'Transparent
Height = 855
Left = 3480
Shape = 3 'Circle
Top = 960
Width = 975
End
Begin VB.Shape Shape2
BackColor = H000080FF
BackStyle = 1 'Opaque
BorderStyle = 0 'Transparent
Height = 855
Left = 1560
Shape = 3 'Circle
Top = 960
Width = 975
End
Begin VB.Shape Shape1
BackColor = H000080FF
BackStyle = 1 'Opaque
BorderStyle = 0 'Transparent
Height = 1095
Left = 1920
Shape = 2 'Oval
Top = 1320
Width = 2055
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
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)
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Dim mouse_x As Single
Dim mouse_y As Single
Private Sub Form_Load()
Call SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)
Me.BackColor = HFF0000
Dim rtn As Long
BorderStyler = 0
rtn = GetWindowLong(hwnd, -20)
rtn = rtn Or H80000
SetWindowLong hwnd, -20, rtn
SetLayeredWindowAttributes hwnd, HFF0000, 0, H1
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
mouse_x = 0
mouse_y = 0
If Button = 1 Then
mouse_x = X
mouse_y = Y
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Form1.Left = Form1.Left + (X - mouse_x)
Form1.Top = Form1.Top + (Y - mouse_y)
End If
End Sub
VB中如何让窗口置顶
新建立类模块:
Option Explicit
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)
窗口代码:
Dim rtn
'让窗口在顶层
rtn = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)
'取消窗口在顶层
'rtn = SetWindowPos(F_V.hwnd, -2, 0, 0, 0, 0, 3)
请问在VB中怎样使一个窗体运行时始终保持在最前?
这个简单啊,引用API函数SetWindowPos就可以解决。下面看看我的代码:
Private Declare Function SetWindowPos Lib "user32.dll" (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_NOMOVE = H2
Const SWP_NOSIZE = H1
Const FLAG = SWP_NOMOVE Or SWP_NOSIZE
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const HWND_TOP = 0
Const HWND_BOTTOM = 1
将窗口设置最前:Call SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAG)
取消窗口的最前:Call SetWindowPos(Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAG)
函数的第一个参数是根据实际情况改变的,它要求你给它传送一个窗口的句柄,这里的 Me.hwnd 就给函数传送了当前窗口的句柄,也就是将当前窗口前置或取消前置。如果要前置其他窗口,那么请向函数传送其他窗口的句柄,这个可以根据:FindWindow API函数获取。希望采纳意见,谢谢。。。
新闻标题:vb.net中窗口至顶 vb如何让窗口置顶
分享路径:http://ybzwz.com/article/dddooeo.html