如何确定 Windows 单选按钮的按钮部分的大小

发布于 2024-07-05 06:51:33 字数 397 浏览 3 评论 0原文

我正在使用 DrawFrameControl 自己绘制老式学校(无主题 - 主题收音机是一个完全不同的问题)单选按钮:

DrawFrameControl(dc, &rectRadio, DFC_BUTTON, isChecked() ? DFCS_BUTTONRADIO | DFCS_CHECKED : DFCS_BUTTONRADIO);

我一直无法找到一种可靠的方法来找出要传递给 RECT 的内容。 我一直在使用 12x12 矩形,但我希望 Windows 告诉我单选按钮的大小。

DrawFrameControl 似乎缩放单选按钮以适合我通过的矩形,因此我必须接近无线电的“正确”尺寸,与屏幕上的其他(非所有者绘制的)无线电不同。

有人知道怎么做吗?

I'm drawing old school (unthemed - themed radios are a whole other problem) radio buttons myself using DrawFrameControl:

DrawFrameControl(dc, &rectRadio, DFC_BUTTON, isChecked() ? DFCS_BUTTONRADIO | DFCS_CHECKED : DFCS_BUTTONRADIO);

I've never been able to figure out a sure fire way to figure out what to pass for the RECT. I've been using a 12x12 rectangle but I'de like Windows to tell me the size of a radio button.

DrawFrameControl seems to scale the radio button to fit the rect I pass so I have to be close to the "right" size of the radio looks off from other (non-owner drawn) radios on the screen.

Anyone know how to do this?

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

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

发布评论

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

评论(2

晚雾 2024-07-12 06:51:33

我从事这个工作已经有一段时间了,所以我所描述的是我所做的,不一定是对问题的直接回答。

我碰巧使用位图 13 x 13 而不是 12 x 12。复选框的位图部分似乎是在 WM_DRAWITEM 中传递的。 然而,我还设置了 WM_MEASUREITEM 并为其提供相同的值,因此我的答案很可能是正确的哲学意义上的“乞求问题”。

        case WM_MEASUREITEM:
            lpmis = (LPMEASUREITEMSTRUCT) lParam;

            lpmis->itemHeight = 13;
            lpmis->itemWidth = 13;

            break;


        case WM_DRAWITEM:
            lpdis = (LPDRAWITEMSTRUCT) lParam;
            hdcMem = CreateCompatibleDC(lpdis->hDC);  



            if (lpdis->itemState & ODS_CHECKED)  // if selected
                {
                SelectObject(hdcMem, hbmChecked);
                }
            else
                {
                if (lpdis->itemState & ODS_GRAYED)
                    {
                    SelectObject(hdcMem, hbmDefault);
                    }
                else
                    {
                    SelectObject(hdcMem, hbmUnChecked);
                    }
                }
            StretchBlt(
                lpdis->hDC,         // destination DC
                lpdis->rcItem.left, // x upper left
                lpdis->rcItem.top,  // y upper left

                // The next two lines specify the width and
                // height.
                lpdis->rcItem.right - lpdis->rcItem.left,
                lpdis->rcItem.bottom - lpdis->rcItem.top,
                hdcMem,    // source device context
                0, 0,      // x and y upper left
                13,        // source bitmap width
                13,        // source bitmap height
                SRCCOPY);  // raster operation

            DeleteDC(hdcMem);
            return TRUE;

这似乎对 Win2000 和 XP 都有效,尽管我不知道 Vista 可能会做什么。

可能值得进行一次实验来看看省略 WM_MEASUREITEM 会带来什么影响,尽管我通常会发现旧代码通常有充分的理由去做一些看起来多余的事情。

It has been a while since I worked on this, so what I am describing is what I did, and not necessarily a direct answer to the question.

I happen to use bit maps 13 x 13 rather than 12 x 12. The bitmap part of the check box seems to be passed in the WM_DRAWITEM. However, I had also set up WM_MEASUREITEM and fed it the same values, so my answer may well be "Begging the question" in the correct philosophical sense.

        case WM_MEASUREITEM:
            lpmis = (LPMEASUREITEMSTRUCT) lParam;

            lpmis->itemHeight = 13;
            lpmis->itemWidth = 13;

            break;


        case WM_DRAWITEM:
            lpdis = (LPDRAWITEMSTRUCT) lParam;
            hdcMem = CreateCompatibleDC(lpdis->hDC);  



            if (lpdis->itemState & ODS_CHECKED)  // if selected
                {
                SelectObject(hdcMem, hbmChecked);
                }
            else
                {
                if (lpdis->itemState & ODS_GRAYED)
                    {
                    SelectObject(hdcMem, hbmDefault);
                    }
                else
                    {
                    SelectObject(hdcMem, hbmUnChecked);
                    }
                }
            StretchBlt(
                lpdis->hDC,         // destination DC
                lpdis->rcItem.left, // x upper left
                lpdis->rcItem.top,  // y upper left

                // The next two lines specify the width and
                // height.
                lpdis->rcItem.right - lpdis->rcItem.left,
                lpdis->rcItem.bottom - lpdis->rcItem.top,
                hdcMem,    // source device context
                0, 0,      // x and y upper left
                13,        // source bitmap width
                13,        // source bitmap height
                SRCCOPY);  // raster operation

            DeleteDC(hdcMem);
            return TRUE;

This seems to work well for both Win2000 and XP, though I have nbo idea what Vista might do.

It might be worth an experiment to see what leaving out WM_MEASUREITEM does, though I usually discover with old code that I usually had perfectly good reason for doing something that looks redundant.

2024-07-12 06:51:33

此页显示了一些控件大小调整指南。 请注意,尺寸以 DLU(对话框单位)和像素给出,具体取决于您是否将控件放置在对话框上:

http://msdn.microsoft.com/en-us/library/aa511279.aspx#controlsizing

我认为 GetSystemMetrics API可能会返回一些常见控件的标准大小,但我没有找到任何东西。 可能有一个通用的控制特定 API 来确定大小。

This page shows some sizing guidelines for controls. Note that the sizes are given in both DLU (dialog units) and pixels, depending on whether you are placing the control on a dialog or not:

http://msdn.microsoft.com/en-us/library/aa511279.aspx#controlsizing

I thought the GetSystemMetrics API might return the standard size for some of the common controls, but I didn't find anything. There might be a common control specific API to determine sizing.

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