We help IT Professionals succeed at work.

positioning Forms on Multiple monitors

Oilexo asked
Last Modified: 2012-06-27
I am trying to make my Visual Basic 6 app work on multiple monitors.
My app has about 10 forms. The user can controI  the size & position of each form.  At session end ,sizes & positions are saved .Next session restores the forms to the last know size & position.
With Multiple monitors, I envision my users (who said they were rational?) spreading out the the forms on 2 or more monitors.
If the monitors are moved on the Virtual DeskTop or removed, my forms might not be visible.
I found this 1997 article in MS knowledge base about programming for Multiple monitors.
Unfortunately for me , it is written in C++;
The last part of the code in the article, MMHelp.c, has routines that might solve my problem.
-ClipWindowToMonitor, MakeSureMonitorIsVisble.
Here is the URL of tje MS article
Do you think that these routines are still valid in the sense that I wish my app to run on all MS platforms from Win95 to Vista?
Has any ever converted these routines to VB?

Watch Question

RobinSoftware Engineer

Maybe the following link is useful to you :


You can download a VB6 sample project that shows how to detect and handle multiple monitors.
RobinSoftware Engineer



Robinu, Thank for trying.
I have been playing with those Multimon examples for some time and still havent got what i need.
I still think the answer to my problems lay in the C++ article of MS
(Here is the URL of the MS article
especially the MMHelp section.)
I'm not a C++ programmer and don't really know an hwnd from  a DC.
Perhaps if someone would be so kind as to attempt to transliterate some of those MMhelp routines into VB6 , the I will at least have starting point to start my hacking.

Thanks so far for your efforts
RobinSoftware Engineer

Ok, have a look at http://allapi.mentalis.org/apilist/MonitorFromRect.shtml

Some of the API function in the c++ article are mentioned there.
And you can search for other api functions.


Hello robinu,
Thanks for your information.
I have been away/down recently.
However, I've rethought what I want my app to do when working with Multimonitors. It seems to me that all of my forms should be shown on the monitor that the main form is running on. If the user drags the main form to another monitor , then all of the remaining forms will follow it to the new monitor ( forms currently visible or not!) .I am now working with a simple 3 monitor setup .I have been capturing the forms final position before exitiing so as to restore  for the next instance. When (restoring)forms that are not on the same monitor as the main, I am looking for them on the wrong monitor. It's just too confusing for me , pity my poor users (who may also have changed their VDT). I am still trying to understand what if any Windows XP assistance/interference has in all of this. I  am testing, turning off all of my forms positioning, and somehow, sometimes , some my forms are appearing on monitors that I never ever set them on. What  
really bugs me, is that the HELP dialogue , appears uncontrollably and unpredictably and only sometimes( no correlation obvious to my small mind) on a monitor unrelated to the calling form.  I will try to build some sort of "truth"
table, showing the starting monitror, the sub form monitor and the Help dialog monitor.  Naturally, to complicate the issue, sub forms may launch further (sometimes modal, sometimes not) sub forms  with the Help dialogue not behaving rationally.

Yours, somewhere on the Virtual DeskTop,


Been away for a while.
1. Monitor of main form.
   I did find some code to subclass my main form and get the monitor handle in the on_move event.
   In that event, I did use the some of the MS example . There was an error in it which held me up for   some time
  The "GetMonitorFromWindow(" method in the class will only work from a module.
  (I found that solution too by searching the web)
  That way, I could get the monitorId  of the main form by its hwnd.
 In each of my forms, in the paint and got_focus events , I check  the location of main monitor,  and the current monitor of this form., If main form changed monitor, or monitor view port changed placing my form off screen, or if monitor removed from desk top, i move form (centered ) to the new monitor.
I save and restore the forms size ,positions and monitor between runs, working just fine now.
So, what to do about the points? Since I had known about the existance of suggested examples, I am leary about the awarding them points. Since I really did the work in solving the problem, maybe I should get the points. I dont know what use the points would be to me . What use are they really to you?
I'll decide in the next few days.

Software Engineer
This one is on us!
(Get your first solution completely free - no credit card required)
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.


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.