Getting size of "window" in OnDraw()

I finally found a (seemingly) reliable way to get the size of the "window"
for both the screen & a printed page by doing this in CMyView::OnDraw( CDC
*pdc):

 if( pdc->IsPrinting() )
      {
      hRes = pdc->GetDeviceCaps( HORZRES );
      vRes = pdc->GetDeviceCaps( VERTRES );
      rectContext = CRect( CPoint( 0 , 0 ) , CPoint( hRes , vRes ) );
      }
 else
      {
      GetClientRect( &rectContext );
      hRes = rectContext.Width();
      vRes = rectContext.Height();
      }
 nRows = vRes / rowHeight;

I'm doing this because GetDeviceCaps() for the screen returns the size of
the whole screen, not the program's client area, and using GetClientRect()
returns the size of the screen client area even when the context pdc is a
printer.

My question is:  Is there a single method that works for both contexts that
I've overlooked?

    TIA
        Norm


0
ndrez (136)
8/3/2003 1:05:15 AM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
1286 Views

Similar Articles

[PageSpeed] 5

Hi Norm,

I think there is no such general function used for printer and screen.
 As the MSDN said,
The GetDeviceCaps function retrieves device-specific information for the 
specified device.
int GetDeviceCaps(
  HDC hdc,     // handle to DC
  int nIndex   // index of capability
);
HORZSIZE Width, in millimeters, of the physical screen. 
VERTSIZE Height, in millimeters, of the physical screen.
Which means that the return value is physical device-specific information. 
If the hdc is a printer, the return value is the Width of the printable 
rectangle, which is concern about the printer device. If the hdc is a 
display, the return value is the width of the physical screen.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons
_88s3.asp

The GetClientRect function retrieves the coordinates of a window's client 
area.
BOOL GetClientRect(
  HWND hWnd,      // handle to window
  LPRECT lpRect   // client coordinates
);
which means that the return value is logical information.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui
/windowsuserinterface/windowing/windows/windowreference/windowfunctions/getc
lientrect.asp

I think your code is good when you need to get the printable size on the 
printer and the drawing size on the CView window.

Regards,
Peter Huang 
Microsoft Online Partner Support 
Get Secure! www.microsoft.com/security 
This posting is provided "as is" with no warranties and confers no rights. 


--------------------
>From: "Norm Dresner" <ndrez@att.net>
>Newsgroups: microsoft.public.vc.mfc
>Subject: Getting size of "window" in OnDraw()
>Lines: 30
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
>Message-ID: <fdZWa.85307$0v4.5709021@bgtnsc04-news.ops.worldnet.att.net>
>Date: Sun, 03 Aug 2003 01:05:15 GMT
>NNTP-Posting-Host: 12.91.172.87
>X-Complaints-To: abuse@worldnet.att.net
>X-Trace: bgtnsc04-news.ops.worldnet.att.net 1059872715 12.91.172.87 (Sun, 
03 Aug 2003 01:05:15 GMT)
>NNTP-Posting-Date: Sun, 03 Aug 2003 01:05:15 GMT
>Organization: AT&T Worldnet
>Path: 
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!newsfeed.cwix.co
m!feed2.news.rcn.net!rcn!wn14feed!worldnet.att.net!bgtnsc04-news.ops.worldne
t.att.net.POSTED!not-for-mail
>Xref: cpmsftngxa06.phx.gbl microsoft.public.vc.mfc:385534
>X-Tomcat-NG: microsoft.public.vc.mfc
>
>I finally found a (seemingly) reliable way to get the size of the "window"
>for both the screen & a printed page by doing this in CMyView::OnDraw( CDC
>*pdc):
>
> if( pdc->IsPrinting() )
>      {
>      hRes = pdc->GetDeviceCaps( HORZRES );
>      vRes = pdc->GetDeviceCaps( VERTRES );
>      rectContext = CRect( CPoint( 0 , 0 ) , CPoint( hRes , vRes ) );
>      }
> else
>      {
>      GetClientRect( &rectContext );
>      hRes = rectContext.Width();
>      vRes = rectContext.Height();
>      }
> nRows = vRes / rowHeight;
>
>I'm doing this because GetDeviceCaps() for the screen returns the size of
>the whole screen, not the program's client area, and using GetClientRect()
>returns the size of the screen client area even when the context pdc is a
>printer.
>
>My question is:  Is there a single method that works for both contexts that
>I've overlooked?
>
>    TIA
>        Norm
>
>
>

0
v-phuang (38)
8/4/2003 11:34:36 AM
Reply:

Similar Artilces:

Losing email in Windows live mail on Windows 7
I am losing some emails that come into my mailbox. I can read it in the Quick View "Unread emails" view but it does not show up in my Inbox or in any other folders. Open that inbox folder, than click View, Show or hide, Show all = messages. If you don't see the View button, press Alt first. --=20 Gary VanderMolen, Microsoft MVP (Mail) Microsoft MVP program: http://mvp.support.microsoft.com "Virgil" <Virgil@discussions.microsoft.com> wrote in message = news:19D2BA1C-BBF4-4E10-8CDC-6BC3406D2E77@microsoft.com... >I am losing some emails that ...

RMS 2.0/Windows Permissions Error
Good Morning Everyone, I have a question for the group. I have a customer running RMS 2.0, pre SP2 on Windows XP. The customer is trying to lock down his cashiers from installing unauthorized software and other such abuses on the computers. Here is the problem. When locked down he is getting the error: "Server Failure 139: A server failure occurred while attempting to read the register." This error only happens as the POS and goes away when the user is added as a local administrator. I am fairly confident this is a problem with permissions regarding licensing or OPOS, bu...

modeless message window in a regular dll?
Hello community, I have written a regular dll that should just show a status window. The problem is that I have no control over the application calling the dll. The application should not be aware of the status window. The window should just be modeless (it shouldn't block *any* application GUI) and it should show a status message. If possible, it should have a Close button. The dll uses a worker thread for requests from the application and it uses a UI thread for socket operations. Note that I use MFC in the dll (which could make it more comfortable to create the window - or - on the ot...

How to change background color of a window that has been created.
I need to change the background of a window that has been created, can you help? Hello Jerry, > I need to change the background of a window that has been created, can > you help? > Answer depends upon the type of window. Typically you can do this in OnEraseBkgnd. Certain controls respond to WM_CTLCOLOR and yet some other, like CButton, need to be owner drawn to change the color. If you have a generic CWnd, you can always specify the brush in the window class; so no special painting is needed. This is good when you know that the background will have one color all the time. -...

Overlapped/Hidden window?
Is there any way to find out that one window(Static text)is overlapped/hidden by other(ComboBox)? ...

Problems with Publisher 2000 and Windows 2000
One of my clients started having problems with Microsoft Publisher 2000 last week. Whenvever she tries to run it on her Windows 2000 box, Windows installer comes up and asks her to insert her office CD, she does, and then she receives an error message saying "The installation source for this product is not available." She is an administrator of her own machine, but ironically, the user "administrator" can run publisher without any problem. I have had this problem with the first disk of Office 2000 in the past, and microsoft was able to resolve it by sending a pr...

windows 7 pro 64bit installing 32bit app
i am installing a 32 bit app on a 64 bit win7 platform it registers regsize32.ocx in the install but when i try and load the app it fails on that file and i can not run regsvr32 as the file is not present where does win7 place 32 but drivers like program files x86 You will find the 32bit version of regsvr32 at c:\windows\syswow64. The ocx might be in the same folder as regsvr32 or could be in the folder where you installed the app (\program files(x86)). "Stuart Macleod" <StuartMacleod@discussions.microsoft.com> wrote in message news:A82A204E-43C3-4BB6-9691-6DB4...

MS Outlook 2002 Running in Windows 98
I just changed to a new ISP. The ISP walked me through setting up an email account for their site. I no longer have a send button. I also can't see Send/Receive under Tools. I have looked and looked to no avail. Any suggestions would be appreciated. Thanks. Abby Abby, Try resetting your toolbars to the default settings. Note that you will lose any customizations you've made to them, but I think it will let you get your "Send/Receive" button and menu item back. -- Regards, Chris Burnham Microsoft Exchange Support This posting is provided "AS IS" with no...

installing Windows Server SP2 onto SBS 2003 SP1
I have SBS 2003 SP1. I have been keeping up with all the windows updates for this machine and would like to update the machine to SP2. I had heard that if you try to update the SBS 2003 SP1 server to SP2, you need to unload a lot of the updates issued after the SP2 was submitted. Is this true? Hi Carl, This hasn't been my experience. And there is no SBS 2003 SP2. It's Windows 2003 SP2 installed on top of SBS 2003 SP1 (which already has Win2003 SP1 installed). Run the SBS 2003 BPA prior to the install of Win2003 SP2 to make sure you don't have an issues ...

Access 2007 Special Effect Text Box Won't show Sunken with Windows XP
Hi All I am just getting to grips with Access 2007 and one of the quirks I have found is that when I design using Windows in XP Windows-Classic colors and set the text boxes on forms' special effect property to "sunken" They appear as sunken in the correct manner. However, when I change to the Windows XP color scheme the forms text boxes appear flat even though the special effect property has not changed. Any ideas or is it a new quirk we have to live with. I haven't tried it with Vista yet. That should be interesting Thanks Bob I am quite sure this is the same for acce...

NewsMaestro Usenet Supertool v. 4.4.8 for Windows/Linux/Unix released
Download page: http://rapidshare.com/files/118192521/NewsMaestro_4.4.8_Src.zip (Hit Free button to download. For some download managers you need to open the .html file it downloaded to do actual download.) * Documentation update. * Bug fix in Archive 2 HTML generator while doing ReChapter. News Maestro is a power tool for usenet that automatically performs any standard Usenet operation, as specified in various RFCs, individually, or in bulk, on any number of groups and articles, utilizing sophisticated filters to select the articles to be processed. As an automated tool to do anything you...

windows media player fails
Yesterday I uploaded MVI_1138.AVI from my camera to my laptop. Then I played it (to see if it was good). Then I played it for guests twice more (so it must have been good). Today it will not play. WMP indicates that it does not recognize the file type. Any suggestions??? Charles ...

able to access the window but not interact with it
Hello: I ran across an interesting issue a couple of days ago with a Great Plains 8.0 client. This client does not have Field-Level Security nor does it have Modifier. The assistant business manager went into Batch Recovery to try to recover a payables computer checks batch. The batch would not post, since she did not enter control figures into the batch entry window. This is required per the Posting Setup window. Anyway, what was strange is that she could access this window but not see any batches in it. If I accessed Great Plains remotely and logged in as "sa", I coul...

IE 8 Won't open New Window or New Tabs in Server 2008 R2
The Situation: IE 8 won't open links in a new window or a new tab either through javascript or manually using the context menus. Page > New Window still works. Clicking the new tab interface button still works. A new process is opened for the new tab but it fails at 'connecting...' This is on a domain connected development workstation running Server 2008 R2 64-Bit. Accelerators turned off, ScreenFilter turned on. VB.NET 2010 Beta installed. Recent work on a project that involves the WebBrowser control. Java is 6.17. Forefront Client Security is installed. All upd...

Windows Update Agent 7.4.7600.226 11-25-09
Note: This question was posed to the vista.general group with no responses offered. My Dell Inspiron 1520 laptop with Windows Vista Home Premium has failed to load the subject update on 20 different occasions since 13Nov09. The "Error Details" is Code 80073712, which is nothing more than a general error code with no specific fixes recommended. I have also tried the manual workaround from the Window Help site as well as the Window Update Fix-It application to no avail. Anybody have an idea as to how to resolve this issue? I have found the following tool to be he...

multiple windows
I can't get multiple windows for my outlook, e.g. 1 window for my outlook today, and 1 for my inbox. But I can do that for the rest of the office applications like word and excel. Pls help. Thxs. BH. ...

Reply window size
Whenever I reply to a message, the window always maximizes, and the fonts change. I'm more concerned about just having the reply window stay teh regular size as the e-mail I am reading and replying to. Thanks. ...

OE with Windows 7?
I am about to buy a computer with Windows 7. I currently use Win XP and prefer to use Outlook Express. I find it available as a download on MS website. Will it install and run on Win 7? If not, they recommend Live Mail. Is it similar to OE. The OE feature I like best is the multiple identities. My friend has Vista with Mail. He has to log into his computer with a different identity anytime he wishes to send mail from a different identity. In OE you can simply click on file Switch Identities to do that. OE can not run on Win7. If you get the Pro or Ultimate edition,...

Integrating Excel with Windows Security
Hi, I have a potential job where I would have to create a relatively complex Excel workbook with some user controls (Command Buttons, List Boxes) and some VBA behind these controls. I will have to implement some form of security so that certain functions are only available to users with appropriate permissions. I know that I can lock and password protect individual cells in Excel. I was just wondering if there is any way I can take this a step farther and integrate it with Windows security. For example, if I have a Windows group named "Engineers", is there a wa...

windows themes not working AND no internet connect
windows themes not working AND no internet connect Every time the computer is started up, the xp theme (Luna) is the windows classic. I know how to start in up in the control panel, but it does not stay that way after shutdown. It can't connect to the internet, even if modem shows all lights working. Verizon has no prob in connection, could be modem issue itself. Spyware & Virus scans (using Verizon Internet Sec. Suite programs) came out clean. FYI- Slow at start up and shut down. Error msgs occur every time (possibly related to VISS). On May 30, 3:21=A0pm, "Ed...

Windows 2008 R2 standard or enterprise
Hi all, I am going to decide which version of windows 2008 R2 for my domain controller(around 1300 users). Which option do I need and then I have to choose windows 2008 R2 enterprise (clustering does not count)? Any RAIDUS cient limitation? certificate server? Thnak you. Hello ed, It doesn't matter if you use standard or enterprise edition for a DC itself, but you have some roles/features not available or complete, see here about the details, especially for CA: http://www.microsoft.com/windowsserver2008/en/us/r2-compare-roles.aspx http://www.microsoft.com/windows...

Storage Groups In Windows SBS 2003 R2 Premium
As I have writen above, I have Windows SBS 2003R2 Premium and would like to make 2 storage groups and then an mailbox storage in the second storage in the exchange, but I get an error massage: "The Storage group already contains the maximum number of storage allowed" ID No. c1034a7a. How do I get around that problem? Is it possible to sent from multiple domains that is running on the Exchange?? I thank you for the help! FlashBang wrote: > As I have writen above, I have Windows SBS 2003R2 Premium and would > like to make 2 storage groups and then an mailbox storage in t...

Using my Contacts from Windows Mail
Hello, I have Windows Vista and use Windows Mail. I have a full list of contacts in "C:/Users/Compaq/Contacts". When I work in Windows Mail and I click on the icon for Contact on the tool bar, I can see all my contacts. However, when I write an email, I click on Create Mail and then I click on the icon to the left "To:" in order to retrieve my contact list and none of my contacts are there. How can I access my "contacts" from Windows Mails ? Try this: Open the Default Programs applet, which you can access either from the Start menu or via the Control Panel...

Integrated Windows authentication OWA and Exchange active sync
I have found that Win 98, NT and VPN clients can not access OWA without turning off integrated windows a authentication in the security settings of the exchange virtual directory in the default website of IIS. That was really not a big deal for me until a bunch if execs signed a new cell phone contract and showed up with tre650's wanting to get e-mail on their phone (nothing like good technology planning). The treo650 is a palmOS-based smartphone and is capable of syncing calendar and phone info via exchange active sync. Of course it did not work straight out of the box. I came across a ...

Create a toplevel window
A hopefully trivial question. I have a normal MDI MFC-based application. Then I'd like to add another toplevel window, with a frame, which I draw into myself. Actually, it displays a bitmap. So I tried deriving a class from CWnd, and then from CFrameWnd. wnd = new CChildWnd(); // Derived from CWnd/CFrameWnd wnd->Create(0, "Program", WS_OVERLAPPEDWINDOW|WS_VISIBLE, CRect(100,100,300,300), 0); However I seem to have hooked it up wrong, as it won't draw anything. Any good examples on how to do this? I am sure I am missing some vital call, as it's not getting a...