带有圆角的窗体边框,格式为 c++建设者XE
我借助以下代码制作了一个带圆角的 C++ Builder XE 表单
BorderStyle = bsNone;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
HRGN frmrgn;
frmrgn = CreateRoundRectRgn (0, 0, ClientWidth, ClientHeight,12,12);
SetWindowRgn(Handle,frmrgn,true);
}
它看起来很酷但边框丢失了,我尝试了很多方法但没有得到好的结果 所以请帮我绘制颜色 RGB(96,96,96) 的边框
,我想让整个表单可拖动。
I have made a C++ Builder XE form with rounded corner with the help of the following code
BorderStyle = bsNone;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
HRGN frmrgn;
frmrgn = CreateRoundRectRgn (0, 0, ClientWidth, ClientHeight,12,12);
SetWindowRgn(Handle,frmrgn,true);
}
It looks cool but the border is missing, I tried many thing but not get good result
so please help me to draw border of color RGB(96,96,96)
And I want to make whole form dragable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1. 绘制深灰色边框
这个很简单,具体取决于您希望边框看起来有多复杂。如果您只想要深灰色的轮廓,可以使用直线和弧线的组合来绘制它,或者使用
FrameRgn
函数使用特定画笔在您的区域周围绘制轮廓。这样做是最好的解决方案,因为您已经有一个用于定义窗口形状的区域。但是,
SetWindowRgn< 的 MSDN 文档/code>
表示,“成功调用
SetWindowRgn
后,系统拥有由区域句柄hRgn
指定的区域。系统不制作该区域的副本。因此,您不应使用该区域句柄进行任何进一步的函数调用。” 您需要为 Paint 方法再次创建区域。您的绘图方法的一些代码:
2. 使窗口在没有标题栏的情况下可拖动
简短的总结是您需要处理
WM_NCHITTEST
消息。 Windows 发送此消息以查看鼠标是否位于标题栏上(“NC”代表“非客户端”;它实际上是在测试它是否位于非客户端区域中的任何位置,该区域可以是任何窗口边框,而不仅仅是窗口边框) )您可以通过说“是的,鼠标现在位于标题中”来使窗口可拖动,即使事实并非如此。一些代码:您可以执行一些自己的命中测试,以限制窗口的哪些部分显示为标题栏,以便创建您自己的标题栏。
示例 Delphi 代码。
示例 Delphi 代码。 msdn.com/b/oldnewthing/archive/2011/02/18/10131176.aspx" rel="nofollow">一篇关于使用此消息以及需要注意的事项/不要陷入陷阱的好文章。
1. Painting a dark grey border
This one's easy, depending on how complex you want the border to look. If you just want an outline in dark grey, either draw it using a combination of lines and arcs, or use the
FrameRgn
function to draw an outline around your region with a specific brush. Doing this is the best solution since you already have a region you've used to define the shape of the window.However, the MSDN documentation for
SetWindowRgn
says, "After a successful call toSetWindowRgn
, the system owns the region specified by the region handlehRgn
. The system does not make a copy of the region. Thus, you should not make any further function calls with this region handle." You'll need to create your region again for the paint method.Some code for your paint method:
2. Making the window draggable without its title bar
The short summary is that you need to handle the
WM_NCHITTEST
message. Windows sends this to see if the mouse is over the title bar ('NC' stands for 'non-client'; it's actually testing to see if it's anywhere in the non-client area, which can be any window border, not just the top one.) You can make your window draggable by saying 'yes, the mouse is in the caption right now' even when it isn't. Some code:You can perform some hit testing of your own to restrict what parts of your window appear to be the title bar, in order to create a title bar of your own.
Example Delphi code.
A good article about using this message, and things to be aware of / traps not to fall into.