说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

VB如何使窗体右上角的"X"无效?

HTML文档下载 WORD文档下载 PDF文档下载
VB如何使窗体右上角的"X"无效?

要Disable Form "X" -->Close的功能(便暗灰色),事实上便是从Form左上方的SystemMenu将关闭的MenuItem去除掉便可以了,去除后,又该如何,那便是在将关闭(Close)的MenuItem加回去 但这里有个小问题,加回去之后"X"仍是暗灰色,要等到我们做了某些固定的动作之后(如TittleBar上Click一下,或选一下SystemMenu等), 我不知道让TittleBar上的这些东西Refresh要送什么消息,所以现在我暂且Send一个在TittleBar上按下Mouse左键的消息给窗体,令"X"能出现的Enable颜色
在窗体上放置一个Command Button,输入以下代码,运行,点击一下Command Button 就可使"X" Enable.
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 AppendMenu Lib "User32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function GetMenuString Lib "User32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) 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 WM_NCLBUTTONDBLCLK = &HA3
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2
Const MF_STRING = &H0&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060
Private hMenu As Long
Private CloseStr As String '纪录Close MenuItem的字符串
Private Sub Command1_Click()
'将"关闭"的那个MenuItem重新加入
Call AppendMenu(hMenu, MF_STRING, SC_CLOSE, CloseStr)
'令"X"出现Enable的颜色
Call SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End Sub
Private Sub Form_Load()
hMenu = GetSystemMenu(Me.hwnd, 0)
CloseStr = String(255, 0)
'SC_CLOSE即是"关闭"的MenuItem ID
Call GetMenuString(hMenu, SC_CLOSE, CloseStr, 256, MF_BYCOMMAND)
CloseStr = Left(CloseStr, InStr(1, CloseStr, Chr(0)) - 1)
Call DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
End Sub
处理 Dropdown List型 Combo的录入问题-VB资料 VB创建和删除快捷方式 从程序中生成 exe 文件 -VB资料 打开和关闭CD-ROM 驱动器 -VB资料 打开和关闭其他应用 -VB资料 新手学VB(insert into)怎么用? 怎样反编译ocx 设置纸张的大小 请问如何向内存写值 在线求救!!!有谁知道济南的能查高程分了吗?? 哪有linux源码的详解? 我创建了一个TfrReport控件,想把他的OnGetValue事件指定为其他控件已有的事件,比如另一个TfrReport的ongetvalue事件,该怎么写代码呢? 关于SQL语句,怎样过滤重复资料? QQ上593796这个群,是程序员联盟,,都是高手快加 what would you like for _ -IS jack in the library? ( )1.____weekends young p People often go to the pa What would you like —____ 英语翻译1. The prices of I've never heard ____ int i have never heard many s lost track of time怎么翻译? “我想象中的中国游”秘鲁少儿绘画比赛第九届北京—东京论坛在北京开幕福岛近海发生7.1级地震 最大观察到德国高层代表团将赴美 跟进默克尔被窃浙江监测教育质量评价 5万余名学生“10人希腊顽强逼平日本“星城”长沙的来历认真负责管好该管的事以改革发展成果检验活动实效远近随心一线牵无上寻仙道神级恶搞龙卷恶人从慕容复开始器道成仙陆家嘴中心绿地旅游草场地旅游石碣旅游敢壮山布洛陀旅游区旅游百色起义纪念碑旅游
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘