p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

access thread: TIPS OF THE DAY


Message #1 by "George Oro" <george@c...> on Tue, 4 Jun 2002 13:24:11 +0400
To those interested,

Actually I forgot where I get this and who's the author. Anyhow, here it is... and many thanks who ever he is.

Just paste the below code to a new module and name it as you like.
What I did is, I put this code to my StartUp Form and reverse on my Admins Area for debugging.

Cheers,
George

-------------------------------- Code Start ---------------------------------------
Option Compare Database
Option Explicit

Private Declare Function apiEnableMenuItem Lib "user32" Alias _
    "EnableMenuItem" (ByVal hMenu As Long, ByVal wIDEnableMenuItem As Long, _
     ByVal wEnable As Long) As Long
     
Private Declare Function apiGetSystemMenu Lib "user32" Alias _
         "GetSystemMenu" (ByVal hwnd As Long, ByVal Flag As Long) _
         As Long

Function EnableDisableControlBox(bEnable As Boolean, _
    Optional ByVal lhWndTarget As Long = 0) As Long

On Error GoTo ErrorHandling_Err

Const MF_BYCOMMAND = &H0&
Const MF_DISABLED = &H2&
Const MF_ENABLED = &H0&
Const MF_GRAYED = &H1&
Const SC_CLOSE = &HF060&

Dim lhWndMenu As Long
Dim lReturnVal As Long
Dim lAction As Long

lhWndMenu = apiGetSystemMenu(IIf(lhWndTarget = 0, Application.hWndAccessApp, lhWndTarget), False)

If lhWndMenu <> 0 Then
     If bEnable Then
        lAction = MF_BYCOMMAND Or MF_ENABLED
     Else
        lAction = MF_BYCOMMAND Or MF_DISABLED Or MF_GRAYED
     End If
     lReturnVal = apiEnableMenuItem(lhWndMenu, SC_CLOSE, lAction)
End If

EnableDisableControlBox = lReturnVal

ErrorHandling_Err:
    If Err Then
        'Trap your error(s) here, if any!
    End If
End Function

------------------------- Code End ---------------------------------


Message #2 by "George Oro" <george@c...> on Tue, 18 Jun 2002 09:50:15 +0400
Hi Guys,

For those who miss this Tips...

Cheers,
George


-----Original Message-----
From: George Oro [mailto:george@c...]
Sent: Tuesday, June 04, 2002 1:24 PM
To: Access Help
Subject: TIPS OF THE DAY


To those interested,

Actually I forgot where I get this and who's the author. Anyhow, here it is... and many thanks who ever he is.

Just paste the below code to a new module and name it as you like.
What I did is, I put this code (*) to my StartUp Form and reverse on my Admins Area for debugging.

 (*) Call EnableDisableControlBox(False,0)

Cheers,
George

-------------------------------- Code Start ---------------------------------------
Option Compare Database
Option Explicit

Private Declare Function apiEnableMenuItem Lib "user32" Alias _
    "EnableMenuItem" (ByVal hMenu As Long, ByVal wIDEnableMenuItem As Long, _
     ByVal wEnable As Long) As Long
     
Private Declare Function apiGetSystemMenu Lib "user32" Alias _
         "GetSystemMenu" (ByVal hwnd As Long, ByVal Flag As Long) _
         As Long

Function EnableDisableControlBox(bEnable As Boolean, _
    Optional ByVal lhWndTarget As Long = 0) As Long

On Error GoTo ErrorHandling_Err

Const MF_BYCOMMAND = &H0&
Const MF_DISABLED = &H2&
Const MF_ENABLED = &H0&
Const MF_GRAYED = &H1&
Const SC_CLOSE = &HF060&

Dim lhWndMenu As Long
Dim lReturnVal As Long
Dim lAction As Long

lhWndMenu = apiGetSystemMenu(IIf(lhWndTarget = 0, Application.hWndAccessApp, lhWndTarget), False)

If lhWndMenu <> 0 Then
     If bEnable Then
        lAction = MF_BYCOMMAND Or MF_ENABLED
     Else
        lAction = MF_BYCOMMAND Or MF_DISABLED Or MF_GRAYED
     End If
     lReturnVal = apiEnableMenuItem(lhWndMenu, SC_CLOSE, lAction)
End If

EnableDisableControlBox = lReturnVal

ErrorHandling_Err:
    If Err Then
        'Trap your error(s) here, if any!
    End If
End Function

------------------------- Code End ---------------------------------


Message #3 by "Kenny Alligood" <kennyalligood@h...> on Wed, 19 Jun 2002 13:41:21 -0400
Thanx for your help I got it to work with a minor modification. I actually 
called the function from my autoexec macro with the RunCode 
EnableDisableControlBox(False, 0).

Kenny


>From: "George Oro" <george@c...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] FW: TIPS OF THE DAY
>Date: Tue, 18 Jun 2002 09:50:15 +0400
>
>Hi Guys,
>
>For those who miss this Tips...
>
>Cheers,
>George
>
>
>-----Original Message-----
>From: George Oro [mailto:george@c...]
>Sent: Tuesday, June 04, 2002 1:24 PM
>To: Access Help
>Subject: TIPS OF THE DAY
>
>
>To those interested,
>
>Actually I forgot where I get this and who's the author. Anyhow, here it 
>is... and many thanks who ever he is.
>
>Just paste the below code to a new module and name it as you like.
>What I did is, I put this code (*) to my StartUp Form and reverse on my 
>Admins Area for debugging.
>
>  (*) Call EnableDisableControlBox(False,0)
>
>Cheers,
>George
>
>-------------------------------- Code Start 
>---------------------------------------
>Option Compare Database
>Option Explicit
>
>Private Declare Function apiEnableMenuItem Lib "user32" Alias _
>     "EnableMenuItem" (ByVal hMenu As Long, ByVal wIDEnableMenuItem As 
>Long, _
>      ByVal wEnable As Long) As Long
>
>Private Declare Function apiGetSystemMenu Lib "user32" Alias _
>          "GetSystemMenu" (ByVal hwnd As Long, ByVal Flag As Long) _
>          As Long
>
>Function EnableDisableControlBox(bEnable As Boolean, _
>     Optional ByVal lhWndTarget As Long = 0) As Long
>
>On Error GoTo ErrorHandling_Err
>
>Const MF_BYCOMMAND = &H0&
>Const MF_DISABLED = &H2&
>Const MF_ENABLED = &H0&
>Const MF_GRAYED = &H1&
>Const SC_CLOSE = &HF060&
>
>Dim lhWndMenu As Long
>Dim lReturnVal As Long
>Dim lAction As Long
>
>lhWndMenu = apiGetSystemMenu(IIf(lhWndTarget = 0, 
>Application.hWndAccessApp, lhWndTarget), False)
>
>If lhWndMenu <> 0 Then
>      If bEnable Then
>         lAction = MF_BYCOMMAND Or MF_ENABLED
>      Else
>         lAction = MF_BYCOMMAND Or MF_DISABLED Or MF_GRAYED
>      End If
>      lReturnVal = apiEnableMenuItem(lhWndMenu, SC_CLOSE, lAction)
>End If
>
>EnableDisableControlBox = lReturnVal
>
>ErrorHandling_Err:
>     If Err Then
>         'Trap your error(s) here, if any!
>     End If
>End Function
>
>------------------------- Code End ---------------------------------
>
>
>


_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com


  Return to Index