开发者

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

开发者 https://www.devze.com 2023-02-03 08:56 出处:网络
I\'m using simple statements to keep it, er, simple: The screen goes from 0, 0 to 1000, 1000 (screen coordinates).

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

  • The screen goes from 0, 0 to 1000, 1000 (screen coordinates).
  • A window goes from 100, 100 to 900, 900 (screen coordinates).
  • I have a memory device context that goes from 0, 0 to 200, 200 (logical coordinates).

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 开发者_StackOverflow中文版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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消