Finding Desktop region in MFC

I am working on a commercial application, and recently discovered a bug
I have been asked to fix (they threw it back in my lap).  

Run the application on a 2-monitor system, such as a laptop in a dock
with an external monitor.  Drag the main window to the second
(non-taskbar) window and quit.  Now move the laptop to a different dock
with the second menu on the other side (or without a second monitor at
all) and launch the app.

Oops.  The app continues to want to go on the side it was last put, even
though there is now no monitor there. (Yes, my dock in the office and at
home have the second monitor on the opposite side, which is how I found
the problem.)

On the Macintosh, there is a concept of a "desktop grey region" that can
be gotten, and an intersection of any particular window done.  If the
two do not intersect, the program knows to move to the main window.  I
am pretty sure the same concept exists in MFC, as I see Excel and
Outlook doing this switch when I move from office to home.

How do I go about getting that region in MFC, and how do I ask the
intersection with my window that I just opened?

As you can probably tell, I'm pretty new to MFC. Just completed my 4th
week using it... :-)


-- 
- Burt Johnson
  MindStorm, Inc.
  http://www.mindstorm-inc.com/software.html
0
burt1 (32)
4/30/2005 6:17:37 PM
vc.mfc 33608 articles. 0 followers. Follow

7 Replies
487 Views

Similar Articles

[PageSpeed] 45

On Sat, 30 Apr 2005 18:17:37 GMT, burt@mindstorm-inc.com (Burt
Johnson) wrote:

>I am working on a commercial application, and recently discovered a bug
>I have been asked to fix (they threw it back in my lap).  
>
>Run the application on a 2-monitor system, such as a laptop in a dock
>with an external monitor.  Drag the main window to the second
>(non-taskbar) window and quit.  Now move the laptop to a different dock
>with the second menu on the other side (or without a second monitor at
>all) and launch the app.
>
>Oops.  The app continues to want to go on the side it was last put, even
>though there is now no monitor there. (Yes, my dock in the office and at
>home have the second monitor on the opposite side, which is how I found
>the problem.)
>
>On the Macintosh, there is a concept of a "desktop grey region" that can
>be gotten, and an intersection of any particular window done.  If the
>two do not intersect, the program knows to move to the main window.  I
>am pretty sure the same concept exists in MFC, as I see Excel and
>Outlook doing this switch when I move from office to home.
>
>How do I go about getting that region in MFC, and how do I ask the
>intersection with my window that I just opened?
>
>As you can probably tell, I'm pretty new to MFC. Just completed my 4th
>week using it... :-)

Some applications (Internet Explorer for example) remember their
position on shutdown and position the main window in the same position
on startup. You need to write code to do the same, in that code you
will need to take into account the *actual* desktop size.
0
code4u (9)
5/1/2005 4:27:23 AM
Code4u <code4u@gmail.com> wrote:

> Some applications (Internet Explorer for example) remember their
> position on shutdown and position the main window in the same position
> on startup. You need to write code to do the same, in that code you
> will need to take into account the *actual* desktop size.

Yes, that code has been in place for years.  I am working on version 10
of a commercial application that sells in the millions of units.

The issue here is multiple monitors, where the user positions the window
on a second monitor then later launches the app and that monitor does
not exist.  This never happened prior to XP, because Windows never
formally supported multiple monitors before.  Now with laptops and
docks, this kind of thing is quite possible.

So... the question, as I said before, is how to find the desktop region,
and how to find out if the position the window wants to open would not
be visible.

A search on MSDN brought up reference to HMONITOR and Device Context:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/mon
itor_7gc4.asp

That looks like the most likely approach to pursue tomorrow when I look
at the code again.  If anyone has any other advice, I'd like to hear it
though.

-- 
- Burt Johnson
  MindStorm, Inc.
  http://www.mindstorm-inc.com/software.html
0
burt1 (32)
5/1/2005 4:57:37 AM
Burt Johnson wrote:
> So... the question, as I said before, is how to find the desktop region,
> and how to find out if the position the window wants to open would not
> be visible.

See the GetSystemMetrics API.  Parameters of this function will give you 
the primary monitor size and virtual desktop size.  Compare them with 
GetWindowRect of your main window to decide if the window would be on 
screen.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
5/1/2005 12:27:00 PM
Scott McPhillips [MVP] <org-dot-mvps-at-scottmcp> wrote:

> Burt Johnson wrote:
> > So... the question, as I said before, is how to find the desktop region,
> > and how to find out if the position the window wants to open would not
> > be visible.
> 
> See the GetSystemMetrics API.  Parameters of this function will give you
> the primary monitor size and virtual desktop size.  Compare them with
> GetWindowRect of your main window to decide if the window would be on
> screen.

Thanks! That sounds like the procedure I was looking for.

-- 
- Burt Johnson
  MindStorm, Inc.
  http://www.mindstorm-inc.com/software.html
0
burt1 (32)
5/1/2005 4:46:32 PM
On Sun, 01 May 2005 04:57:37 GMT, burt@mindstorm-inc.com (Burt
Johnson) wrote:

>So... the question, as I said before, is how to find the desktop region,
>and how to find out if the position the window wants to open would not
>be visible.

Sorry Burt but your question seemed somewhat muddled ("desktop grey
region"??). GetSystemMetrics is a standard API for this sort of thing,
alternatively you could get the desktop's window handle using
GetDesktopWindow() and go from there. This is pretty basic stuff, I'm
not trying to sound condescending, but since you're working on such an
important application, have you considered first working through a
Windows MFC/Win32 book? The Prosise book is a good one:

http://www.amazon.com/exec/obidos/tg/detail/-/1572316950/103-5341690-8470216?v=glance

Good luck!
0
code4u (9)
5/1/2005 6:47:07 PM
Code4u <code4u@gmail.com> wrote:

> On Sun, 01 May 2005 04:57:37 GMT, burt@mindstorm-inc.com (Burt
> Johnson) wrote:
> 
> >So... the question, as I said before, is how to find the desktop region,
> >and how to find out if the position the window wants to open would not
> >be visible.
> 
> Sorry Burt but your question seemed somewhat muddled ("desktop grey
> region"??). GetSystemMetrics is a standard API for this sort of thing,
> alternatively you could get the desktop's window handle using
> GetDesktopWindow() and go from there. This is pretty basic stuff, I'm
> not trying to sound condescending, but since you're working on such an
> important application, have you considered first working through a
> Windows MFC/Win32 book? The Prosise book is a good one:
> 

Sorry, "desktop grey region" is the term used in Macintosh programming
to get the region that is the union of all the monitor rectangles.
Didn't know what else to call it.

This call sounds like what I was looking for. Thanks.

Also, thanks for the pointer to the book. I have just placed an order
for it.  One of my confusions in this whole project is that I was told
originally I would be writing C# in .NET environment.  I thus bought
several .NET books.

Then, a couple days after I joined, they said they had another urgent
problem first, and put me on a fixing some broken code on older modules,
using VC++. Since the IDE was still Microsoft .NET, I went for a couple
weeks trying to figure out why my books on managed code weren't making
any sense.  It is only in the last couple weeks that I have discovered
that managed and unmanaged code are different worlds, and that I am
really in the older MFC world.

Very confusing introduction to this stuff. :-)  I've programmed for 35
years, going from punch card Fortran to assembly (MC6800) to Pascal to C
(Mac & Unix) to C++ (Mac) to Java (Mac & PC), and now to whatever wierd
mixed environment I am in now.  I've been there a month and am just
figuring out which way is up...

-- 
- Burt Johnson
  MindStorm, Inc.
  http://www.mindstorm-inc.com/software.html
0
burt1 (32)
5/1/2005 10:41:05 PM
On Sun, 01 May 2005 22:41:05 GMT, burt@mindstorm-inc.com (Burt
Johnson) wrote:

>Code4u <code4u@gmail.com> wrote:
>
>> On Sun, 01 May 2005 04:57:37 GMT, burt@mindstorm-inc.com (Burt
>> Johnson) wrote:
>> 
>> >So... the question, as I said before, is how to find the desktop region,
>> >and how to find out if the position the window wants to open would not
>> >be visible.
>> 
>> Sorry Burt but your question seemed somewhat muddled ("desktop grey
>> region"??). GetSystemMetrics is a standard API for this sort of thing,
>> alternatively you could get the desktop's window handle using
>> GetDesktopWindow() and go from there. This is pretty basic stuff, I'm
>> not trying to sound condescending, but since you're working on such an
>> important application, have you considered first working through a
>> Windows MFC/Win32 book? The Prosise book is a good one:
>> 
>
>Sorry, "desktop grey region" is the term used in Macintosh programming
>to get the region that is the union of all the monitor rectangles.
>Didn't know what else to call it.
>
>This call sounds like what I was looking for. Thanks.
>
>Also, thanks for the pointer to the book. I have just placed an order
>for it.  One of my confusions in this whole project is that I was told
>originally I would be writing C# in .NET environment.  I thus bought
>several .NET books.
>

Yep, Microsoft has done a fine job of confusing the hell out of
everyone with their .Net marketing. From what you've told us, you're
maintaining an MFC application; MFC is an unmanaged framework although
there's no reason why you can't mingle managed C++. Despite the hype,
the only feasible way to implement a large Windows desktop application
is MFC, it's an old piece of technology that has stood the test of
time surprisingly well. If you need to get under the hood and modify
the default behavior of MFC, or if you merely want to understand the
guts, then run, don't walk and pickup "MFC Internals":

http://www.amazon.com/exec/obidos/tg/detail/-/0201407213/qid=1114992096/sr=8-1/ref=sr_8_xs_ap_i1_xgl14/103-5341690-8470216?v=glance&s=books&n=507846

My copy has paid for itself many times over. One last piece of advice,
many high quality libraries have been built to extend MFC. Unless what
you are trying to do is domain specific, the chances are good that an
implementation already exists. I've been using the Codejock library
for quite a while, it's has some great GUI components, is very easy to
use (inherit from their base class) and is well supported. I have no
connection with these guys other than being a happy customer

www.codejock.com
0
code4u (9)
5/2/2005 12:12:54 AM
Reply:

Similar Artilces:

How can I find career change resumes templates?
I like to review some nice "Professional Career Change Resume Templates" for the job market. If someone could tell me where to go on the inter-net, it will be well appreciated. Thanks! You could start at www.google.com "Mike" <Mike@discussions.microsoft.com> wrote in message news:705F99E5-1326-4E81-B98F-A7337C5C9AEA@microsoft.com... :I like to review some nice "Professional Career Change Resume Templates" for : the job market. If someone could tell me where to go on the inter-net, it : will be well appreciated. Thanks! Templates are...

Find and replace 03-04-10
I'm trying to scan a field in one of my tables and find a specific character and remove it. However, the character is a " so I'm having difficulty. The field I speak of of contains the sizes of our material so the values look like this: 1/4" 1/2" 1/3" and so on. How can I find all of the " in my feild and remove them? I don't want to replace them I just want to remove them. Thanks, Chris Savedge Create a query, and in the Criteria row under the problem field, enter: Like "*[""]*" -- Allen Browne - ...

Lookup/Find help
Windows XP Professional Office 2000 Hypothetical, but hopefully you'll get the gist of it: I have two worksheets. On worksheet #1, I have two columns. First column is a list of entire workgroup by name and 2nd column is the hours worked. On the second worksheet I simply have an list of names that is a subgroup of those on the first page. These indicate a target group. EXAMPLE Worksheet #1 Sam 35 Joe 37 Mary 20 Beth 41 Ted 38 Worksheet #2 Joe Beth Now, on the first worksheet, I want to add a third column for summing only the target workgroup. Basically, I need a function...

How to spwan(in MFC)?
how to spwan??? Hello, WinExec() system() ShellExecute[Ex]() CreateProcess() Regards, Elias http://www.codeproject.com/system/newbiespawn.asp -- Regards, Nish [VC++ MVP] "�Ϲο�" <fuerza@kebi.com> wrote in message news:bh79mv$m1n$1@news1.kornet.net... > how to spwan??? > > ...

can't find normal.dot
Version: 2004 Operating System: Mac OS X 10.4 (Tiger) Processor: Power PC Hello, I need to delete my normal.dot file and I can't find it anywhere. I've had to do this before and I was able to find it in the templates folder, but I guess an update or two has changed that. Can anyone tell me where to find it? Spotlight says that it doesn't exist. But I have to be able to delete it. Is it called something different now? If you're using Spotlight & searching for "Normal.dot" it's no wonder it isn't being found - that isn't the correct name :-) it's ...

Finding maximum value
Hello, I want to find the maximum value in a column, but I want to ignore the negative and positive part of the value. Basically, the maximum difference from zero. Example: the maximum value I am looking for will be -0.467. -0.467 0.345 -0.253 0.411 Thanks Ruan One way (array-entered: CTRL-SHIFT-ENTER or CMD-RETURN): =INDEX(A1:A4,MATCH(MAX(ABS(A1:A4)),ABS(A1:A4),FALSE)) In article <OGKhnF1KEHA.2100@TK2MSFTNGP10.phx.gbl>, "Ruan" <ruan@aegismed.com> wrote: > Hello, > > I want to find the maximum value in a column, but I want to ignore the > negati...

How do I find the inside page in the 3-panel brochure.
I am trying to make a 3-panel brochure and all that seems to be available is the side shown in the brochure options. When I print, it prints both sides yet I can see no way to access the inside part. Thanks. View, status bar... this will allow you to change page views, you will see the page tabs at the bottom of the screen. I am not sure I know what you are asking. Are you saying you are printing the brochure sight unseen? -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "springmtn" <springmtn@discussions.microsoft.co...

Find a multiple photos on a page template for Publisher?
Possible to find a template for Publisher to print a page full of multiple photos without recreating the page each time I print. Why not save your page you have created as a template? File, "save as", files of type, scroll down to Publisher template. -- Mary Sauer http://msauer.mvps.org/ "srfaith" <srfaith@discussions.microsoft.com> wrote in message news:157E95AB-1159-4889-B196-61E147E6E240@microsoft.com... > Possible to find a template for Publisher to print a page full of multiple > photos without recreating the page each time I print. ...

Outlook Desktop Client Error
Hi, I have installed desktop client on my system.It has been installed successfully.While opening the outlook it is showing some errors like error while loading Crm functionality. CRM server is unavailable, try again later. This is my system configuration Windows 2003 server standard edition MS office 2003 with SP2 Previously it was working fine. The errors are 1.There is a problem communicating with the Microsoft CRM server.The server might be unavailable. Try again later.If the problem persists,contact system administrator. 2. An error occured loading CRM functionality,try restarting ...

getting rid of the standard mfc icon (in taskbar)
i made an application based on mfc, and used the standard mfc icon up until now. i thought changing it would be a simple task. in the resource editor i got rid of all mfc icons in various resolutions, and replaced it with my own icon in 3 different resolutions. it does work in almost all the places: the main window is shown with the correct icon, the taskbar shows correctly with the icon, even MessageBox() shows the icon now, but as soon as i do open a MessageBox while my main-window is shown, the counter in taskbar moves up to two (you know how windows xp groups together tasks with th...

Finding Desktop region in MFC
I am working on a commercial application, and recently discovered a bug I have been asked to fix (they threw it back in my lap). Run the application on a 2-monitor system, such as a laptop in a dock with an external monitor. Drag the main window to the second (non-taskbar) window and quit. Now move the laptop to a different dock with the second menu on the other side (or without a second monitor at all) and launch the app. Oops. The app continues to want to go on the side it was last put, even though there is now no monitor there. (Yes, my dock in the office and at home have the second ...

Performance counter for Outlook Finds?
What server performance counters (if any) are there for monitoring the number of "Find" requests that Outlook clients make? -GT ...

finding calendar and data info
I had to move my primary hard drive into another computer. It is now running as a slavein the new computer. I'm unable however, to find my calendar and contacts from Outlook 2003 when I open the program on the new computer. If I attempt to open the program from the F drive (the drive assigned in the new computer to the hard drive that was moved from another computer) it tells me the program is not installed. If I open Outlook 2003 from the C drive of the new computer, of course, it doesn't find the old calendar and contacts. I would appreciate any and all assistance in findin...

Conditional Formatting VBA with formula to find string
Hi, Please can I get some help.... I need to create a conditional format VBA in Excel 2007 (because I have many conditions to include) and I don't know how to do it... The Action Required: If Product A appears in any text string in range($C$95:$C$300) then colour that cell RED, if Product B appears anywhere in a text string within range($C$95:$C$300) then colour that cell BLUE, if Product B appears anywhere in a text string within range($C$95:$C$300) then colour that cell GREEN, and so on through 41 products... Data - I have a list of about 41 Product names in range Z...

Using sdk to find out if an Account already exists
Hi, Want to use sdk to see if an Account already exists , all i have is its name. I've looked at Retrieve method but it requires the Guid. Any equivalent call to Retrieve that just takes name? Or a way to get the Guid from the name? Sample code would be great if available. Thanks for all help. John Hi John, The method you are looking for is RetrieveMultiple as only the guid search gives the certainty to retrieve only one record. All explanations are in the sdk but as the sdk sample is nearly the exact code you want, here it is : // Set up the CRM Service. CrmService service =3D new ...

Find number of weekdays and wekend days given a total number of da
Hello, I have a question for the gurus here. I am working on a spreadsheet where in column A I have Total # of Vacation days. Example: # Vac Days --- # Weekdays --- # Weekend days 75 55 20 44 32 12 25 19 6 I figured this out by simply creating a list like this 1 Weekday 2 Weekday 3 Weekday 4 Weekday 5 Weekday 6 Weekend 7 Weekend And so on... And then doing a countif to figure out how many of either on...

Doesn't find files w/spaces in name
There are a lot of folders and Excel spreadsheets on our shared drive that I need to open. Most of the folders and file names are named like: get reports\reports sep 2004.xls When I try to open one, Excel doesn't find it and I think it's because there are spaces in the folder names and/or file names. Is there a setting in Excel that will help me get around this? This was working until I had a glitch in Excel and the technician fixed the glitch and this problem appeared. Any help would be appreciated. I found an answer and so far it works. "C:/program files/microsoft off...

SQL statement to find a particular column within all tables
I am looking for a query that will allow me to find all instances of a particular column within all tables so I know where they are all located. Does anyone have such a query they would be willing to share? Thank you. Pam, I posted this query a few months aback on my blog (http://dynamicsgpblogster.blogspot.com/2008/03/in-past-days-i-have-found-lot-of-people.html), but here is the excerpt: select distinct rtrim(objs.name) from syscolumns cols inner join sysobjects objs on (cols.id = objs.id) inner join sysindexes indx on (cols.id = indx.id) where (cols.name = 'ACTINDX') and (ob...

CAsyncSocket()::OnReceive() will not be fired !!! -> MFC BUG ?!?
Hello peoples i have wrotten a FTP-Client with a own Class of CAsyncSocket. Sometime the messagge from the Server will NOT BE reveiced, but the server have ben sendet to the Client ( the OnReceive() of the Client is not called !!) I use MSVS6.0 OR can´t use the CAsyncSocket for a FTP-Client ? ( the CInternetConnetion can´t use, why i need ALL sended and received data for displaying regard Nico van Halobar Nico van Halobard wrote: > Hello peoples, > > i have wrotten a FTP-Client with a own Class of CAsyncSocket. Sometime the messagge from the Server will NOT BE revei...

Accessing desktop shortcuts when programs are running
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: intel Is there any way to toggle between program windows and the desktop so that you can access the shortcut icons there without resizing or minimizing your program windows? It would be great to be able to do this, especially when I have four or five word documents open . . . Thanks! You can use the ApplicationName> Hide ApplicationName or Hide Others command to hide the window(s) to access the Desktop - assuming you don't have any other application windows open. However, you might want to explore other more effective...

find
How can I setup a macro or use a function to find a column who's first cell is called "Addresses" then move the whole column to sheet 2. Is it possible? Puzzled J, If there is only one cell with the word "Addresses" in it: Sub MoveAddresses() Cells.Find("Addresses").EntireColumn.Cut Worksheets("Sheet 2").Range("IV1").End(xlToLeft)(1,2) End Sub This will put the column into the column with the first free cell in row 1 of Sheet 2. HTH, Bernie MS Excel MVP "J Bates" <newss@pittam.plus.com> wrote in message news:4507...

Newbie Remote Assistant and Desktop Questions
i Folks: Developing C++ on VS 2008 Pro, XP Pro, Win32. I have a client that recently upgraded from Vista to Windows 7 Ultimate, 32 bit, on his laptop. I recommended he get Ultimate so I could run Remote Desktop over the Internet. This is before I actually tried using Remote Desktop. After getting Remote Desktop up, I see that I really want, to help my client, is Remote Assistant. Both Remote Desktop and Remote Assistant are now running fine with two XP PCs on my LAN, using my Internet address, to connect. I've cobbled together port numbers requiring...

MFC Resource Language Translation?
Hi All, I need translate my MFC application into a variety of different languages. The problem is my app has a lot of different dialogs all of which are heavily text labelled. Is there anyway to export all of the text in the app to a RTF file? Any suggestion gratefully received! Kind Regards Andrew I don't know about RTF, but my Polish translator swears by WordTrans (http://www.wordtrans.co.uk/content/home.asp) whereas my Spanish/Portuguese translators use Catalyst (http://www.alchemysoftware.ie/). From my point of view, the latter translates the resource DLL files, so everything ...

Finding/deleting macros...
Thanks to anyone who helped me with my finding/deleting link question... Now in a different workbook.. when i open it, it prompts whether t enable or disable macros. When i go to the macros list though, it blank, none listed. How could I find where thesee phantom macros ar and get rid of them? FYI we always choose Disable macros. This is work book that was built a long time ago, probably has about 50+ tab of which we only currently use about 15. Thanks for any help! Chri -- Message posted from http://www.ExcelForum.com Hi you also have to remove the modules: - open the VBA editor (hi...

In Excel how do I find unformatted shapes that are invisible?
I am sent an Excel spreadsheet each week that I copy and paste and add to a main worksheet. The size of the file is getting huge. I discovered the reason for the size is the many unformatted shapes in this file. I would like to delete them. The problem is because they are unformatted, they are invisible. I only know they are there because I happened upon them accidently. Is there way to make all these visible so I can delete them one at a time? Or a way to delete all of them all at once? Hi Not sure if I understand but try this : in Excel 2003 or older... Go to Edit > ...