VB 用SendMessage向指定窗口发送消息,发送哪个消息可以改变窗体的类型?
有的程序无标题栏,用这个API怎么把程序加上标题栏?大概的说一下就可以了,不用贴完整代码。谢谢各位高手了。...
有的程序无标题栏,用这个API怎么把程序加上标题栏?
大概的说一下就可以了,不用贴完整代码。
谢谢各位高手了。 展开
大概的说一下就可以了,不用贴完整代码。
谢谢各位高手了。 展开
展开全部
'这个程序运行的效果是,单击一下窗体,变成无标题栏,再次单击,又变有标题栏。
'刚才试验过,把Me.Hwnd改成windows计算器的句柄,就可以随意改变计算器的窗体类型
'设置窗体结构信息函数
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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_SYSMENU = &H80000
Private Const WS_CAPTION = &HC00000
Private Const WS_SIZEBOX = &H40000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
'为窗体指定一个新位置和状态函数
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 SWP_NOZORDER = &H4
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOREPOSITION = &H200
'获得整个窗体的大小和位置
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Change As Boolean
Private Sub Form_Click()
Dim lStyle As Long
Dim MyRect As RECT
'获取窗体的大小和位置
GetWindowRect Me.hwnd, MyRect
'取得当前窗体信息
lStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
If Change Then
'分别使系统菜单(包括图标)、标题、大小、最大化、最小化显示/有效
lStyle = lStyle Or WS_SYSMENU
lStyle = lStyle Or WS_CAPTION
lStyle = lStyle Or WS_SIZEBOX
lStyle = lStyle Or WS_MAXIMIZEBOX
lStyle = lStyle Or WS_MINIMIZEBOX
Else
'分别使系统菜单(包括图标)、标题、大小、最大化、最小化隐藏/无效
lStyle = lStyle And Not WS_SYSMENU
lStyle = lStyle And Not WS_CAPTION
lStyle = lStyle And Not WS_SIZEBOX
lStyle = lStyle And Not WS_MAXIMIZEBOX
lStyle = lStyle And Not WS_MINIMIZEBOX
End If
'按lStyle的值设置窗体信息
SetWindowLong Me.hwnd, GWL_STYLE, lStyle
'保持窗体的大小与位置不变
SetWindowPos Me.hwnd, 0, MyRect.Left, MyRect.Top, MyRect.Right - MyRect.Left, MyRect.Bottom - MyRect.Top, SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED
'改变显示/隐藏状态
Change = Not Change
End Sub
'刚才试验过,把Me.Hwnd改成windows计算器的句柄,就可以随意改变计算器的窗体类型
'设置窗体结构信息函数
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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_SYSMENU = &H80000
Private Const WS_CAPTION = &HC00000
Private Const WS_SIZEBOX = &H40000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
'为窗体指定一个新位置和状态函数
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 SWP_NOZORDER = &H4
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOREPOSITION = &H200
'获得整个窗体的大小和位置
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Change As Boolean
Private Sub Form_Click()
Dim lStyle As Long
Dim MyRect As RECT
'获取窗体的大小和位置
GetWindowRect Me.hwnd, MyRect
'取得当前窗体信息
lStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
If Change Then
'分别使系统菜单(包括图标)、标题、大小、最大化、最小化显示/有效
lStyle = lStyle Or WS_SYSMENU
lStyle = lStyle Or WS_CAPTION
lStyle = lStyle Or WS_SIZEBOX
lStyle = lStyle Or WS_MAXIMIZEBOX
lStyle = lStyle Or WS_MINIMIZEBOX
Else
'分别使系统菜单(包括图标)、标题、大小、最大化、最小化隐藏/无效
lStyle = lStyle And Not WS_SYSMENU
lStyle = lStyle And Not WS_CAPTION
lStyle = lStyle And Not WS_SIZEBOX
lStyle = lStyle And Not WS_MAXIMIZEBOX
lStyle = lStyle And Not WS_MINIMIZEBOX
End If
'按lStyle的值设置窗体信息
SetWindowLong Me.hwnd, GWL_STYLE, lStyle
'保持窗体的大小与位置不变
SetWindowPos Me.hwnd, 0, MyRect.Left, MyRect.Top, MyRect.Right - MyRect.Left, MyRect.Bottom - MyRect.Top, SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED
'改变显示/隐藏状态
Change = Not Change
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询