Solved

No x code

Posted on 1998-08-11
4
173 Views
Last Modified: 2010-05-18
Can anyone tell me the VB5 code the will no remove or disable the close (x) button on the top left of any window.
The thing is I want to do this without removeing or disabling the minimize button.

So I need the minimize button, but want rid of the close button.

Peat, Thanks.
0
Comment
Question by:peat042998
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 9

Accepted Solution

by:
cymbolic earned 40 total points
ID: 1468540
following code is from VBNet:
Add the following code to a BAS module:
------------------------------------------------------------------------



Option Explicit

Public Const MF_BYPOSITION = &H400
Public Const MF_REMOVE = &H1000

Public Declare Function DrawMenuBar Lib "user32" _
      (ByVal hwnd As Long) As Long
     
Public Declare Function GetMenuItemCount Lib "user32" _
      (ByVal hMenu As Long) As Long
     
Public Declare Function GetSystemMenu Lib "user32" _
      (ByVal hwnd As Long, _
       ByVal bRevert As Long) As Long
       
Public Declare Function RemoveMenu Lib "user32" _
      (ByVal hMenu As Long, _
       ByVal nPosition As Long, _
       ByVal wFlags As Long) As Long'--end block--'
   


 Form Code  
To test, add the following into a command button. Shown here is the code called from the form's Load sub:
------------------------------------------------------------------------



Option Explicit

Private Sub Form_Load()

   Dim hMenu As Long
   Dim menuItemCount As Long

  'Obtain the handle to the form's system menu
   hMenu = GetSystemMenu(Me.hwnd, 0)
 
   If hMenu Then
     
     'Obtain the number of items in the menu
      menuItemCount = GetMenuItemCount(hMenu)
   
     'Remove the system menu Close menu item.
     'The menu item is 0-based, so the last
     'item on the menu is menuItemCount - 1
      Call RemoveMenu(hMenu, menuItemCount - 1, _
                      MF_REMOVE Or MF_BYPOSITION)
   
     'Remove the system menu separator line
      Call RemoveMenu(hMenu, menuItemCount - 2, _
                      MF_REMOVE Or MF_BYPOSITION)
   
     'Force a redraw of the menu. This
     'refreshes the titlebar, dimming the X
      Call DrawMenuBar(Me.hwnd)

   End If
   
End Sub


'--end block--'
   
0
 
LVL 18

Expert Comment

by:deighton
ID: 1468541
Below is code to disable unload using the x.  You can still unload using an exit key if you set bExit = true before unload me.  This works if the window is a VB form.


(declarations)


Dim bExit As Boolean


Private Sub Form_Unload(Cancel As Integer)

    If bExit = False Then
        Cancel = True
    End If
       
End Sub

Private Sub Command1_Click()
    bExit = True
    Unload Me
End Sub




0
 

Author Comment

by:peat042998
ID: 1468542
Thanks, that was bril!!!
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1468543
Bought This Question.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

742 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question