如何使用visual c ++在win32 API中创建圆形/圆形按钮 [英] how to create a round/circular button in win32 API using visual c++

查看:79
本文介绍了如何使用visual c ++在win32 API中创建圆形/圆形按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual C++ 中有一个 Window (win32 API) 应用程序.我没有使用 MFC.我必须用位图图像创建一个圆形/圆形按钮.我的应用程序有一个皮肤视图.任何人都可以帮助我完成这项任务.提前致谢.

I have a Window (win32 API) Application in visual c++. I am not using MFC. I have to create a round/circular button with bitmap image. My application have a skined view. Can any one help me out in achieving this task. Thanks in advance.

推荐答案

按钮是窗口.您可以使用 CreateWindow 或 CreateWindowEx 调用创建按钮:

Buttons are windows. You can create a button with the CreateWindow or CreateWindowEx call:

-http://msdn.microsoft.com/en-us/library/ms632680(VS.85).aspx

-http://msdn.microsoft.com/en-us/library/ms632680(VS.85).aspx

创建按钮窗口时,请确保传递 BS_OWNDERDRAW 样式:

When you create your button window ensure that you pass the BS_OWNDERDRAW style:

-http://msdn.microsoft.com/en-us/library/bb775951(VS.85).aspx

-http://msdn.microsoft.com/en-us/library/bb775951(VS.85).aspx

这会告诉按钮向按钮的 WNDPROC 发送 WM_DRAWITEM 消息:

That will tell the button to send WM_DRAWITEM messages to your buttons' WNDPROC:

-http://msdn.microsoft.com/en-us/library/bb775923(v=VS.85).aspx

-http://msdn.microsoft.com/en-us/library/bb775923(v=VS.85).aspx

在按钮的 WNDPROC 中,您将处理 WM_DRAWITEM 消息并根据作为 lParam 中的指针接收的 DRAWITEMSTRUCT 中的信息绘制按钮.

In your buttons' WNDPROC you would handle the WM_DRAWITEM message and paint your button according to the information in the DRAWITEMSTRUCT received as a pointer in lParam.

要将位图呈现为除矩形以外的任何内容,您需要提供与您希望为按钮呈现的位图大小相同的 1 位位掩码位图.位掩码设置了您希望在屏幕上设置按钮位图中像素的位.按钮位图中不显示的像素必须是黑色的.使用 AND 运算符将您的位掩码位图 Bitblt 到屏幕,然后 OR 您的按钮位图.当然,您需要考虑各种按钮状态(通常一个按钮只有两种状态.)

To render a bitmap as anything but rectangular you will need to provide a 1-bit bitmask bitmap the same size as the bitmap you wish to render for your button. The bitmask has bits set where you want the pixels in your button bitmap to be set on the screen. The pixels in your button bitmap that do not display need to be black. Bitblt your bitmask bitmap to the screen with the AND operator then OR your button bitmap. Of course you will need to account for the various button states (normally a push button is only two states.)

我可能在上面的解释中混合了黑/白或设置/未设置位,但 AND/OR 按位 (SRCAND/SRCPAINT) 光栅操作是您想要实现的正确操作.

I may have mixed the black/white or set/unset bits in the explanation above, but the AND / OR bitwise (SRCAND/SRCPAINT) Raster Operations are the correct operations for what you are trying to acheive.

-http://msdn.microsoft.com/en-us/library/aa930997.aspx

-http://msdn.microsoft.com/en-us/library/aa930997.aspx

希望有所帮助.

这篇关于如何使用visual c ++在win32 API中创建圆形/圆形按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆