Link to home
Start Free TrialLog in
Avatar of RogerH1
RogerH1

asked on

Window placement when minimized

I am trying to set the location of my window on the desktop once it is minimized. I have used the following code in my form_resize event, but when I change the X and Y coordinates in it nothing happens. I would like to find a way that I can relocate a minimized window anywhere I want on the desktop(i.e. above the Start button, or the upper right corner...). I have the ShowInTaskbar set to False.


If Me.WindowState = vbMinimized Then
Call SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, SW_MINIMIZED)
End If

Has anyone done this before?

Thanks,
Roger.
Avatar of rspahitz
rspahitz
Flag of United States of America image

Haven't done it, but how about if you simply change the size of the form to something really small and then move it?

If that doesn't work, instantiate a new borderless form that has a picture of your choice on it, and when the original is "minimized" simply hide it and show this other tiny form, at the location of your choice.
Avatar of RogerH1
RogerH1

ASKER

I tried playing with one I found at AllAPI.Net but I was not able to get it to work. Here is the address if anyone wants to see it:

http://www.allapi.net/apilist/example.php?example=Window%20Placement

My two forms each have a Picturebox in them with the controls and objects pasted in. I went this way so that I could use scrollbars in each of the two forms. Well this caused another problem. When I would hide Form1 to go into Form2 it would still show up in the Taskbar, even though it was hidden. So instead of having an instance of two forms in the Taskbar I took them both out and minimize it to the desktop instead. This works fine except that I cannot relocate their possition. When it is minimzed it is set to the TopMost then I make it NotTopMost when maximized so that it will sit on top of the Taskbar rather than below (in case Auto-Hide is enabled).

With all of this in mind, maybe that will help somebody to come up with a better solution.

Thanks.
I experimented with the idea of overriding the minimize in the Resize event procedure, and it just leads to problems.

The other choice I suggested should work (create a new mini-form just for when the main form is minimized), but you'll have to simulate a windows title bar.

At this point, I don't know of any way to override Windows's choice of location when a window is minimized.
Avatar of RogerH1

ASKER

Rspahitz, I appreciate your help. I cannot award any points only because I went a different direction than you were suggesting. However, they were good suggestions because I was definitely giving it some thought as to trying them.

It turns out that I was very close, except the flag in the SetWindowPos was wrong. I tried putting in the actual SWP... flag names and never got it to work without an error. So I thought that alot of these words relate to numbers most of the time. Once I started playing with them I finally got it to work. Thanks for everyones help, you were all on the right track.


If Me.WindowState = vbMinimized Then
  Call SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 550, 0, 0, 0)
ElseIf Me.WindowState = vbMaximized Then
  Call SetWindowPos(Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, 3)
End If

Thanks,
Roger.
:-{)
OK...go to customer support and post a zero-point question asking that the refund your points here then PAQ this for future benefit to others.

Glad you got it working!  It ended up being an interesting test for me anyway...

Avatar of Richie_Simonetti
If you set form's borderstyle to 5, when minimized you form will be above strat button.
You need to manage minize and maximize fucntions by yourself.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- refund/PAQ
Please leave any comments here within the
next seven days.
Avatar of RogerH1

ASKER

I never gone a good response here and never knew how to close it out.

Thanks,
Roger.
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial