关于VB窗体的问题

请问哪位高手知道在VB编程中如何的关去掉窗体上掉的窗体的那个差,就是说让窗体不能关掉。谢谢... 请问哪位高手知道在VB编程中如何的关去掉窗体上掉的窗体的那个差,就是说让窗体不能关掉。谢谢 展开
 我来答
二白Q0
2007-07-22 · TA获得超过2413个赞
知道大有可为答主
回答量:990
采纳率:0%
帮助的人:1088万
展开全部
1)把controlBox设置为False,可以使最大化、最小化、关闭按钮不可见。
2)如果想使关闭按钮失效,而不影响最大化、最小化,可以使用下列代码:

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = 0 Then
Cancel = True
End If
End Sub

这时,最好在窗体上添加一个关闭按钮(不然只能通过结束进程来关闭窗体了),在按钮代码中加上:
Private Sub Command1_Click()
Unload Me
End Sub
由于这种方式在关闭窗体时,QueryUnload事件中的UnloadMode参数会是1,所以不会被屏蔽。

3)如果要使关闭按钮失效或不可见,而不影响最大最小化的话,就只好用API了,抄来一段代码修改一下:
Option Explicit

'Menu item constants.
Private Const SC_CLOSE As Long = &HF060&

'SetMenuItemInfo fMask constants.
Private Const MIIM_STATE As Long = &H1&
Private Const MIIM_ID As Long = &H2&

'SetMenuItemInfo fState constants.
Private Const MFS_GRAYED As Long = &H3&
Private Const MFS_CHECKED As Long = &H8&

'SendMessage constants.
Private Const WM_NCACTIVATE As Long = &H86

'User-defined Types.
Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type

'Declarations.
Private Declare Function GetSystemMenu Lib "user32" ( _
ByVal hwnd As Long, ByVal bRevert As Long) As Long

Private Declare Function GetMenuItemInfo Lib "user32" Alias _
"GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
ByVal b As Boolean, lpMenuItemInfo As MENUITEMINFO) As Long

Private Declare Function SetMenuItemInfo Lib "user32" Alias _
"SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long

' Private Declare Function SendMessage Lib "user32" Alias _
' "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
' ByVal wParam As Long, lParam As Any) As Long

'Application-specific constants and variables.
Private Const xSC_CLOSE As Long = -10
Private Const SwapID As Long = 1
Private Const ResetID As Long = 2

Private hMenu As Long
Private MII As MENUITEMINFO

Private Function SetId(Action As Long) As Long
Dim MenuID As Long
Dim Ret As Long

MenuID = MII.wID
If MII.fState = (MII.fState Or MFS_GRAYED) Then
If Action = SwapID Then
MII.wID = SC_CLOSE
Else
MII.wID = xSC_CLOSE
End If
Else
If Action = SwapID Then
MII.wID = xSC_CLOSE
Else
MII.wID = SC_CLOSE
End If
End If

MII.fMask = MIIM_ID
Ret = SetMenuItemInfo(hMenu, MenuID, False, MII)
If Ret = 0 Then
MII.wID = MenuID
End If
SetId = Ret
End Function

Private Sub Form_Load()
Dim Ret As Long

hMenu = GetSystemMenu(Me.hwnd, 0)
MII.cbSize = Len(MII)
MII.dwTypeData = String(80, 0)
MII.cch = Len(MII.dwTypeData)
MII.fMask = MIIM_STATE
MII.wID = SC_CLOSE
MII.fState = (MII.fState Or MFS_GRAYED)
MII.fMask = MIIM_STATE
Ret = SetMenuItemInfo(hMenu, MII.wID, False, MII)

End Sub

Private Sub Command1_Click()
Unload Me
End Sub

参考资料: http://support.microsoft.com/kb/q184686/

昨岁葱嘻脚1452
2007-07-23
知道答主
回答量:70
采纳率:0%
帮助的人:0
展开全部
在窗体属性里改:
方法一:将controlBox 属性设为False
方法二:将 BorderStyle 属性设为0-none,即无窗口边框,这时,你可以自己画边框(通过其picture属性设置进去),并在右上角放一个按钮,设置
caption="X";
定义其功能
Private Sub Command1_Click()

if .... then
end
else ...

End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zheng0823
2007-07-21 · TA获得超过975个赞
知道小有建树答主
回答量:1117
采纳率:0%
帮助的人:992万
展开全部
Form属性中有个controlBox属性,将他设置为FALSE就可以了!!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zhang7831305
2007-07-23 · 超过11用户采纳过TA的回答
知道答主
回答量:105
采纳率:0%
帮助的人:0
展开全部
哪要那么麻烦
下面的代码就可以搞定:
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long

Private Sub Form_Load()
RemoveMenu GetSystemMenu(Me.hwnd, 0), &HF060, &H1000&
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式