Date: | March 14, 2005 / year-entry #63 |
Tags: | other |
Orig Link: | https://blogs.msdn.microsoft.com/oldnewthing/20050314-00/?p=36203 |
Comments: | 34 |
Summary: | A common feature for many applications is to record their screen location when they shut down and reopen at that location when relaunched. If implemented naively, a program merely restores from its previous position unconditionally. You run into usability problems with this naive implementation. If a user runs two copies of your program, the two... |
A common feature for many applications is to record their screen location when they shut down and reopen at that location when relaunched. If implemented naively, a program merely restores from its previous position unconditionally. You run into usability problems with this naive implementation. If a user runs two copies of your program, the two windows end up in exactly the same place on the screen. Unless the user paid close attention to their taskbar, it looks like running the second copy had no effect. Now things get interesting. Depending on what the program does, the second copy may encounter a sharing violation, or it may merely open a second copy of the document for editing, or two copies of the song may start playing, resulting in a strange echo effect since the two copies are out of sync. Even more fun is if the user hits the Stop button and the music keeps playing! Why? Because only the second copy of the playback was stopped. The first copy is still running. I know one user who not infrequently gets as many as four copies of a multimedia title running, resulting in a horrific cacophany as they all play their attract music simultaneously, followed by mass confusion as the user tries to fix the problem, which usually consists of hammering the "Stop" button on the topmost copy. This stops the topmost instance, but the other three are still running... If a second copy of the document is opened, the user may switch away from the editor, then switch back to the first instance, and think that all the changes were lost. Or the user may fail to notice this and make a conflicting set of changes to the first instance. Then all sorts of fun things happen when the two copies of the same document are saved. Moral of the story: If your program saves and restores its screen position, you may want to check if a copy of the program is already running at that screen position. If so, then move your second window somewhere else so that it doesn't occupy exactly the same coordinates. |
Comments (34)
Comments are closed. |
There seems to be no solution to this problem if your application last started maximized!
I’ve also noticed some programs doing things like this, and then showing up off the screen if I change my resolution or change the positioning of my multiple monitors. So, it’s probably a good idea to make sure that the coordinates you want to restore at are still within the visible area that the user can see.
If the previous instance is maxed, you can start the next copy in restored mode using the previous coords. Also, you can restore the previous instance and then continue on with the normal positioning system.
On a vaguely related note, Windows Explorer has/had a bizarre bug which causes it to open windows with a width of zero! I never figured out how this happened or how to fix it – for some reason the default size didn’t get updated even though I kept resizing these zero-width windows using Alt-Space. I can’t imagine how an ordinary user would cope with invisible windows like that.
> I’ve also noticed some programs doing things like this, and then
> showing up off the screen if I change my resolution or change the
> positioning of my multiple monitors. So, it’s probably a good idea
> to make sure that the coordinates you want to restore at are still
> within the visible area that the user can see.
I agree.
Best solution is probably what many applications already do and
prevent multiple instances from being run.
Another issue that has bitten me many times:
The desktop dimensions might have changed.
I have a dual-monitor workstation at work, but I frequently VPN in from home and use Remote Desktop. (single monitor at home)
Consider what happens you start an app in remote desktop, and its former location was on the second monitor. The form opens so far to the right that it is completely non-visible. That’s really irritating!! You have to use the move option on the taskbar, and then use the keyboard arrows to drag the form back over.
Even worse, if the app doesn’t take this into account with its dialog boxes, you can get modal dialogs on the non-existent monitor. (Happens with Visio all the time, because Visio tries to remember which monitor to display its dialogs on).
Several apps I’ve used will behave strangely if you close them while they are minimized, then reopen them. I assume they’re using something other than GetWindowPlacement to determine where they were.
I have the same problem switching between my laptop LCD and my desktop. Very different resolutions.
Is there any way for an open application to realize the screen has been resized, and that it is now off-screen?
> Is there any way for an open application to realize the screen has
> been resized, and that it is now off-screen?
I think there is a notification when the resolution is changed while
an application is running, but beside storing the resolution from the
last start and comparing this value with the current one I am not
aware of any way to determine such a change.
Some programs use GetWindowPlacement to save the position and then they use SetWindowPos to set it.
Try it with the bar on the top, it’s funny…
http://blogs.msdn.com/oldnewthing/archive/2004/07/07/175285.aspx
A pet peeve of mine is the VS.NET + Deskmenu Powertoy combo. I keep a shortcut of Visual Studio .NET on my desktop and use the deskmenu to launch it. Visual Studio always starts in "restored" mode, even if it was maximized when I closed it! Probably Deskmenu uses SW_SHOWNORMAL command and Visual Studio decides to ignore its saved settings. (BTW, Visual Studio 6 did work correctly, this problem started with .NET)
Whose fault is this? Should Deskmenu use SW_SHOW instead, or Visual Studio should ignore the show command?
erk, typo! its ‘cacaphony’ — ‘phon’ as in suond.
bonk bonk bonk…
Am I the only one who finds it funny that the post correcting Raymond’s spelling has two spelling errors – and one of them is the word being corrected?
‘Cacophony’.
Those who can’t really shouldn’t criticise.
mike good piont! but if u gota be wihtuot sin to cast sttonas then nboody culd cast stoans at all! an nobody wnats 2 lieve in a wrold lik taht.
Yo mihgt be rigt, whu nows!
And what if the window completely fills the work area, but it’s not maximized? Sometimes trying to protect the user from himself is just not worth it.
Yeah, I see this all the time. It’s a flaw in the windows user interface in my opinion. (Not the position, but the opening of applications twice)
Naive users, and even me occasionally, click the application icon twice because it just takes too long for the application to show up. And there is hardly any noticable feedback from the windows GUI if a program is lauching.
And an application should only be allowed to open twice if it load’s two distinct documents, or if the users requests to do so from with the application. And then, yes, you are right, a naive placing policy is not enough.
I would absolutely LOVE to see two functions added to Win32 or put in some sort of utility library.
CascadeWindowPos( WINDOWPOS *out, WINDOWPOS const *in ) – Offsets the window down and to the right, or moves it up to the top leftif it’s out of room. That would help to solve this problem.
EnsureWindowPosVisible( WINDOWPOS *out, WINDOWPOS const *in, flags ) – Will ensure that the window is partially visible, full visible, not spanning monitors, et cetera depending on the flags parameter.
…
That is, if these functions don’t already exist. These would be so wonderfully useful for multimon situations.
Most of my time goes in maximized windows or fullscreen apps. Atleast when you have the todays standard 1280×1024 display.
Most of the time if the window is not maximized goes in moving it around. So the default should be to open apps in maximized state. Now that we have everything running maxed, it is good time to think how to make the experience better if you need to do work between the apps. The answer obviously is not to restore them to a smaller size to do some drag drop crap.
I would not be surprised if Apple has solved this already.
Note that if a window has wandered off-screen, you don’t have to move it all the way back with the keyboard. Press any arrow key once and then move the mouse. The window will follow the mouse cursor until you click. If it happens a lot, remember alt-space, M, arrow, move mouse, click.
Windows will move/resize windows that are on the monitor that changed, but not those out in never land.
Just don’t window movement and prevent your window from going off-screen at all, ever. Starting off-screen is bad. Allowing the user to move the window off-screen is good. (Virtual desktops!)
And not all corrections are criticism.
A bit offtopic:
One of the things I really miss in windows is session management, every *nix desktop out there has it, but at work I’m stuck with win2k and every morning I have to start all the applications I need and move them to the correct monitor, this is quite annoying.
Will there ever be session management in win32 ?
Aaargh!: Microsoft hasn’t changed the functionality of its window manager since 1995. That’s ten years — more than an eternity in the short-lived world of software. What makes you believe that they will change it in the foreseeable future? How long are you willing to wait?
"How long are you willing to wait?"
I stopped waiting for a decent windows version shortly after win98 was released, that was the last version of win32 I had installed on my home machine, in a dual-boot config with Linux. I thrashed it when I realized I didn’t actually use it anymore and I needed the disk-space.
Sadly, I have to use win32 at work, so I would still appreciate it if they would fix their OS, but I’ve given op the hope it might actually happen.
I once wrote a desktop utility (a free tool shipped with the drivers for a certain graphics card) that hooked into all desktop apps to provide a few useful things like starting new apps up in their last position. I’m pleased to say it had that exact feature… it would iterate through all top-level windows, and if it found one with the same classname and already in the position, it would move window-caption-height pixels to the right and down.
Re the zero-window width thing, I had IE6 doing this to me at home. No matter how many times I resized the window (by dragging window borders) new IE windows kept opening with zero width. Finally my non-technical partner found and used the "Size" command on the window menu and of course only then did IE get the idea…. wow was she smug! I don’t know why the WM_SYSCOMMAND made a difference.
There’s an app whose annoying behaviour in this regard I often run into.
It’s called "notepad.exe".
Sigh…
It’s hard to restore the coords correctly. Several ‘gotchas’ is mentioned already (minimized window, resolution change, multimonitor, …). Usually I want to "bounce" the window against any border (and resize it if it’s larger than the desktop), but it becomes complicated with multimonitor. Function for this should have been included in multimon-api.
And, applications which doesn’t allow several instances usually do this because it’s hard to manage shared resources. Not because it is userfriendly in any way. I hate those programs.
The work-around (which works 99% of the time) is to use 2 computers.
what kills me is, I have my laptop connected to my 21" monitor and use both monitors for designing
but if I turn on the laptop with the other monitor disconnected and open Photoshop, it will sometimes open in the ghost monitor!… and what’s worst, I can manage to move that window manually, but when I do "File, Open", or "File Save", etc, those open in the ghost monitor!!… and you can’t move those windows!… arrrrgghh… I have to connect the monitor open every single window in the laptop monitor before I can work in the laptop by itself
I must be the lone odd egg. I find I *don’t* want my window positions anything but what I last set them at. This includes mutlitple instances of the app displaying over each other. I also want an app to remember its last state (min/max/normal) and display in that state every time (or as many times) I open it.
>I must be the lone odd egg. I find I *don’t* want my window positions anything but what I last set them at.
Me 2.
Have never heard any complain about "usability problems" with this approach.
Agree with the comments about apps that don’t notice when you move from a multi-monitor set-up to a single screen.
I now am used to moving all apps back to the primary display before I shut them down as I can’t keep track of which ones do not handle this scenario well.
Walk the template header and do what it says.
"So the default should be to open apps in maximized state. Now that we have everything running maxed, it is good time to think how to make the experience better if you need to do work between the apps. The answer obviously is not to restore them to a smaller size to do some drag drop crap.
I would not be surprised if Apple has solved this already."
‘the answer to do some drag drop crap’ is obviously drag-and-drop the crap onto application button on the taskbar, which causes this application to be put in the front and then you can drop the crap in it wherever you like. On Windows, anyway… no idea how Apple has solved this, if at all.