主题:如何使窗体右上角的关闭按钮失效
zhang5382
[专家分:170] 发布于 2010-12-21 20:32:00
看到一些程序,窗体右上角的关闭按钮不能使用,只有点关闭按钮才能退出,这样处理有它的好处,不知如何使右上角的关闭按钮失去作用,要改哪个控件的哪个属性?
另一个问题:如何使一些控件成为透明的?
回复列表 (共3个回复)
沙发
一江秋水 [专家分:9680] 发布于 2010-12-22 14:17:00
取消关闭按纽只能用API函数:
Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Const SC_CLOSE = &HF060&
Private Const MF_BYCOMMAND = &H0&
Private Const MF_GRAYED = &H1&
Private Sub Form_Load()
EnableMenuItem GetSystemMenu(hwnd, False), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED
End Sub
板凳
zhang5382 [专家分:170] 发布于 2010-12-22 19:25:00
计算机这玩意是越学不懂的东西越多。
3 楼
天天学习 [专家分:4570] 发布于 2010-12-23 16:17:00
在任务栏图标上或者程序的标题栏上一点鼠标右键,关闭按钮又可以用了
'禁止关闭按钮的API声明:
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Const MF_BYPOSITION = &H400&
Private Sub DisableClose(ByVal hwnd As Long, Optional ByVal MDIChild As Boolean)
'禁止关闭按钮
Dim hSysMenu As Long
Dim nCnt As Long
Dim cID As Long
hSysMenu = GetSystemMenu(hwnd, False)
If hSysMenu = 0 Then Exit Sub
nCnt = GetMenuItemCount(hSysMenu)
If MDIChild Then
cID = 3
Else
cID = 1
End If
If nCnt Then
'RemoveMenu hSysMenu, nCnt - cID, MF_BYPOSITION Or MF_REMOVE
'RemoveMenu hSysMenu, nCnt - cID - 1, MF_BYPOSITION Or MF_REMOVE
DeleteMenu hSysMenu, nCnt - cID, MF_BYPOSITION
DeleteMenu hSysMenu, nCnt - cID - 1, MF_BYPOSITION
End If
End Sub
不过,按Alt + F4还是可以关闭,需要在queryUnload中再进行处理
我来回复