Re: Find DesktopRegion in MFC VC++
- From: "Severian [MVP]" <severian@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 01 May 2005 07:45:09 GMT
On Sat, 30 Apr 2005 23:54:09 GMT, burt@xxxxxxxxxxxxxxxxx (Burt
Johnson) wrote:
>Severian [MVP] <severian@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>> This is a very common problem with applications; since rearranging my
>> two monitors, I still have to occasionally use Alt+Space, M and move a
>> window into the visible area.
>
>The PC didn't really support multiple monitors till XP, so I doubt it is
>in the programmers' psych to think of these things. We have had that
>support built into the Mac since about 1989, so I don't know any Mac
>application that does not support it just as a normal way of doing
>things.
Windows 98 supported multiple monitors, and I've used them on Windows
2000 since, well, about the year 2000.
There were some multi-monitor adapters that worked on NT4, but they
don't really count.
>I wasn't aware of that alt-space + M trick. Thanks for pointing it out.
>I have been rearranging the desktop, moving the app, then rearranging
>back to normal. If I booted on laptop without a second monitor at all,
>I thought I was simply out of luck.
My suggestion was for any app you write; perhaps a nice utility would
be a simple program that ensured all top-level windows were visible.
(However, some programs move windows to bizarre positions just to
ensure they aren't visible.)
>> My applications retrieve the desktop region and create a region from
>> the application window rectangle. If the intersection of these is not
>> the app window, then some part of the application is not visible, in
>> which case I place it at the default position.
>>
>> Unfortunately, I'm not very familiar with MFC, but you should be able
>> to use the CRgn (CRegion?) functions to do what you want.
>
>That sounds like a likely place to look. I'll check it out -- thanks!
Here's a portion of my non-MFC code:
/* pwp was read from my saved startup position */
void PlaceWindow(HWND hwnd, PWINDOWPLACEMENT pwp, UINT forceshow)
{
UINT s = pwp->showCmd;
WINDOWPLACEMENT wp2 = {sizeof(WINDOWPLACEMENT)};
HRGN hrgnWork = GetWorkAreaRegion();
GetWindowPlacement(hwndMain, &wp2); /* Get min/max positions; */
pwp->ptMaxPosition = wp2.ptMaxPosition; /* since we don't save */
pwp->ptMinPosition = wp2.ptMinPosition; /* those. */
if (forceshow) /* Ignore pwp->showCmd */
pwp->showCmd = forceshow;
else if (pwp->showCmd == SW_MINIMIZE
|| pwp->showCmd == SW_SHOWMINIMIZED
|| pwp->showCmd == SW_SHOWMINNOACTIVE)
s = pwp->showCmd = (pwp->flags & WPF_RESTORETOMAXIMIZED)
? SW_MAXIMIZE : SW_NORMAL; /* Don't open minimized */
if (IsRectEmpty(&pwp->rcNormalPosition)/* Ensure wind is visible */
|| !RectInRegion(hrgnWork, &pwp->rcNormalPosition)) {
if (MonitorCount() > 1)
GetMonitorRect(0, &pwp->rcNormalPosition, FALSE);
else
GetFullWorkArea(&pwp->rcNormalPosition, FALSE);
}
SetWindowPlacement(hwndMain, pwp);
pwp->showCmd = s;
DeleteObject(hrgnWork);
}
This application runs from Win95->Win2k3, so I use multimon.h to
simulate multi-monitor calls on systems that don't support
multi-monitor APIs. A couple of routines I call above may need
additional explanation; ask here or email me at (severian at severian
dot org) if you have any questions.
GetWorkAreaRegion() is probably the most important, so I'll show it
here:
HRGN GetWorkAreaRegion(void)
{
HRGN hrgn, hrgn2;
int i;
hrgn = CreateRectRgn(0, 0, 0, 0);
for (i=0; i<monitor_count; i++) {
hrgn2 = CreateRectRgnIndirect(&moninfo[i].rcWork);
CombineRgn(hrgn, hrgn, hrgn2, RGN_OR);
DeleteObject(hrgn2);
}
return hrgn;
}
IIRC, I build moninfo[] and monitor_count on program startup and when
I receive certain system messages.
There may be much simpler ways to do things, but my need for
compatibility with so many O/Ses and configurations makes my code a
bit complex.
Googling for multimon.h may be quite helpful as well.
--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.
.
- Follow-Ups:
- Re: Find DesktopRegion in MFC VC++
- From: Burt Johnson
- Re: Find DesktopRegion in MFC VC++
- References:
- Re: Find DesktopRegion in MFC VC++
- From: Severian [MVP]
- Re: Find DesktopRegion in MFC VC++
- From: Burt Johnson
- Re: Find DesktopRegion in MFC VC++
- Prev by Date: Re: Visual C++ project when runs consumes 1MB/Sec
- Next by Date: Re: How much oop is too much oop?
- Previous by thread: Re: Find DesktopRegion in MFC VC++
- Next by thread: Re: Find DesktopRegion in MFC VC++
- Index(es):
Relevant Pages
|