Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

api problems - Close button

Status
Not open for further replies.

ecannelora

Programmer
Feb 4, 2005
34
0
0
US
okay, I researched turning off the close button for reports, and here's what I have:

Code:
Option Compare Database
Option Explicit

Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, _
   ByVal bRevert As Long) As Long

Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As _
   Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long

Private Declare Function GetMenuItemInfo Lib "user32" Alias _
   "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As _
   Long, lpMenuItemInfo As MENUITEMINFO) As Long

Private Type MENUITEMINFO
    cbSize As Long
    fMask As Long
    fType As Long
    fState As Long
    wID As Long
    hSubMenu As Long
    hbmpChecked As Long
    hbmpUnchecked As Long
    dwItemData As Long
    dwTypeData As String
    cch As Long
End Type

Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060&



[b]Public Property Get Enabled() As Boolean[/b]
    Dim hWnd As Long
    Dim hMenu As Long
    Dim result As Long
    Dim MI As MENUITEMINFO

    MI.cbSize = Len(MI)
    MI.dwTypeData = String(80, 0)
    MI.cch = Len(MI.dwTypeData)
    MI.fMask = MF_GRAYED
    MI.wID = SC_CLOSE
[b]   hWnd = Application.Screen.ActiveReport.hWnd[/b]
    hMenu = GetSystemMenu(hWnd, 0)
    result = GetMenuItemInfo(hMenu, MI.wID, 0, MI)
    Enabled = (MI.fState And MF_GRAYED) = 0
End Property

[b]Public Property Let Enabled(boolClose As Boolean)[/b]
    Dim hWnd As Long
    Dim wFlags As Long
    Dim hMenu As Long
    Dim result As Long

[b]    hWnd = Application.Screen.ActiveReport.hWnd[/b]
    hMenu = GetSystemMenu(hWnd, 0)
    If Not boolClose Then
        wFlags = MF_BYCOMMAND Or MF_GRAYED
    Else
        wFlags = MF_BYCOMMAND And Not MF_GRAYED
    End If
    result = EnableMenuItem(hMenu, SC_CLOSE, wFlags)
End Property

I think the key elements are in the Get and Let Property statements when I set hWnd = Application.Screen.ActiveReport.hWnd

My problem now is that it only turns off the Close button if the report is restored or minimized. If it's maximized, the button is still enabled. How can I turn it off when the Report is maximized?

please, please let me know if you have ideas or if you know how I can do it. I'm pretty frustrated.

thanks a lot!
eric
 
Why not this??

Microsoft said:
Set the CloseButton property to No.

Note When you set the CloseButton property to No, Microsoft Access disables the Close button and also disables the Close command on the Control menu. If you want to remove the Close button completely, set the BorderStyle property to None.

I assume you got your code from here Microsoft Close

HTH



 
In Access 2000, there is no close property for a report. Unless I'm retarded or blind. and I freely admit, either is possible.
 
that second one does a bit more than I was looking for, but it gets the job done.

Thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top