We help IT Professionals succeed at work.

Challenge: Minimizing the main form from modal form

stanis
stanis asked
on
442 Views
Last Modified: 2010-05-01
Hi!

I am making an SDI application that, among other things, has to send emails to a number of recipients. This procedure may take some time, so I open a progress form modally and display the status of the sending operation there.

However, the main application window is often maximized, and the user has no way of getting to the desktop to open files, etc, other than by clicking "Minimize all windows", which is not available on all OS versions supported. Clicking the Minimize button on the modal form only minimizes the modal form itself (to the bottom left corner of the screen, not the taskbar).

I tried setting WindowState of the main form to vbMinimized when the modal form is minimized (in its Resize event). This does minimize the main form together with the modal form, but in this case I cannot bring up the application again and have to Control-Alt-Delete it. I even tried subclassing the form and watching the messages, but I am getting nowhere. I cannot make the form non-modal because there are many issues involved.

Do you have any clues?

Thanks a lot!

Stanislav
Comment
Watch Question

when dont you just minimize the main window with the modal window

in the Resize Function for the modal window just put

mainWindow.WindowState = vbMinimized

why wont that work?

Author

Commented:
Hi!

You can try for yourself, it doesn't. I think it has to do with window focus, etc. Once the window is minimized to the taskbar this way, I cannot bring up both windows and the app stays there forever. I have to quit it the hard way by using Ctrl+Alt+Delete.

Stanislav
Sure I will try.
Quick question are you only trying this while runnign the program in the IDE or have you tested a compiled version of this program with the same problem?
Alright I see what you are saying...Give me a little bit to find you a solution.
One option would be to add an icon to the System Tray so we can have a menu pop-up and allow us to run some code to restore the windows...

-Brian
I know why its doing this, its doing it because Form2 (modal form) has the current focus so therefor form1 isnt allowed any system messages. So when the users clicks on Form1() the one that ends up in the task bar its not receiving the msg because the modal form is active.

Author

Commented:
Hi again,

Well, this is a solution, but it's not intuitive enough. Many programs out there simply either make a separate progress form (with its own taskbar icon) and open it non-modally. However, my application is SDI and many concurrency problems are sure to pop up if I follow the same path. I am sure there should be a solution, just not so simple.

Thanks for trying to help!

Stanislav

Author

Commented:
I am thinking that maybe I can intercept the message that comes to the modal form when both windows are minimized, and set WindowState of the main form. However, what message to look out for? I use vbAccelerator SSubTmr dll so I can do subclassing if I know the message. However, WM_ACTIVATEAPP never comes to the modal window because it does not activate in the first place. Maybe some non-client area message?

Stanislav
Give me some time, Ill find a solution.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi, Brian!

Thanks a bunch!

I will test this solution tonight and will get back to you tomorrow (I am a bit pressed for time at the moment). Sounds like this is it.

Stanislav

Author

Commented:
Hi!

I tested the code, but it doesn't really work in my situation: 1) the solution seems to work for 2 modal forms on top of one non-modal, 2) An additional comment is made about minimizing both forms for my situation, but it says that the main form is simply moved off the screen. It's weird. I will do some more testing and will get back to you.

If you have any other solutions, I will be glad to get one.

I found some code for Delphi by using Google, but I cannot test it because I don't have Borland Delphi. I am not even sure it works, though, because although it uses message intercepting techniques, it intercepts the same WM_COMMAND message with SC_MINIMIZE argument which should be handled by the Resize event in VB code.

Stanislav
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
made a mistake of posting the same code in the link provided by brian ..
/Visual_Basic/Q_10231797.html ...
Why don't you just set in your progress form (on some command button event):
frmMain.Visible=False
To hide main window ?
And when user wants to show it again - provide it with other button with caption "Show" and code: frmMain.Visible=True
Ot you can try with frmMain.Move -10000,-10000,0,0 (To make it very small) ;)

Just funny suggestions ;)

Author

Commented:
Thanks, guys!

Brian, your tip could not work without the comment by Rejojohny, so I decided to split the points 350 to 150. I think that's fair enough.

For some reason, Rejojohny's code worked while Brian's didn't. Maybe it was my fault and I missed something, but it works now!

Best regards,
Stanislav

Author

Commented:
Hi again!

I made some modification to this project. Now, I subclass the modal form, watching for WM_SYSCOMMAND message and checking for wParam=(SC_MINIMIZE AND 65520). When the message is received, I hide the modal form and minimize the main form. There is no visual effect of modal form being minimized to the lower left corner, as before, so I think this is a better solution.

I had to cope with another problem which shows only under WinXP. When the modal form is reshown from main form's Resize event, the main form appears as a small rectangle, as though its minimized icon was moved from the taskbar without being fully shown. I got around this by watching for WM_ACTIVATE message with wParam=WA_ACTIVE (in main window) and only redisplaying the modal form from there. The Resize event, obviously, is triggered before the window is fully displayed.

Best regards,
Stanislav

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.