Re: Find DesktopRegion in MFC VC++



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.
.



Relevant Pages

  • Re: Name change
    ... Four processors, two monitors, gigabit Ethernet, and nearly 900GB ... size - but I've got a 17" CRT screen that's about 2.5" higher than the ... `across two screens' - just to be able to work on both, ... Dali-esque windows too ...
    (uk.people.support.depression)
  • Re: How do I do 3 monitors?
    ... to run two monitors from a single computer. ... > I did find out that the display adapter (PCI card) was on the Microsoft ... >> You can use several secondary display adapters in Windows XP, ... >> Windows XP as secondary display adapters. ...
    (microsoft.public.windowsxp.general)
  • Re: Terminating an external application (.exe)?
    ... I have an application that run's 3 other applications and monitors them ... If your monitor also starts the application it monitors you already have the ... You did not tell use whether the monitored applications have windows or not. ... this is a 3rd-party app. ...
    (borland.public.delphi.language.objectpascal)
  • Re: Desktop shortcuts rearranged automatically with restart
    ... Thank you, Ramesh. ... Switch to Registry Editor window, and navigate to the following key: ... Restart Windows and see if the icon positions are retained. ... Very often when I restart the pc (where monitors are still ...
    (microsoft.public.windowsxp.general)
  • Re: ComboBox DropDown Size: Design vs Run Time?
    ... Windows will actually draw a dropdown list that's larger than ... No, I've not extended the code to support multiple monitors, but you're right, I should do ... need the extra code and I think it does exactly what you wish. ...
    (microsoft.public.vc.mfc)