Nell
Nell

Reputation: 13

How to draw a part of a window into a memory device context?

I'm using simple statements to keep it, er, simple:

I need to send a WM_PRINT message to the window. I can pass the device context to the window via WM_PRINT, but I cannot pass which part of its window it should draw into the device context.

Is there some way to alter the device context that will result in the window drawing a specific part of itself into the device context (say, its bottom right portion from 700, 700 to 900, 900)?

(This is all under plain old GDI and in C or C++. Any solution must be too.)

Please note: This problem is part of a larger solution in which the device context size is fixed and speed is crucial, so I cannot draw the window in full into a separate device context and blit the part I want from the resultant full bitmap into my device context.

Upvotes: 1

Views: 362

Answers (1)

Frédéric Hamidi
Frédéric Hamidi

Reputation: 262919

You can call SetViewportOrgEx() to specify the device context coordinates that will be mapped to the window's origin:

SetViewportOrgEx(yourDC, -600, -600, NULL);

Since your window's size is 800x800, offsetting the DC's coordinate system by -600x-600 will result in the 200x200 bottom right area of the window being drawn, and the rest being clipped.

Upvotes: 1

Related Questions