使窗体的“关闭”按钮无效 需要什么函数?

rodman1982 2003-05-08 09:41:34
我急用 。。。。等候
...全文
53 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
lihonggen0 2003-05-09
'把以下程序复制到窗体中就可以做到

Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Const SC_CLOSE As Long = &HF060


Private Sub Form_Load()
hMenu = GetSystemMenu(Me.hWnd, 0)
DeleteMenu hMenu, SC_CLOSE, 0&
End Sub

回复
to lihonggen0(李洪根,用.NET,标准答案来了)
hwndmenu = getsystemmenu(Me.hwnd, 0)找不了接口,为什么呢??
回复
rodman1982 2003-05-09
pipipig() LoveBH(IT狗狗) 谢谢你们了。。。。。。。。。
回复
lihonggen0 2003-05-09
http://vbboshi.myrice.com/magazine/list_11-20/mag_files/mag(14).htm

这里有好多东西
回复
lihonggen0 2003-05-09
Private Declare Function getsystemmenu Lib "user32" (ByVal hwnd As Long, ByVal brevert 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 Declare Function getmenuitemcount Lib "user32" (ByVal hmenu As Long) As Long
Private Const mf_byposition = &H400&


'使用:

Private Sub form_load()

Dim hwndmenu As Long
Dim c As Long
hwndmenu = getsystemmenu(Me.hwnd, 0)
c = getmenuitemcount(hwndmenu)
deletemenu hwndmenu, c - 1, mf_byposition
c = getmenuitemcount(hwndmenu)
deletemenu hwndmenu, c - 1, mf_byposition
End Sub



回复
LoveBH 2003-05-09
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 Declare Function DrawMenuBar Lib "User32" (ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemCount Lib "User32" (ByVal hMenu As Long) As Long
Private Const MF_BYPOSITION = &H400&

Private Sub Command1_Click()
DisableClose Me
End Sub


Private Sub DisableClose(Frm As Form)
Dim hMenu As Long, nCount As Long
'获取系统菜单的句柄
hMenu = GetSystemMenu(Frm.hwnd, 0)
'得到系统菜单的菜单项目
nCount = GetMenuItemCount(hMenu)
'将关闭按钮置为无效
Call RemoveMenu(hMenu, nCount - 1, MF_BYPOSITION)
'重画系统菜单
DrawMenuBar Frm.hwnd
End Sub

Private Sub Command2_Click()
End
End Sub
回复
xiaoxingchi 2003-05-09
Private Sub Form_Unload(Cancel As Integer)
Cancel = 1
End Sub

-----------------------------------------------------------------------
人在江湖,人不由已!我喜欢程序员这职业!
回复
xubaogongChina 2003-05-08
笨鸟很厉害 但是在菜单中却有了
回复
form1.controlBox=false即可
回复
Rozre 2003-05-08
up
回复
pipipig 2003-05-08
忘了说要方2个按钮在上面 COMMAND1 和2
回复
pipipig 2003-05-08
Option Explicit

Private Const WM_NCACTIVATE = &H86
Private Const SC_CLOSE = &HF060&

Private Const MIIM_STATE = &H1&
Private Const MIIM_ID = &H2&

Private Const MFS_GRAYED = &H3&
Private Const MFS_CHECKED = &H8&

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
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


Const xMenuID = 10&

Private Sub Command1_Click()
Dim hMenu As Long, MII As MENUITEMINFO

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

GetMenuItemInfo hMenu, SC_CLOSE, False, MII

MII.wID = xMenuID
MII.fMask = MIIM_ID
SetMenuItemInfo hMenu, SC_CLOSE, False, MII

MII.fState = MII.fState Or MFS_GRAYED
MII.fMask = MIIM_STATE
SetMenuItemInfo hMenu, MII.wID, False, MII

SendMessage Me.hWnd, WM_NCACTIVATE, True, ByVal 0&
End Sub

Private Sub Command2_Click()
Dim hMenu As Long, MII As MENUITEMINFO

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

GetMenuItemInfo hMenu, xMenuID, False, MII

MII.wID = SC_CLOSE
MII.fMask = MIIM_ID
SetMenuItemInfo hMenu, xMenuID, False, MII

MII.fState = MII.fState And (Not MFS_GRAYED)
MII.fMask = MIIM_STATE
SetMenuItemInfo hMenu, MII.wID, False, MII

SendMessage Me.hWnd, WM_NCACTIVATE, True, ByVal 0&
End Sub

Private Sub Form_Load()
Command1.Caption = "关闭无效"
Command2.Caption = "关闭恢复"
End Sub
回复
LoveBH 2003-05-08
好象是 GetSystemMenu函数
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7517

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-08 09:41
社区公告
暂无公告