计算正确的宽度以调整图像大小以显示在ClistCtrl中

发布于 2025-02-09 07:39:01 字数 2094 浏览 2 评论 0原文

目前,我必须这样的代码:

CRect rcList;
m_ListThumbnail.GetClientRect(rcList);
rcList.DeflateRect(25, 25);

// Use monitor 1 to work out the thumbnail sizes
CRect rcMonitor = m_monitors.rcMonitors.at(0);

m_iThumbnailWidth = rcList.Width();

double dHt = ((double)rcMonitor.Height() / (double)rcMonitor.Width()) * (double)m_iThumbnailWidth;
m_iThumbnailHeight = (int)dHt;

我通过将矩形缩放为25。我不需要水平滚动条。

当我呈现监视器的缩略图时,我尝试按摩这些缩略图值(不完整):

nWidth = m_iThumbnailWidth;

double dHt = ((double)rcCapture.Height() / (double)rcCapture.Width()) * (double)m_iThumbnailWidth;
nHeight = (int)dHt;

if (nHeight > m_iThumbnailHeight)
{
    AfxMessageBox(L"Need to investigate!");
}

其中rccapture是监视器的大小。

如果我删除deflaterect行,则我的窗口如下显示:

“在此处输入图像描述”

如您所见,这是我所期望的。有一个水平滚动条,我必须调整大小相当大的大小才能查看缩略图:

”在此处输入图像说明“

我要计算的只是一组缩略图尺寸clistctrl。我真的不希望用户调整窗口大小。


使用我的调整后的代码更新,

该代码现在使用主要的监视器纵横比来计算缩略图大小(如上所述)以更好的whitespace呈现应用程序:

“在此处输入图像说明”

这是底部额外空间的原因因为监视器是16:9,所以我挤进了4:3。因此是固定的。

但是,如您所见,使用clistCtrl客户端宽度不够。


更新

这是渲染代码:

// Set the mode first!
SetStretchBltMode(dcImage, COLORONCOLOR);

int iTop = (m_iThumbnailHeight - nHeight) / 2;

// Copy (and resize)
bRet = ::StretchBlt(dcImage, 0, iTop,
    nWidth, 
    nHeight, 
    dcScreen.m_hDC, 
    rcCapture.left, 
    rcCapture.top, 
    rcCapture.Width(), 
    rcCapture.Height(), SRCCOPY | CAPTUREBLT);

At the moment I am having to fudge my code like this:

CRect rcList;
m_ListThumbnail.GetClientRect(rcList);
rcList.DeflateRect(25, 25);

// Use monitor 1 to work out the thumbnail sizes
CRect rcMonitor = m_monitors.rcMonitors.at(0);

m_iThumbnailWidth = rcList.Width();

double dHt = ((double)rcMonitor.Height() / (double)rcMonitor.Width()) * (double)m_iThumbnailWidth;
m_iThumbnailHeight = (int)dHt;

I fudge it by deflating the rectangle by 25. m_ListThumbnail is a CListCtrl and I am trying to render my thumbnails so that I do not need a horizontal scroll bar.

When I render the thumbnails of the monitors, I attempt to massage these thumbnail values (incomplete):

nWidth = m_iThumbnailWidth;

double dHt = ((double)rcCapture.Height() / (double)rcCapture.Width()) * (double)m_iThumbnailWidth;
nHeight = (int)dHt;

if (nHeight > m_iThumbnailHeight)
{
    AfxMessageBox(L"Need to investigate!");
}

Where rcCapture is the size of the monitor.

If I remove the DeflateRect line, my window displays like this:

enter image description here

As you can see, it is note as I expected. There is a horizontal scroll bar and I have to resize quite a bit to see the thumbnail:

enter image description here

All I want to compute is a set of thumbnail dimensions so that the scaled down monitor image is going to fit in the CListCtrl. I don't really want the user to have to resize the window.


Update

With my adjusted code which now uses the primary monitor aspect ratio to work out the thumbnail sizes (as added above) renders the app with better whitespace:

enter image description here

That was the reason of the extra space at the bottom because the monitors were 16:9 and I was squishing into 4:3. So that is fixed.

But as you can see, using the CListCtrl client width is not sufficient.


Update

This is the rendering code:

// Set the mode first!
SetStretchBltMode(dcImage, COLORONCOLOR);

int iTop = (m_iThumbnailHeight - nHeight) / 2;

// Copy (and resize)
bRet = ::StretchBlt(dcImage, 0, iTop,
    nWidth, 
    nHeight, 
    dcScreen.m_hDC, 
    rcCapture.left, 
    rcCapture.top, 
    rcCapture.Width(), 
    rcCapture.Height(), SRCCOPY | CAPTUREBLT);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那伤。 2025-02-16 07:39:01

控件以边距呈现图标。当我使用getItemPosition函数时,指出x值为21。这就是为什么我的deflaterect(25,25)工作的原因。但是我不知道clistCtrl如何计算该保证金值。


最终,我通过使用 seticonSpacing 函数。这样:

m_ListThumbnail.SetIconSpacing(
    CSize(m_iThumbnailWidth, ::GetSystemMetrics(SM_CXHSCROLL)));

一旦完成了以上完成的窗口,就会如下:

“在此处输入图像描述”

当有3或4个监视器缩略图时,情况可能会有所不同,从而导致垂直滚动条。但是我只有两个监视器可以测试。

The control renders the icon with a margin. When I used GetItemPosition function it indicated that the x value was 21. This is why my DeflateRect(25, 25) worked. But I don;t know how the CListCtrl computed that margin value.


Eventually I found out how to do this without deflating, by using the SetIconSpacing function. Like this:

m_ListThumbnail.SetIconSpacing(
    CSize(m_iThumbnailWidth, ::GetSystemMetrics(SM_CXHSCROLL)));

Once the above has been done the window looks like this:

enter image description here

Things might be a little different when there are 3 or 4 monitor thumbnails, thus causing a vertical scroll bar. But I only have two monitors to test with.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文