Results 1 to 11 of 11

Thread: How to diable close button of form ???

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    1

    Exclamation

    How to diable close button of form ???
    but i can use min and max button
    on the form ....
    please tell me how to...
    thank you

  2. #2
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183

    Smile

    In the form's unload event you could put this

    Code:
    Cancel = True

  3. #3
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183

    Lightbulb

    Of course if you used the method I told you above the only way to close the form would be by using the end command which would close the entire app. This isn’t a problem if you only intend on using one form. I know its possible to disable the X button so it can’t be clicked at all but I’m not sure how.

  4. #4
    Guest
    Try this.
    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

  5. #5
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183

    Question

    Now I’m really confused. I read in an API book that you can’t use Integer values in an API declaration. However, the two above declarations are using Integer values. Was the book wrong or did I misinterpret something?

  6. #6
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    If you want to put it back at some point then use this to gray it out and ungray it

    Code:
    Option Explicit
    Private Const MF_BYCOMMAND = &H0&
    Private Const MF_ENABLED = &H0&
    Private Const MF_GRAYED = &H1&
    Private Const SC_CLOSE = &HF060&
    Private Const FOOLVB = -10
    Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
    
    
    Public Sub DisableClose(frm As Form)
    
    Dim hMenu As Long
    hMenu = GetSystemMenu(frm.hwnd, 0)
    
    If hMenu Then _
        Call ModifyMenu(hMenu, SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED, FOOLVB, "Close")
        
    Call DrawMenuBar(frm.hwnd)
    
    End Sub
    
    Public Sub EnableClose(frm As Form)
    
    Dim hMenu As Long
    hMenu = GetSystemMenu(frm.hwnd, 0)
    
    If hMenu Then _
        Call ModifyMenu(hMenu, FOOLVB, MF_BYCOMMAND Or MF_ENABLED, SC_CLOSE, "Close")
        
    Call DrawMenuBar(frm.hwnd)
    
    End Sub
    it also makes the x button go gray as a visual indicator

  7. #7
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    I don't know where you read that hypnos, Integers aren't used often in API declares, usually longs are used instead but there are some APIs which take a integer parameters.

  8. #8
    Guest
    Integer's are uncommon but are still used. A C++ WORD is the same as VB's ByVal Integer.

  9. #9
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183

    Cool

    I read it in "Visual Basic 6 Win32 API Tutorial". Maybe the guy was just saying there is no reason to use them?

  10. #10
    Guest
    Maybe he was just generalizing it. Yes you can declare everything as Long; but the other data types save space. For example, you can convert Char to Long or Byte. Both are acceptable but Byte saves a lot more space.

  11. #11
    Guest
    Just incase you're interested, here are C to VB conversions.

    Code:
    HWMD            ByVal var As Long
    LPSTR           ByVal var As String
    HDC             ByVal var As Long
    WORD            ByVal var As Integer
    DWORD           ByVal var As Long
    CHAR            ByVal var As Byte (or String * 1)
    INT             ByVal var As Integer
    INT FAR *       intValue As Integer
    CHAR FAR *      ByVal var As String
    LONG            ByVal var As Long
    LONG FAR *      var As Long
    BYTE            ByVal var As Byte
    BOOL            ByVal var As Boolean
    UNSIGNED SHORT  ByVal var As Integer
    UNSIGNED CHAR   ByVal var As Integer
    UNSIGNED LONG   ByVal var As Long

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