见:http://community.csdn.net/Expert/topic/4206/4206368.xml?temp=.2831079移除系统菜单法。
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
Const GWL_STYLE = (-16)
Const WS_SYSMENU = &H80000Private Sub RemoveSysButton(ByVal hHwnd As Long)
'功能:移除窗口系统菜单
'参数:hHwnd - 窗口的句柄
Dim lWnd As Long
lWnd = GetWindowLong(hHwnd, GWL_STYLE)
lWnd = lWnd And Not (WS_SYSMENU)
lWnd = SetWindowLong(hHwnd, GWL_STYLE, lWnd)
End SubPrivate Sub Form_Load()
RemoveSysButton (Me.hwnd)
End Sub这段代码移除另一个软件的右上角关闭按钮时,它把左上角的软件图标也移除了,怎么才能在移除另一个软件的右上角关闭按钮时,保留左上角的图标?谢谢先!
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
Const GWL_STYLE = (-16)
Const WS_SYSMENU = &H80000Private Sub RemoveSysButton(ByVal hHwnd As Long)
'功能:移除窗口系统菜单
'参数:hHwnd - 窗口的句柄
Dim lWnd As Long
lWnd = GetWindowLong(hHwnd, GWL_STYLE)
lWnd = lWnd And Not (WS_SYSMENU)
lWnd = SetWindowLong(hHwnd, GWL_STYLE, lWnd)
End SubPrivate Sub Form_Load()
RemoveSysButton (Me.hwnd)
End Sub这段代码移除另一个软件的右上角关闭按钮时,它把左上角的软件图标也移除了,怎么才能在移除另一个软件的右上角关闭按钮时,保留左上角的图标?谢谢先!
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Const MF_BYPOSITION = &H400&
Const MF_REMOVE = &H1000&
Private Sub Command1_Click()
Unload Me
End SubPrivate Sub Command2_Click()
RemoveSysButton (Me.hwnd)
End SubPrivate Sub RemoveSysButton(ByVal hHwnd As Long)
Dim hSysMenu As Long, nCnt As Long
hSysMenu = GetSystemMenu(hHwnd, False) If hSysMenu Then
nCnt = GetMenuItemCount(hSysMenu)
If nCnt Then
RemoveMenu hSysMenu, nCnt - 1, MF_BYPOSITION Or MF_REMOVE
RemoveMenu hSysMenu, nCnt - 2, MF_BYPOSITION Or MF_REMOVE ' Remove the seperator
RemoveMenu hSysMenu, nCnt - 3, MF_BYPOSITION Or MF_REMOVE
RemoveMenu hSysMenu, nCnt - 4, MF_BYPOSITION Or MF_REMOVE ' Remove the seperator
RemoveMenu hSysMenu, nCnt - 5, MF_BYPOSITION Or MF_REMOVE ' Remove the seperator
RemoveMenu hSysMenu, nCnt - 6, MF_BYPOSITION Or MF_REMOVE ' Remove the seperator
RemoveMenu hSysMenu, nCnt - 7, MF_BYPOSITION Or MF_REMOVE ' Remove the seperator
DrawMenuBar hHwnd
End If
End If
End Sub