本文介绍了SetWindowExt和SetWindowExtEx很奇怪(负高度,上下颠倒)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到关于SetViewportExt()SetViewportExtEx()的怪异行为.

I am running into a weird behavior regarding SetViewportExt() and SetViewportExtEx().

我的MFC应用程序使用MM_ISOTROPIC映射来设置视图设备上下文并按如下方式配置设备上下文:

My MFC application uses MM_ISOTROPIC mapping for setting up the view device context and configures the device context as follows:

m_dc.SetMapMode( MM_ISOTROPIC );

// Set the window extent (document space)
CSize docSizeLP = GetDocumentSizeLP();
m_dc.SetWindowExt(docSizeLP.cx, docSizeLP.cy);

// Next set the viewport extent
CSize docSizeDP = GetDocumentSizeDP();
m_dc.SetViewportExt((int) (docSizeDP.cx * fZoom), (int) (docSizeDP.cy * fZoom));

现在我遇到了三件事:

  • 将视图呈现到图元文件(CMetaFileDC)时,视图内容在图元文件中倒置.但是,如果将SetViewportExt()调用替换为SetViewportExtEx()调用,则图元文件是正确的.差异似乎是SetViewportExtEx()设置了负的视口高度,尽管我传递的值肯定是正值-而且我需要使用负的视口高度才能使图元文件正确.
  • 另一方面,SetViewportExtEx()用作默认设置会导致打印预览不显示任何内容.再次调用SetViewportExtEx()时,视口高度会变为负数,这可能是造成这种情况的原因.
  • 在普通视图渲染(MFC视图)中,SetViewportExt()SetViewportExtEx()都将导致正视口高度.
  • When rendering my view to a meta file (CMetaFileDC) then my view content is upside down in the metafile. However, if I replace the SetViewportExt() call with a SetViewportExtEx() call then the metafile is correct. The difference seems to be that SetViewportExtEx() sets a negative viewport height, although my passed value is definitely positive - and that I need the negative viewport height to get the metafile correct.
  • On the other hand, using the SetViewportExtEx() as default results in the print preview to not show anything. Again the viewport height turns negative when calling SetViewportExtEx(), which is probably the reason for this.
  • In normal view rendering (MFC view) both SetViewportExt() and SetViewportExtEx() result in a positive viewport height.

那么,有人对这两个问题有答案吗?

So, does anybody have answers to these two questions?

  1. 为什么SetViewportExtEx()在我传递正数的同时,SetViewportExtEx()在图元文件和打印预览呈现中将视口高度设置为负值?
  2. 为什么我的图元文件渲染需要负的视口高度才能最终不被颠倒?
  1. Why the heck does SetViewportExtEx() set my viewport height as negative value in metafile and print preview rendering, although I pass a positive one?
  2. Why does my metafile rendering require a negative viewport height in order to be not upside down in the end?

自从我的智慧到此为止,我很好奇是否有人对此有答案. :-)

I am curious whether anybody has answers to this, since my wisdom ended here. :-)

推荐答案

您的问题为我提供了解决增强型图元文件遇到的问题的提示.我的应用程序还使用MM_ISOTROPIC模式并在视图中心显示逻辑(0,0)进行输出.输出图像偏移且缩放比例不正确.

Your question gave me a hint to solving a problem I had with enhanced metafile. My application was also outputting using MM_ISOTROPIC mode and with the logical (0,0) in the center of the view. The output image was offset and scaled incorrectly.

花了很多时间后,我终于意识到问题可能出在MFC CDC的设备上下文的两个版本上.第一个DC m_hDC用于实际输出,第二个m_hAttribDC用于查询设备指标(如DPI).

After spending quite a bit of time with it, I finally realized that the problem might be with the 2 versions of device contexts that MFC's CDC has. First DC m_hDC is for the actual output and the second one m_hAttribDC is for querying device metrics like DPI.

我最终要做的是通过以下方式准备设备上下文:

What I finally ended up doing was to prepare device context in the following way:

if (pDC->IsPrinting()){
  pDC->SetMapMode(MM_ISOTROPIC);
  pDC->SetViewportOrg(x0, y0);
  pDC->SetWindowExt(wind_extent, wind_extent);
  pDC->SetViewportExt(viewport_extent, -viewport_extent);
}
else{
  ::SetMapMode(pDC->m_hDC, MM_ISOTROPIC);
  ::SetViewportOrgEx(pDC->m_hDC, x0, y0, NULL);
  ::SetWindowExtEx(pDC->m_hDC, wind_extent, wind_extent, NULL);
  ::SetViewportExtEx(pDC->m_hDC, viewport_extent, -viewport_extent, NULL);
}

此后,打印预览和图元文件输出正常.

The print preview and metafile output worked fine afterwards.

希望这会有所帮助.

这篇关于SetWindowExt和SetWindowExtEx很奇怪(负高度,上下颠倒)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:25