Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with ResetDC() and GDI+

124 views
Skip to first unread message

bob dong

unread,
Jul 23, 2004, 5:44:12 AM7/23/04
to
hi there,

i'm having troble with ResetDC() and GDI+. Look at the following codes:

......; // codes to init DEVMODE
//Graphics myG(hdcPrinter);
hDC = ResetDC(hdcPrinter, pDevMode);

the ResetDC() function call will succeed in this way. But if the 2nd line is
not commented, then it will fail and return NULL.

Can anybody tell me why? THX in advance.

Bob Dong


vipin

unread,
Jul 23, 2004, 10:17:07 AM7/23/04
to
let me tell you onething that a usage like this is wrong:-

Graphivs gr(hdc);
hdc1 = ResetDC(hdc , pdevmode);

When you call ResetDC(...) and had it been successful then Graphics object g
would be invalid because the hdc is destroyed when you call ResetDC and a
new HDC is returned.

So the above usage is wrong, so don't think of correcting with the above
sequence.

thanks
vipin

"bob dong" <don...@kingsoft.net> wrote in message
news:#tvVLmJc...@TK2MSFTNGP09.phx.gbl...

bob dong

unread,
Jul 23, 2004, 10:04:46 PM7/23/04
to
thanks vipin. i have the following findings.

as MSDN says, ResetDC is disabled between StartPage(...) and EndPage(...).
See the following codes:

StartPage(hdcPrinter);
ResetDC(hdcPrinter, pDevMode); // which will fail
dwErr = GetLastError(); // will return 0x7a

and the following codes:

Graphivs gr(hdc);
hdc1 = ResetDC(hdc , pdevmode);

dwErr = GetLastError(); // will return 0x7a also

and 0x7a == ERROR_INSUFFICIENT_BUFFER == The data area passed to a system
call is too small. i just doubt it.

My conclusion is ResetDC(...) is also disabled after Graphivs gr(hdc);. I
want to use ResetDC(...) to change the paper size and orientation during a
print job. Now the only workaround i can think about is dividing the job
into many separated ones. that's a pity and too ugly.

"vipin" <vi...@nospam.com> wrote in message:
OF7S84Lc...@TK2MSFTNGP11.phx.gbl...

vipin

unread,
Jul 26, 2004, 3:59:06 AM7/26/04
to
The documentation you are pointing to has nothing to do with the error you
see. The reason why it is disabled between StartPage and endpage is that the
surface on which graphics calls are to be done should be ready before
StartPage(...) and ResetDC creates a new surface.

Graphics object encapsulates the hdc and you try to delete the encapsulated
HDC using ResetDC(...), this not right anyway :) Had the ResetDC been
successful, the graphics object is useless and viceversa.

But I don't know you how the sync up is happening between GDI+ object and
GDI object though. Because at GDI level you can't query a GDI+ status which
is maintained by the gdiplus dll.

thanks
vipin


"bob dong" <don...@kingsoft.net> wrote in message

news:#5rWGKSc...@TK2MSFTNGP10.phx.gbl...

bob dong

unread,
Jul 26, 2004, 9:54:22 AM7/26/04
to
Many thanks to vipin!

"vipin" <vi...@nospam.com> 写入消息新闻
:OlsikTuc...@tk2msftngp13.phx.gbl...

0 new messages