Strange functions on Load and Unload

D

David

I'm working on an old old system that uses customized menu
bars. It is a pain because they keep popping up and
affecting my development since they replace the Access
menu bars. The Load and Unload events for my main menu are
as follows. Can anyone explain to me what they are doing?
I'd really like to get rid of the customized menu bars
completely since I have extensively modified this system
and they are now all wrong. They are maintained by global
Windows API functions which are incomprehensible to me.

Private Sub Form_Load()
On Error Resume Next

Dim intChildWindowState As Integer

intChildWindowState = GetPrivateProfileInt("Secondary
Window", "State", 0, "srts_a.ini")

If intChildWindowState = 2 Then
DoCmd.Maximize
End If

Application.MenuBar = "mcrMenuBar"

DoCmd.ShowToolbar "Form View", A_TOOLBAR_NO
DoCmd.ShowToolbar "Print Preview", A_TOOLBAR_NO
DoCmd.ShowToolbar "SRTS Print Preview", A_TOOLBAR_NO
DoCmd.ShowToolbar "SRTS", A_TOOLBAR_YES

'App3DRegister

End Sub

Private Sub Form_Unload(Cancel As Integer)

Dim intChildWindowState As Integer
Dim intReturnCode As Integer

DoCmd.ShowToolbar "SRTS", A_TOOLBAR_NO

DoCmd.ShowToolbar "Form View", A_TOOLBAR_WHERE_APPROP
DoCmd.ShowToolbar "Print Preview",
A_TOOLBAR_WHERE_APPROP

If IsZoomed(Forms!frmMain.hWnd) <> 0 Then
intChildWindowState = 2
Else
intChildWindowState = 0
End If

intReturnCode = WritePrivateProfileString("Secondary
Window", ByVal "State", ByVal Trim$(Str
(intChildWindowState)), "srts_a.ini")

'App3DUnRegister

If SysCmd(SYSCMD_RUNTIME) Then
DoCmd.Quit
End If

End Sub
 
J

John Nurick

Hi David,

Not strange at all. GetPrivateProfileInt() and
WritePrivateProfileString() are venerable API functions that retrieve
and set entries in old-fashioned Windows .ini files. See
http://www.allapi.net for a really handy API information tool.

More inline:

I'm working on an old old system that uses customized menu
bars. It is a pain because they keep popping up and
affecting my development since they replace the Access
menu bars. The Load and Unload events for my main menu are
as follows. Can anyone explain to me what they are doing?
I'd really like to get rid of the customized menu bars
completely since I have extensively modified this system
and they are now all wrong. They are maintained by global
Windows API functions which are incomprehensible to me.

Private Sub Form_Load()
On Error Resume Next

Dim intChildWindowState As Integer

Next line retrieves the "State" value from the "Secondary Window" key in
the file srts_a.ini, with a default of 0 if the entry doesn't exist.
intChildWindowState = GetPrivateProfileInt("Secondary
Window", "State", 0, "srts_a.ini")

If intChildWindowState = 2 Then
DoCmd.Maximize
End If
If there's a macro called mcrMenuBar this uses the AddMenu commands in
the macro to build the main menus for the app:
Application.MenuBar = "mcrMenuBar"
The next lines hide the Form View and Print Preview built in toolbars
and the custom SRTS Print Preview toolbar:
DoCmd.ShowToolbar "Form View", A_TOOLBAR_NO
DoCmd.ShowToolbar "Print Preview", A_TOOLBAR_NO
DoCmd.ShowToolbar "SRTS Print Preview", A_TOOLBAR_NO
and display the SRTS custom toolbar:
DoCmd.ShowToolbar "SRTS", A_TOOLBAR_YES

'App3DRegister

End Sub

Private Sub Form_Unload(Cancel As Integer)

Dim intChildWindowState As Integer
Dim intReturnCode As Integer

Hide SRTS toolbar
DoCmd.ShowToolbar "SRTS", A_TOOLBAR_NO
Default "display where appropriate" behaviour for Form View and Print
Preview toolbars
DoCmd.ShowToolbar "Form View", A_TOOLBAR_WHERE_APPROP
DoCmd.ShowToolbar "Print Preview",
A_TOOLBAR_WHERE_APPROP

Get value representing window state of main form
If IsZoomed(Forms!frmMain.hWnd) <> 0 Then
intChildWindowState = 2
Else
intChildWindowState = 0
End If Store it in the .ini file
intReturnCode = WritePrivateProfileString("Secondary
Window", ByVal "State", ByVal Trim$(Str
(intChildWindowState)), "srts_a.ini")

'App3DUnRegister
If this is a run-time version of Access then quit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top