您的批评和鼓励都是我把编程无限办好的动力! 您编程时遇到困难,或遇到不顺心的事想发发牢骚尽管到这里来吧! 虽然本网力求全面,但也不能包罗万象,这些我筛选出的优秀网站连接就是对本站最好的补充! 学习编程当然也离不开书本了,这里收集大量编程书籍! 编程无限之源码超市,这里收集的代码令你意想不到的全面! 欢迎光临编程网校,这里专门收集VB/CB入门文章及技术文章! 欢迎光临编程无限!
     
       
 
当前位置:英文资料 >> Interface
Disable Enable the Close (X) button in the titlebar of a window.
  资料类型: Interface 上传时间: 2001-02-21 阅读次数: 2310



This tip shows how to disable/enable the Close (X) Button in the titlebar of a window. The way that this is possible is by removing the "Close" item out of the System Menu for the window. For looks, the seperator before the "Close" item is also removed.

Add two command buttons (Command1 and Command2) to a form and add the following code...

Option Explicit

Private Const MF_BYPOSITION& = &H400&
Private Declare Function GetSystemMenu& Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long)
Private Declare Function RemoveMenu& Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long)
Private Declare Function GetMenuItemCount& Lib "user32" (ByVal hMenu As Long)

Private Sub Command1_Click()
Dim lHwnd As Long
Dim lSysMenu As Long
Dim lItemCount As Long
lHwnd = Me.hwnd
lSysMenu = GetSystemMenu(lHwnd, False)
lItemCount = GetMenuItemCount(lSysMenu)
RemoveMenu lSysMenu, lItemCount - 1, MF_BYPOSITION
RemoveMenu lSysMenu, lItemCount - 2, MF_BYPOSITION
End Sub

Private Sub Command2_Click()
Dim lHwnd As Long
Dim lSysMenu As Long
lHwnd = Me.hwnd
lSysMenu = GetSystemMenu(lHwnd, True)
End Sub

Command1 will disable the Close button and Command2 will enable it again.

Note: This code takes for granted that in the System Menu for the window that the "Close" item is the last item in the menu. You might need to adjust the "-1" or "-2" in the RemoveMenu functions to remove the correct menu items.

推荐给朋友 点 评( 0 ) 返回前页 关闭此页
   
  本类最热文章排名:
  1.Minimize All Windows to Show Desktop
2.Setting Video Resolu...
3.Create An Active Skin
4.Make MDI Child Forms Act Modal
5.clear all text in the form
6.Passing A Variable To A Form
7.Creates A form contr...
8.Gradient Color Trans...
9.Tile A Bitmap Accross A Form
10.Labeling your forms
   
   
  评论:
 
 
 

 

关于本站 版权声明 联系方法
编程无限 V4.1 Copyright © 1999-2008 21code.com

京ICP备05006938号