How to hide access window killing my popup menus?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • munkee
    Contributor
    • Feb 2010
    • 374

    #1

    How to hide access window killing my popup menus?

    Hi all,

    I am using the following article code to minimize the access container window when my application starts because it looks really professional without the grey background being there.

    However I have found my shortcut menu's no longer work. I have tried even executing code such as:

    Code:
    CommandBars("mymenu").showpopup
    This fails with an error saying method popup of command bar failed (runtime error).

    Is there another method which can be used to hide the access window so only my popup form shows cleanly? or some form of shortcut way to get past this issue.

    I have also found this method also stops the default menu popups working also.
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Could you post the specific code for hiding the Access DB window you are referring to? You mention it but have not posted it.

    Thanks

    Stewart

    Comment

    • munkee
      Contributor
      • Feb 2010
      • 374

      #3
      In my splash screens on load even I call a routine as follows:

      Code:
      Private Sub Form_Open(Cancel As Integer)
      'Start open ended error handler
      On Error GoTo tagError
      
      Call AccessMinimize
      
      DoCmd.OpenForm "frmHidden", acNormal, , , , acHidden
      
      'End of successful code
      ExitMe:
      Exit Sub
      
      'Handle the error type code
      tagError:
          MsgBox Err.Description
          Resume ExitMe
      End Sub
      This is then running the following code:

      Code:
        Option Explicit
      
      Declare Function apiGetActiveWindow Lib "user32" Alias _
               "GetActiveWindow" () As Long
      Declare Function apiGetParent Lib "user32" Alias "GetParent" _
               (ByVal hwnd As Long) As Long
      Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _
               (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
      Declare Function apiIsIconic Lib "user32" Alias "IsIconic" (ByVal _
               hwnd As Long) As Long
      Declare Function apiIsZoomed Lib "user32" Alias "IsZoomed" (ByVal _
               hwnd As Long) As Long
               
      Global Const SW_MAXIMIZE = 3
      Global Const SW_SHOWNORMAL = 1
      Global Const SW_SHOWMINIMIZED = 2
            
      Function GetAccesshWnd()
      Dim hwnd As Long
      Dim hWndAccess As Long
      
      ' Get the handle to the currently active window.
      hwnd = apiGetActiveWindow()
      hWndAccess = hwnd
      
      ' Find the top window without a parent window.
      While hwnd <> 0
          hWndAccess = hwnd
          hwnd = apiGetParent(hwnd)
      Wend
      
      GetAccesshWnd = hWndAccess
      
      End Function
           
      Function AccessMinimize()
          AccessMinimize = apiShowWindow(GetAccesshWnd(), SW_SHOWMINIMIZED)
      End Function
      
      Function AccessMaximize()
          AccessMaximize = apiShowWindow(GetAccesshWnd(), SW_MAXIMIZE)
      End Function
      
      Function AccessRestore()
          AccessRestore = apiShowWindow(GetAccesshWnd(), SW_SHOWNORMAL)
      End Function
      
      
                      
      Function IsAccessMaximized()
      If apiIsZoomed(GetAccesshWnd()) = 0 Then
          IsAccessMaximized = False
      Else
          IsAccessMaximized = True
      End If
      End Function
      
      Function IsAccessMinimized()
      If apiIsIconic(GetAccesshWnd()) = 0 Then
          IsAccessMinimized = False
      Else
          IsAccessMinimized = True
      End If
      End Function
      
      Function IsAccessRestored()
      If IsAccessMaximized() = False And IsAccessMinimized() = False Then
          IsAccessRestored = True
      Else
          IsAccessRestored = False
      End If
      End Function

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        I suspect the problem is that the application is not hidden at all; it's window is minimised, in which case Access itself is no longer the active window as far as Windows is concerned. In my tests (in Access 2007 rather than 2003) with a dummy popup switchboard the switchboard functions, but as the results are minimised within the application window they are not visible unless the application is restored manually.

        If you wish the splash screen to be visible without the normal Access background you can use the minimise function as at present to keep the splash screen visible with the application minimised, then (say) call the restore function from the splash screen form's On Close event to allow the other forms to behave normally.

        -Stewart

        Comment

        • munkee
          Contributor
          • Feb 2010
          • 374

          #5
          Scott

          that is how I run one of my databases. minimise on load and restore when I work with reports. But for my new database I wanted the same professional look but needed custom short cut menus. Looks like I will have to deal with the ugly background being there. I'm also wondering if the access windows opacity could be changed so it isnt minimised but its invisible.... More research to be done into that though



          Also forgot to add you need to use popup forms for this code to work correctly. Access minimises but the forms stay visible. You can see your desktop and the form floating on top. Hence the professional look
          Last edited by munkee; Feb 1 '11, 07:53 PM. Reason: sorry for bad punctuation using my phone to post this

          Comment

          • munkee
            Contributor
            • Feb 2010
            • 374

            #6
            I've managed to crack this using some apis.

            I have dropped the minimisation of the application window because to be honest it is full of drawbacks.

            I have mixed a couple of apis together to produce code which firstly grabs the current screen resolution. Divides this by half to get the theoretical centre of the screen. The access window is then resized to be at a minimum footprint of 0 by 0.

            I then position this to the centre of my screen with all of my forms within access being set to popups.

            I execute the code via my autoexec macro by calling the function "SizeAccess "

            Code:
                   Option Compare Database
                   Option Explicit
                   
                   Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
                   Declare Sub SetWindowPos Lib "user32" (ByVal hwnd&, ByVal hWndInsertAfter&, ByVal x&, ByVal y&, ByVal cx&, ByVal cy&, ByVal wFlags&)
                   Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
                   Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
            
                   'PUBLIC Constants
                   Public Const SM_CXSCREEN = 0
                   Public Const SM_CYSCREEN = 1
                   
                   'Moves MS Access window to top of Z-order.
                   Global Const HWND_TOP = 0
                   'Creates a window with a maximize box
                   Global Const WS_MINIMIZEBOX = &H20000
                   'Creates a window with a minimize box
                   Global Const WS_MAXIMIZEBOX = &H10000
                   Global Const GWL_STYLE = (-16)
                   'Values for wFlags.
                   Global Const SWP_NOZORDER = &H4      'Ignores the hWndInsertAfter.
                   
                   Function SizeAccess()
                    Dim cx As Long
                    Dim cy As Long
                    Dim h As Long
                    Dim L As Long
                    Dim cHeight As Long
                    Dim cWidth As Long
                    
                    'Size to set app window height/width
                    cHeight = 0
                    cWidth = 0
                    
                    'Get handle to Microsoft Access.
                    h = Application.hWndAccessApp
                    
                    'Set the position for the app to be centred to (50 and 100 refer to offsetting due to application titlebar size)
                    cx = (GetSystemMetrics(SM_CXSCREEN) / 2) - 50
                    cy = (GetSystemMetrics(SM_CYSCREEN) / 2) - 100
                       
                    'Position the access window
                    SetWindowPos h, HWND_TOP, cx, cy, cWidth, cHeight, SWP_NOZORDER
                     
                     'Get the current style.
                     L = GetWindowLong(h, GWL_STYLE)
                    
                     'Get rid of the Minimize Button
                     L = L And Not (WS_MINIMIZEBOX)
                     
                     'Get rid of the maximise button
                     L = L And Not (WS_MAXIMIZEBOX)
                     
                     L = SetWindowLong(h, GWL_STYLE, L)
                     
                    End Function
            The reason this works is basically by ensuring my application window is always small and "hidden" behind my popup forms. The application will continue to have focus so now shortcut menus will work correctly.

            Comment

            • TheSmileyCoder
              Recognized Expert Moderator Top Contributor
              • Dec 2009
              • 2322

              #7
              Could you post a screenshot of your application (or parts of it)? Im a bit curious about the "profession al" look you get from using such code.

              Comment

              Working...