Solved

Minimizing and Restoring Multiple Forms in VB5

Posted on 1998-06-25
5
292 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

763 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

9 Experts available now in Live!

Get 1:1 Help Now