4个回答
展开全部
为工程添加代码模块Moudall,在其中放置如下声明代码:
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 Flag=SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_TOPMOST=-1 '窗体总在最前面
Public Const HWND_NOTOPMOST=-2 '窗体不在最前面
为窗体添加代码如下:
Private Sub Command1_Click()
Form1.Caption = "现在是普通窗口"
SetWindowPos Form1.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, Flag
End Sub
Private Sub Command2_Click()
Form1.Caption = "现在是TopMost窗口"
SetWindowPos Form1.hwnd, HWND_TOPMOST, 0, 0, 0, 0, Flag
End Sub
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 Flag=SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_TOPMOST=-1 '窗体总在最前面
Public Const HWND_NOTOPMOST=-2 '窗体不在最前面
为窗体添加代码如下:
Private Sub Command1_Click()
Form1.Caption = "现在是普通窗口"
SetWindowPos Form1.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, Flag
End Sub
Private Sub Command2_Click()
Form1.Caption = "现在是TopMost窗口"
SetWindowPos Form1.hwnd, HWND_TOPMOST, 0, 0, 0, 0, Flag
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
'以上为API函数声明
Public Const HWND_TOPMOST = -1
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_FRAMECHANGED = &H20
'The frame changed: send WM_NCCALCSIZE
Public Const SWP_DRAWFRAME = SWP_FRAMECHANGED
'以上为程序中用到的常量
Public Const HWND_BOTTOM = 1
Public Const HWND_BROADCAST = &HFFFF&
Public Const HWND_DESKTOP = 0
Public Const HWND_NOTOPMOST = -2
Public Const HWND_TOP = 0
Public Const SWP_HIDEWINDOW = &H80
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_NOCOPYBITS = &H100
Public Const SWP_NOOWNERZORDER = &H200
'Don't do owner Z ordering
Public Const SWP_NOREDRAW = &H8
Public Const SWP_NOREPOSITION = SWP_NOOWNERZORDER
Public Const SWP_NOZORDER = &H4
Public Const SWP_SHOWWINDOW = &H40
'以上常量声明在程序中没有使用
'可以试着在调用SetWindowPos函数时使用这些常量或它们的组合
'得到其他效果
Public Const Flags = SWP_DRAWFRAME Or SWP_NOMOVE Or SWP_NOSIZE
然后再按钮中加入代码
' 使用Windows API函数SetWindowPos将窗口设置为总在最前面
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW
'悬挂式窗口
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
'以上为API函数声明
Public Const HWND_TOPMOST = -1
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_FRAMECHANGED = &H20
'The frame changed: send WM_NCCALCSIZE
Public Const SWP_DRAWFRAME = SWP_FRAMECHANGED
'以上为程序中用到的常量
Public Const HWND_BOTTOM = 1
Public Const HWND_BROADCAST = &HFFFF&
Public Const HWND_DESKTOP = 0
Public Const HWND_NOTOPMOST = -2
Public Const HWND_TOP = 0
Public Const SWP_HIDEWINDOW = &H80
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_NOCOPYBITS = &H100
Public Const SWP_NOOWNERZORDER = &H200
'Don't do owner Z ordering
Public Const SWP_NOREDRAW = &H8
Public Const SWP_NOREPOSITION = SWP_NOOWNERZORDER
Public Const SWP_NOZORDER = &H4
Public Const SWP_SHOWWINDOW = &H40
'以上常量声明在程序中没有使用
'可以试着在调用SetWindowPos函数时使用这些常量或它们的组合
'得到其他效果
Public Const Flags = SWP_DRAWFRAME Or SWP_NOMOVE Or SWP_NOSIZE
然后再按钮中加入代码
' 使用Windows API函数SetWindowPos将窗口设置为总在最前面
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
右上角的工程资源管理器中,在工程名上(如工程1)右键——工程序属性;通用项中设置:工程类型为标准exe,启动对象下拉菜单中选中你要的窗体就行了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'使用SetWindowPos函数可以设置窗体的大小、位置和显示顺序
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 '1
'保持窗体当前位置
Const SWP_NOMOVE = &H2 '2
'窗体显示顺序常量
Const HWND_TOPMOST = -1
'设置当前窗体显示在最前面
'取消设置
Const HWND_NOTOPMOST = -2
Dim OnTop As Boolean
Private Sub Command1_Click()
OnTop = Not OnTop
If OnTop Then
Command1.Caption = "取消显示在最前面"
'当前窗体显示在最前面
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
Else
'取消显示模式
Command1.Caption = "显示在最前面"
SetWindowPos Me.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
End If
End Sub
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 '1
'保持窗体当前位置
Const SWP_NOMOVE = &H2 '2
'窗体显示顺序常量
Const HWND_TOPMOST = -1
'设置当前窗体显示在最前面
'取消设置
Const HWND_NOTOPMOST = -2
Dim OnTop As Boolean
Private Sub Command1_Click()
OnTop = Not OnTop
If OnTop Then
Command1.Caption = "取消显示在最前面"
'当前窗体显示在最前面
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
Else
'取消显示模式
Command1.Caption = "显示在最前面"
SetWindowPos Me.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询