Results 1 to 5 of 5

Thread: easy question - I hope!!

  1. #1
    Guest
    Try this:

    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&
    Form Code
    Then paste this into the form:
    
    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

  2. #2
    New Member
    Join Date
    Oct 2000
    Posts
    8

    Question

    Thanks

    however I couldn't quite get it to work
    -the first bit I placed in the general section which it didn't seem to like
    was I meant to place it elsewhere?

  3. #3
    Guest
    Yes:
    Code:
    Public Declare Function RemoveMenu Lib "user32" Alias "RemoveMenu" (ByVal hMenu As Long, _
    ByVal nPosition As Long, ByVal wFlags As Long) As Long
    Public Declare Function GetSystemMenu Lib "user32" Alias "GetSystemMenu" (ByVal hwnd As Long, _
    ByVal bRevert As Long) As Long
    Private Declare Function GMC Lib "user32" Alias "GetMenuItemCount" (ByVal hMenu As Long) As Long
    
    Sub NoX(FormHwnd As Long)
        Dim x, y
        x = GetSystemMenu(FormHwnd, 0)
        y = GMC(x)
        Removemenu x, y - 1, &400&
        Removemenu x, y - 2, &400&
    End Sub
    And to disable X, use:

    Code:
    NoX(Me.Hwnd)
    Enjoy. You get 2 faces as reward:

  4. #4
    Guest
    Matt's code is fine, however, he doesn't need the MF_REMOVE because the only two are BYPOSITION and BYCOMMAND.

    I was going to answer that! Bad Matt! Joke. Matt's good.

  5. #5
    New Member
    Join Date
    Oct 2000
    Posts
    8

    Talking

    Chears
    Thank you both, I'll give it a shot

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