Results 1 to 11 of 11

Thread: Take the [X] off of the top

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    35

    Unhappy

    How to I make a form, where it shows the Form's Caption and Includes a Icon, but doesnt have the X to close out the program at the top? Thanx
    "..Follow the white rabbit.."

  2. #2
    Guest
    Here's how to disable the X button, so you can have a caption and icon on the form.

    Code:
    Declare Function GetSystemMenu Lib "user32" _
    (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    
    Declare Function GetMenuItemCount Lib "user32" _
    (ByVal hMenu As Long) As Long
    
    Declare Function DrawMenuBar Lib "user32" _
    (ByVal hwnd As Long) As Long
    
    Declare Function RemoveMenu Lib "user32" _
    (ByVal hMenu As Long, ByVal nPosition As Long, _
    ByVal wFlags As Long) As Long
    Public Const MF_BYPOSITION = &H400&
    Public Const MF_REMOVE = &H1000&
    
    Private Sub Form_Load()
    Dim hSysMenu As Long
    Dim nCnt As Long
    
    ' First, show the form
    Me.Show
    
    ' Get handle to our form's system menu 
    ' (Restore, Maximize, Move, close etc.)
    hSysMenu = GetSystemMenu(Me.hwnd, False)
    
    If hSysMenu Then
    ' Get System menu's menu count
    nCnt = GetMenuItemCount(hSysMenu)
    
    If nCnt Then
    
    ' Menu count is based on 0 (0, 1, 2, 3...)
    
    RemoveMenu hSysMenu, nCnt - 1, _
    MF_BYPOSITION Or MF_REMOVE
    
    RemoveMenu hSysMenu, nCnt - 2, _
    MF_BYPOSITION Or MF_REMOVE ' Remove the seperator
    
    DrawMenuBar Me.hwnd 
    ' Force caption bar's refresh. Disabling X button
    
    Me.Caption = "Try to close me!"
    End If
    End If
    End Sub

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    go to the form properties box and set the 'controlbox' option to false.

  4. #4
    Guest
    crptcblade, that will make the X button not visible, but the program's icon will not show.

  5. #5
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    sorry, i missed that part of the original thread 8-)

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    35

    Smile

    Cool thanx, both ways will work fine for me. I really only wanted the [X] gone but it will work without the icon showing as well. Thanks alot
    "..Follow the white rabbit.."

  7. #7
    Guest
    Short and Simple.
    Code:
    Private Declare Function GetSystemMenu Lib "User32" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
    Private Declare Function RemoveMenu Lib "User32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
    Const MF_BYPOSITION = &H400
    
    Private Sub Form_Load()
        Call RemoveMenu(GetSystemMenu(hWnd, 0), 6, MF_BYPOSITION)
    End Sub

  8. #8
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    Megatron:

    Are you saying that your example code will remove the close
    (X) button or that you need to still disable the control box
    and your code will allow the icon to stay?

    Never mind, just tried your code and it works. BTW, can the
    other controls be greyed out also?

    Through playing around, I found that there are 7 menu
    items (based on 0):

    0 - ?
    1 - Move
    2 - Size
    3 - Minimize
    4 - Maximize
    5 - ?
    6 - Close (ALT-4) and greys out "X"

    0 and 5 didn't seem to do anything and although you can't
    use the Minimize and Maximize control icons they do not get
    greyed out.

    [Edited by dsy5 on 09-07-2000 at 09:04 PM]
    Donald Sy - VB (ab)user

  9. #9
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Megatron,

    How would I use your code if I put it in a module? For some reason, it doesn't seem to disable the X if I put the first 3 lines of code in a module and change the first 2 to "Public"..

    But it does work on the form that it's being called from..

    My idea is that I'm developing a standard library of code that I can reuse in various projects..

    Thanks for any help you can provide to make this work..

    Dan

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    If you use something like this:
    Code:
    Private Function Remove(hWnd as Long) As Integer
        Remove = RemoveMenu(GetSystemMenu(hWnd, 0), 6, MF_BYPOSITION)
    End Function
    That should work. Megatron's function works for the current window handle only, so it needs to be in a form.

    One edit later...
    Damn! That bug's still there


    [Edited by parksie on 09-16-2000 at 02:12 AM]
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11
    Guest
    To gray out the Max button, you do not need any API. Just set the MaxButton property to False.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width