vb 中borderstyle设置为0 怎么让窗体最前端啊?且能随意移动窗体啊?
展开全部
'虽然我自己的问题还没有人回答,解决不了问题,下面的事就没有办法开展...
'在模块中声明以下函数
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 a& = -1
Public Const b& = &H1
Public Const c& = &H2
Public Const HTCAPTION = 2
Public Const WM_NCLBUTTONDOWN = &HA1
Public Declare Function ReleaseCapture Lib "user32" () As Long '!!!!!!!!
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then '移动
Dim ReturnVal As Long
X = ReleaseCapture()
ReturnVal = SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If
End Sub
Private Sub Form_Load()
SetWindowPos Me.hwnd, a, 0, 0, 0, 0, b Or c '置顶
End Sub
'在模块中声明以下函数
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 a& = -1
Public Const b& = &H1
Public Const c& = &H2
Public Const HTCAPTION = 2
Public Const WM_NCLBUTTONDOWN = &HA1
Public Declare Function ReleaseCapture Lib "user32" () As Long '!!!!!!!!
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then '移动
Dim ReturnVal As Long
X = ReleaseCapture()
ReturnVal = SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If
End Sub
Private Sub Form_Load()
SetWindowPos Me.hwnd, a, 0, 0, 0, 0, b Or c '置顶
End Sub
展开全部
要移动窗体就要在窗体的鼠标事件里调用函数来控制窗体。
至于最前端?都要用API函数才能搞定。
至于最前端?都要用API函数才能搞定。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'看来阁下是想做一个恶搞的程序吧,做个窗体让它永远最前端,而且能移动。我给它再增加一个功能吧,让它透明。
'1.这段时随意移动
Private Sub Timer1_Timer()
Dim X As Integer
Dim Y As Integer
X = Int(Rnd * 10000) + 1
Y = Int(Rnd * 10000) + 1
Form1.Left = X
Form1.Top = Y
End Sub
'2.这段是窗体最前端
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 '(API函数)
Private Sub Form_Resize()
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3
End Sub
'1.这段时随意移动
Private Sub Timer1_Timer()
Dim X As Integer
Dim Y As Integer
X = Int(Rnd * 10000) + 1
Y = Int(Rnd * 10000) + 1
Form1.Left = X
Form1.Top = Y
End Sub
'2.这段是窗体最前端
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 '(API函数)
Private Sub Form_Resize()
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'在bas加入:
Declare Function ReleaseCapture Lib "user32" () As Long
Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" ( _
ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Public Const HTCAPTION = 2
Public Const WM_NCLBUTTONDOWN = &HA1
'''''
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub
Declare Function ReleaseCapture Lib "user32" () As Long
Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" ( _
ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Public Const HTCAPTION = 2
Public Const WM_NCLBUTTONDOWN = &HA1
'''''
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询