Solved

Minimizing and Restoring Multiple Forms in VB5

Posted on 1998-06-25
5
297 Views
Last Modified: 2010-05-03
My progam starts with a form "frmMain", then opens and closes many other forms as it runs.  However the "frmMain" form always stays on the screen as sort of a visible background object.  At any one time, several of these forms may be shown in the Win 95 Status Bar at the bottom of the screen.

My question is this:

The only form with a Minimize Button in the "frmMain".  However when a user clicks this button I want ALL the open forms in my VB5 application to be minimized also.  As it stands now, when I minimize the "frmMain" form, the other open forms stay visible on the screen, superimposed on whatever other applications windows the user has previously opened.  This is messy.  The user expects them all to disappear.

To Summarize - when I click the Minimize button on the Main form I want all the other open forms to minimize also.  And when I restore the Main form once again I want all the other forms to restore also.

dougr

0
Comment
Question by:dougr
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:jjmartin
ID: 1464360
This sounds like the best option would be to use an MDI.  Multiple Document Interface.  Your main form would be and MDI form and all the other forms are "child" forms to the MDI.  If you didn't want to do this, set the showintaskbar property to false for all the forms but frmMain.  Then in the minimize event of frmMain, you would have to put in the code to minimize the individual forms.  This way is messy.  The MDI interface would look better to the user, and be more efficient.
0
 

Author Comment

by:dougr
ID: 1464361
jjmartin:

Thanks for the answer.  Unfortunately, it isn't quite what I was looking for.

The MDI idea looks good, but unfortunately I have about 500,000 bytes of code written and do not want to make such a major change to the program structure.

I do set the ShowInTaskbar property to True at design time for some of the Sub-forms because I do want some of them to show in the Taskbar so that the user can switch back and forth between forms by clicking the mouse.  Unfortunately the ShowInTaskbar property is "read only" at run-time, so I can't turn it on and off when the program is running.

I have tried code in the frmMain Form_Resize event similar to the following with no luck:

Private Sub Form_Resize()
  If Me.WindowState = vbMinimized Then
    frmForm1.WindowState = vbMinimized
    frmForm2.WindowState = vbMinimized
    ....
      ....
  End If
End Sub

I even tried unloading the other forms when the frmMain form is minimized:

Private Sub Form_Resize()
  If Me.WindowState = vbMinimized Then
    Unload frmForm1
    Unload frmForm2
    ....
      ....
  End If
End Sub

All of the above code seems to be ignored by the program when frmMain is minimized.

dougr
0
 
LVL 4

Accepted Solution

by:
yowkee earned 100 total points
ID: 1464362
dougr,

Try this:

-----
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_MINIMIZE = 6
Const SW_NORMAL = 1

Private Sub Form_Resize()
    Static bMinimize As Boolean
    Dim frmTmp As Form
   
    If Me.WindowState = vbMinimized Then
        bMinimize = True
       
        For Each frmTmp In Forms
            ShowWindow frmTmp.hwnd, SW_MINIMIZE
        Next
    Else
        If bMinimize = True Then
            bMinimize = False
            For Each frmTmp In Forms
                ShowWindow frmTmp.hwnd, SW_NORMAL
            Next
        End If
    End If
End Sub
-----

Regards.
0
 

Author Comment

by:dougr
ID: 1464363
Thank you for the code.  It seems to be working fine.

Perhaps I could elicit some comments from you on the following topic:

I am a relative neophyte with respect to Visual Basic although I spent many years working with Microsoft DOS Basic Version 7.  I have received several good solutions from the Experts Exchange, and I have observed that several of them have involved API calls.  My question is this: Where can you get lists of the various functions and calls?  Is there an Internet Site or Textbook that lists them and how to use them?

In some ways these API calls remind me of the many DOS Interrupts we used to use in DOS Basic to gain access to speed improvements or to perform operations which were not provided by the built-in Basic Functions and Commands.

Thanks for your help.

dougr
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1464364
dougr,

  Well, Windows API is the programming interface provided by OS(here's Windows), just like those DOS interrupt which provided by DOS. Thus, almost all application running under Windows will use the Windows API. Those RAD product such as VB, Delphi, BCB just a good wrapper of API in order to provide friendly programming environment.

  The basic of Windows API came from three DLLs: Kernel32.dll, Gdi32.dll and user32.dll. And in fact they call their appropriate 16 bit dlls(krnl386.exe, gdi.exe and user.exe) which previously was the core of Windows 3.xx. The different of the oldie DOS interrupt and these Windows API is that all windows application was running in protected mode. An user application can't access the interrupt directly instead through the API. And yeah, internally those APIs still call the DOS interrupt.

  For your question about the reference of APIs. Getting good resource and experience might be the way to deal with them. Basically we search the API info/syntax from MSDN. You could subscribe MSDN On-line through MS site(www.microsoft.com/msdn). For some new APIs which come from some new DLL distributed with MS production, you could find out about them through some tools to analyse the DLL(eg, QuickView, Dumpbin frmo VC), and search for them in coming include file for VC++. And definitely these infos will be easily found in VC compared with VB. It's just not VB style to provide those info.

  Hope this help. :)

Yowkee
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now