VC 7.1: Preview DC

With Visual C++ MFC 7.1 when doing a print preview the Attribute HDC and 
the Output HDC of the CDC differ. Whenever a pen, brush or font is selected 
into this CDC via SelectObject an assert is triggered as the two HDC's do 
not match. This was never a problem using Visual C++ MFC 6.0.

Is there any way to get around this or am I missing something blindlingly 
obvious ?

Thanks,
Brett
0
knowbase (5)
11/18/2004 7:55:55 AM
vc.mfc 33608 articles. 0 followers. Follow

11 Replies
781 Views

Similar Articles

[PageSpeed] 31

Hi Brett,

For the conveniece to investigate this issue, would you please give us some 
code snippet to illustrate this problem? 


Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

0
v-garych (605)
11/19/2004 6:54:57 AM
Here is the offending code section from afxwin1.inl:

_AFXWIN_INLINE HGDIOBJ CDC::SelectObject(HGDIOBJ hObject) // Safe for 
NULL handles
	{ ASSERT(m_hDC == m_hAttribDC); // ASSERT a simple CDC object
		return (hObject != NULL) ? ::SelectObject(m_hDC, hObject) : 
NULL; }

Note the ASSERT.

Here is a section on Print Preview from the help file:

Print preview is somewhat different from screen display and printing 
because, instead of directly drawing an image on a device, the 
application must simulate the printer using the screen. To accommodate 
this, the Microsoft Foundation Class Library defines a special 
(undocumented) class derived from CDC, called CPreviewDC. All CDC objects 
contain two device contexts, but usually they are identical. In a 
CPreviewDC object, they are different: the first represents the printer 
being simulated, and the second represents the screen on which output is 
actually displayed.

Note the statement that the device contexts are different during a print 
preview.


v-garych@online.microsoft.com (Gary Chang[MSFT]) wrote in
news:PvJE3SgzEHA.2544@cpmsftngxa10.phx.gbl: 

> Hi Brett,
> 
> For the conveniece to investigate this issue, would you please give us
> some code snippet to illustrate this problem? 
> 
> 
> Thanks for your understanding!
> 
> Best regards,
> 
> Gary Chang
> Microsoft Online Partner Support
> 
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no
> rights. --------------------
> 
> 

0
knowbase (5)
11/22/2004 10:31:16 AM
Sorry for the late response, Brett,

> ...

The MFC code and the corresponding doc you referred is alright, by the way, 
how is your problem's code on using the CPreviewDC::SelectObject?


Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

0
v-garych (605)
11/25/2004 10:22:01 AM
In my document I have the following code which implements a pen and brush 
cache:

pDC->SelectObject(m_pens[m_lastColorSelected = foundPen]);
pDC->SelectObject(m_brushes[m_lastColorSelected]);

The pDC is passed in from the OnDraw in the view. In Print Preview in 
Debug mode there is an assert on both of those function calls. In normal 
redraw there is no assert.

If I have 10 calls to set pens then I have to click through 20 asserts in 
order to continue debugging. This is a major pain.

v-garych@online.microsoft.com (Gary Chang[MSFT]) wrote in
news:DM8Clit0EHA.3200@cpmsftngxa10.phx.gbl: 

> Sorry for the late response, Brett,
> 
>> ...
> 
> The MFC code and the corresponding doc you referred is alright, by the
> way, how is your problem's code on using the CPreviewDC::SelectObject?
> 
> 
> Thanks for your understanding!
> 
> Best regards,
> 
> Gary Chang
> Microsoft Online Partner Support
> 
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no
> rights. --------------------
> 
> 

0
knowbase (5)
11/26/2004 8:04:13 AM
>pDC->SelectObject(m_brushes[m_lastColorSelected]);

What's m_brushes - an array of HBRUSH?

I had a similar sounding issue, illustrated by this example:

void CPrevtestView::OnDraw(CDC* pDC)
{
	CPrevtestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
#if 1
	HBRUSH hBr;
	hBr = CreateSolidBrush( RGB( 128, 128, 128 ) );
	HBRUSH hOldBr = (HBRUSH) pDC->SelectObject( hBr );
	pDC->Rectangle( 10, 10, 110, 110 );
	pDC->SelectObject( hOldBr );
#else
	CBrush hBr;
	hBr.CreateSolidBrush( RGB( 128, 128, 128 ) );
	CBrush * hOldBr = pDC->SelectObject( &hBr );
	pDC->Rectangle( 10, 10, 110, 110 );
	pDC->SelectObject( hOldBr );
#endif
}

Build it as it as, and you'll get the ASSERT when you use print
preview. However if you change the #if to 0 and rebuild, the print
preview won't ASSERT.

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl7375 (2060)
11/26/2004 8:38:57 AM
Thanks David, that advice worked a treat.

I use an array of CPen and CBrush and was not passing pointers to 
SelectObject so the handle version of the function was being called.

Now I must just get past the problem of fonts as in the following example 
which also cause asserts in the Print Preview:

// get this font from the font cache
CFont *pFont = pDoc->getFont(workTextDef);
// Set the font
CFont *oldFont = pDC->SelectObject(pFont);
.....
.....
.....
// Reset the font
pDC->SelectObject(oldFont); // ASSERT in Print Preview

Thanks again for your input, saved me a lot of time !

David Lowndes <davidl@example.invalid> wrote in 
news:flqdq0haoh9u6oebk711ikr1h2shobt4c6@4ax.com:

>>pDC->SelectObject(m_brushes[m_lastColorSelected]);
> 
> What's m_brushes - an array of HBRUSH?
> 
> I had a similar sounding issue, illustrated by this example:
> 
> void CPrevtestView::OnDraw(CDC* pDC)
> {
>      CPrevtestDoc* pDoc = GetDocument();
>      ASSERT_VALID(pDoc);
> #if 1
>      HBRUSH hBr;
>      hBr = CreateSolidBrush( RGB( 128, 128, 128 ) );
>      HBRUSH hOldBr = (HBRUSH) pDC->SelectObject( hBr );
>      pDC->Rectangle( 10, 10, 110, 110 );
>      pDC->SelectObject( hOldBr );
> #else
>      CBrush hBr;
>      hBr.CreateSolidBrush( RGB( 128, 128, 128 ) );
>      CBrush * hOldBr = pDC->SelectObject( &hBr );
>      pDC->Rectangle( 10, 10, 110, 110 );
>      pDC->SelectObject( hOldBr );
> #endif
> }
> 
> Build it as it as, and you'll get the ASSERT when you use print
> preview. However if you change the #if to 0 and rebuild, the print
> preview won't ASSERT.
> 
> Dave

0
knowbase (5)
11/26/2004 12:32:29 PM
>Thanks David, that advice worked a treat.

Good :)

>Now I must just get past the problem of fonts as in the following example 
>which also cause asserts in the Print Preview:
>
>// get this font from the font cache
>CFont *pFont = pDoc->getFont(workTextDef);
>// Set the font
>CFont *oldFont = pDC->SelectObject(pFont);
>....
>// Reset the font
>pDC->SelectObject(oldFont); // ASSERT in Print Preview

Sorry, I've not come across that one. I can't think why it should be
asserting only in preview mode. When you find out, let us know!

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl7375 (2060)
11/26/2004 3:22:39 PM
Hi Brett,

Do you have worked out some results with the new problem?

Since I have tested the sample code snippet with a SDI application, and I 
don't get the assertion under the print preview scenario, so does your 
program have anything particular? 


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

0
v-garych (605)
11/30/2004 10:46:21 AM
Hi Brett,

Meantime, I also consult this problem with our internal experts, their 
opinion is that constraint only exists in SelectObject(HGDIOBJ), you can 
wrap your HGDIOBJ in an actual MFC type and it will be fine. 


Wish it helps!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

0
v-garych (605)
12/2/2004 1:40:17 AM
Hi Gary,

Thanks, that part was sorted out with help from David Lowndes. I was 
calling SelectObject(CPen) and not SelectObject(&CPen) so the HGDIOBJ 
version was being used.

I still have a problem with fonts but need to investigate a bit further.

Cheers,
Brett

v-garych@online.microsoft.com (Gary Chang[MSFT]) wrote in
news:81Uro$A2EHA.3984@cpmsftngxa10.phx.gbl: 

> Hi Brett,
> 
> Meantime, I also consult this problem with our internal experts, their
> opinion is that constraint only exists in SelectObject(HGDIOBJ), you
> can wrap your HGDIOBJ in an actual MFC type and it will be fine. 
> 
> 
> Wish it helps!
> 
> Best regards,
> 
> Gary Chang
> Microsoft Online Partner Support
> 
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no
> rights. --------------------
> 

0
knowbase (5)
12/2/2004 5:07:58 AM
> I still have a problem with fonts but need to investigate a bit further.

OK, Brett, If you need any other help, please feel free to post here.


Good Luck!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

0
v-garych (605)
12/2/2004 9:14:18 AM
Reply:

Similar Artilces:

HELP! #7
After trying to handle some files that were just too big - the server was kind enough to sweep them away. Now I have two messages in my out box. One of them -to my wife fortunately, has been sent to her about ten times, yet remains in my out box. When I try to delete them, I receive an error window telling me I can not do so due to an unknown error - and that I should restart outlook (which I've done upwards of a dozen times). This is a long shot but try setting Outlook to the offline state (on the File menu), stop & restart Outlook then try deleting the item "bill"...

Writing an Anaglyph Video Presenter for the Windows Media Player 1
Dear community, Some time ago we implemented a DirectX Custom Renderer Filter, which is able to take a stereo video and render an anaglyph image. Now my question: What is the optimal solution to integrate such an anaglyph presenter into the Windows Media Player? - Extending the EVR with a custom presenter? (and how can i register my video for this specific resenter, so that the WMP uses my presenter instead of the EVR to show a stereo video) - Writing a DMO Rendering Plug-In? - what else is possible and useful? Suggestions are very welcome! :) Maybe somebody fr...

Print Preview #5
MFC preview has 3 states ZOOM_OUT , ZOOM_MIDDLE and ZOOM_OUT. Which one is 100% preview? What are the percentage scaling for each of the states? ...

Outlook 2003 not fully installing with Windows 7
HI - have a new computer with Windows 7 and a trial version of Office 2007. Installed Office 2003 and MS Office Service Pack 3 - all components installed and working fine except Outlook 2003. When opening Outlook it gets as far as the "Welcome" message and then stops. Allows me to access mail, contacts and calander and set up e-mail accounts and sends test e-mail from accounts setup. When I try to send an e-mail it sends an error message "object not found" I can add to contacts list but address books are not working - I cannot add an identity to them. Have tri...

Outlook 2K3, 1 SMTP acct, 1 Exchange Acct
So, I would like to configure outlook on my home pc to check my personal SMTP account as well as my work Exchange account. I can set them up in tandum fine but they all get dumped to the same inbox, and what's worse it it's not leaving my work emails on the exhange server as I would like. I could setup a filter based on To: to put emails into different folders but that doesn't really work across the board (BCC:, etc.). I would have thought the default behavior would be to have two Inbox folders under the different "Mailbox" expandable navigation menus in Outlook and p...

1 drive with 2 device IDs causing corruption
I have a drive which has been Z: for eons and has recently had G: assigned as well. I reformatted the drive, added as Z: again and still G: is defined. I'm getting corruption on indices (even though indexing is turned off for the drive as Z:). Ping ponging between chkdsk /f for the two IDs settles down to no errors but then a reboot and it's back... XP Pro, SP3, what else would help the experts? Did you remove G and Z and then reset as Z again.? Neil "Le" <Le@discussions.microsoft.com> wrote in message news:BF3628FC-88EF-4C13-9629-72CF7A0E2E42@micro...

Set Increment on Spin Button to 0.1
I'm using a spin button from the control toolbar to increase the value in a cell. the min value i want is 0 the maximum is 2 but i want it to increase by 0.1 in the properties this doesn't seem to be allowed help!!!! Thanx Mark Mark, Here is one way. Link your spinbutton to an unused cell (I use) A15. Set the max to 20. Then in code, set the real cell's value like so Private Sub SpinButton1_SpinUp() Range("A16").Value = Range("A15").Value / 10 End Sub Private Sub SpinButton1_SpinDown() Range("A16").Value = Range("A15").Valu...

Some videos have thumbnail previews while others do not....
why do some AVI files have a thumb image while others do not? ...

calling javascript function in vc
i have a c# function calling javascript like this: private System.Windows.Forms.WebBrowser virtualEarthMapBrowser; private void executeScript(string scriptName, params object[] parameters) { virtualEarthMapBrowser.Document.InvokeScript(scriptName, parameters); } Can you help me figure out how should i write this function in vc++? If your code is also compatible in both vc6 and vc2005, that will be better. I appreciate your help. -- jake "Jakein2006" <peng_xh@163.com> wrote in message news:2FD6990A-30E9-47E1-8373-5A4563675594@microsoft.com... >i have a c...

print preview & own CPreviewDC
Hello, i will write my own print preview. But i've some problem, to use CPreviewDC. I will use instead of void SetScaleRatio(int nNumerator, int nDenominator); void SetTopLeftOffset(CSize TopLeft); a function, to put the visible CRect on the screen. It is a rect with a offset, and width & heigth are proportional of the printer physical size CRect( 10, 10, double(m_sizePrinter.cx) * dZoom, double(m_sizePrinter.cy * dZoom) ) How can i do this ? Thanxs Jimmy ...

Virtual PC upgrade 5 to 6.1
I want to upgrade VPC to 6.1 but put it onto a new machine. Can this be done without going through the hassle of installing all the previous versions and upgrading them. TIA Rod Hi Rod, You can copy your virtual machine's file to your new computer. VPC 6 should have no trouble converting to its format (you won't be able to go back to 5 with it, though). I would make sure you have a good backup of your 5 virtual machine in any event, just in case. -Jim Gordon Mac MVP All responses should be made to this newsgroup within the same thread. Thanks. About Microsoft MVPs: http://w...

Access 2007 database on Windows Vista and Windows 7
I created a database using Access 2007. I am going to distribute it as a runtime application using the Access 2007 runtime engine. The problem is that engine is only supported up to Windows XP SP2. What do I need in order for my database to run on PC's with Windows Vista and Windows 7? Is there a version of the runtime engine that will work with those operating systems? Access 2007 runtime works on XP (SP2 or SP3), Vista and Windows 7 (I believe). I think Microsoft just didn't update the web page to indicate that it works on Windows 7 (maybe it's not officially t...

INVESTMENT: 0 quantity, 1 cent value?
Help: I had two 401(k) mutual fund investments that I contributed to over a great deal of time. Recently I sold the entire positions of both and bought different funds. Now, for these two investments, the reports section of Money 02 is showing 0 quantity, but 1 cent value for each. As a result, I cannot delete these two investments from my investments list, as it says I still have positions in them. So why would Money show a value and say I have a position in an investment that has no quantity, and how do I get rid of this? Thanks, Because it has some non-zero amount that is very, very...

Can't see other free/busy time past March 1.
Can't see other free/busy time past March 1. Any ideas? Go into Tools>Options>Calendar options> Free/busy options. there you can change the default time to the time you like. I think there might be a 12 month limit. then again, who knows what he/she will be doing in 12 months.. >-----Original Message----- >Can't see other free/busy time past March 1. Any ideas? >. > ...

MS Excel performance with Windows 7 Starter
Hi, I use a netbook and performance is quite okay with most app's. It's just got an Atom processor with 2G RAM. The performance in excel is very slow, is there anything that I can do to speed it up? I am using Excel 2007 Home and Student and navigating from one cell to the next is quite slow. Love Windows 7 and Office 2007 but am ageing fast, HELP!! -- PaulD ...

Exchange 2000's reliance on fsmo DC
I'm trying to figure out why every time my dc that runs all 5 of the fsmo roles gets rebooted, my Outlook clients loose the ability to connect to exchange. I have a second dc that is a GC. Can anyone shed some light on this for me? Windows 2000 native mode, Exchange 2000, Outlook 2003 clients. thanks, chris is the second dc listed in exchange as a directory server? and why have all 5 fsmo roles on 1 dc anyway? "Chris" <Chris@discussions.microsoft.com> wrote in message news:9F392194-E328-44D4-AEDD-5F43A0C82E32@microsoft.com... > I'm trying to figure out w...

Excel 97 #7
Hi I have an Excel file built in Office 97, I need to open this file in Office 2000, but it wont open. I have Office 97 here and can view it - is there any way I can open this file in 2000. Please Help!!! Thank you x ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~View and post usenet messages directly from http://www.ExcelForum.com/ ~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements There shouldn't really be any reason why the file shouldn't open in 2K. Do you get any error mess...

Cannot save files in normal mode with word 2003 after Windows 7 up
This a new entry for a previously reported problem. The original problem is that I am unable to save Word 2003 files in normal mode. The message indicates that I do not have enough HDD or RAM space. Neither case is true. I can save files by running Word in XP compatibility mode but I then can't open a file from outside Word by clicking on it. I get a message that says 'Unable to send command to the program.' Everything works ok in Safe Mode. The question arose about a NAV plug-in. I have temporarily removed Norton AntiVirus completely, no help As far...

image preview in preview pane
It is possible to adjust viewing image (tif file) in preview pane in Outlook. Now I see only filename etc. ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~View and post usenet messages directly from http://www.ExcelForum.com/ No. -- Russ Valentine [MVP-Outlook] "olegb" <olegb.zp8dy@outlookforum.com> wrote in message news:olegb.zp8dy@outlookforum.com... > > It is possible to adjust viewing image (tif file) in preview pane in > Outlook. > Now I see only filename etc. > > > -----------------------------...

An additional quantity of "1" of an item is purchased
Hello: A GP 10.0 Mfg client is seeing in purchasing reports where an additional receipt of a quantity of "1" for an item is being received. This quantity is in addition to the quantity that the client ordered through purchasing. Is Manufacturing MRP generating this order for this additional quantity? That's my only guess. The only other area of Manufacturing that I an think of where an additional quantity could be generated is in the Fixed Quantity field in Bill of Materials. But, that field is showing 0. Are there any other setups that I need to look at to determine ...

How do you print pages 1 AND 3 in a worksheet?
Am I being silly? In Word, it is easy and obvious, but in excel there is no function t print a range. Putting "1,3" gives a "bad integer" message. Please help the noob. Le -- SirLoi ----------------------------------------------------------------------- SirLoin's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1593 View this thread: http://www.excelforum.com/showthread.php?threadid=27413 try this Sub printsheets() ma = Array("Sheet1", "Sheet3", "Sheet5") For x = LBound(ma) To UBound(ma) Sheets(ma(x)).PrintPrev...

Budget Question #7
Is the a way to have Budget display a period other than what is available. I would like to be able to query year to date income as well as expenses year to date. I used to use Quicken and it had that option. Is there away to do it on Money? -- JimB Which Budget model (Advanced, Essential, Spending and Savings)? Which Money version/Edition? Are you looking in a report or the Budget screen itself? If the former, which report? In general, I suspect the answer you are headed for is no. "JimB" <JimB@discussions.microsoft.com> wrote in message news:A8678C15-9B13-45F5-B45...

extender #7
We are running gp9 and recently purchased extender. Went in and changed the key codes and validated but extender is not showing up under tools. Any idea what else has to be done. Thank you in advance -- Sandy Chace Bamco Belting Products, Inc. Did you install the extender chunk file? -- Richard L. Whaley Author / Consultant / MVP Documentation for Software Users Get our Free Tips and Tricks Newsletter and check out our books at http://www.AccoladePublications.com "SANDY CHACE" wrote: > We are running gp9 and recently purchased extender. Went in and changed the key >...

Office Clipboard in Office 2007, Windows 7
Hi all, I have a user that for a long time has been using Corel Paint Shop Pro Photo X2 for photo management, and Word for creation of reports with his photos. This weekend, I upgraded him to Windows 7, and as part of the process upgraded him to Office 2007 SP2, up from the original release. Along the way were several other office updates as well. His original workflow was to crop the photos to his liking in the photo editor, then copy them and paste them directly into his word document. I had seen him do this in past while looking at other issues in word, and it worked. H...

SFO (Sales for Outlook) failing to install.
Hello all, I am having a heck of a time trying to get Sales for Outlook working. I have read many post about similar problems but I have not been able to find something that will work for me. NOTE: all testing/installing was done with the same domain user which is a local admin. I was able to install SFO once on my computer but it would not sync. In my attempts to fix it I got to the point where I felt a re-install was needed. I tried to uninstall it and the uninstall failed. So here I was, now not able to install or uninstall. Here's what I did to clean the system: 1) Uninstalle...