产生各种形状的窗体?

xiaoliou 2003-10-30 08:50:59
我想产生各种形状的窗体
用creatllipicrgn 和 setwindowrgn好象只能产生圆,椭圆的窗体
比如我想产生五角星的窗体,怎么做?
另外: 用CreateCompatibleBitmap 和 selectobject好象不行?
...全文
17 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyl910 2003-11-01
  • 打赏
  • 举报
回复
用CreatePolygonRgn创建多边形区域
至于五角星所对应的多边形坐标
别告诉我你没学过几何——用sin、cos算就是了

====================


另外: 用CreateCompatibleBitmap 和 selectobject好象不行?
----------------
这只是重新设定窗口能更新的区域,与透明无关
hisofty 2003-11-01
  • 打赏
  • 举报
回复
字状窗体:
Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function PathToRegion Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Sub Form_Click()
'end
Unload Me
End Sub
Private Sub Form_Load()
Dim hRgn As Long
const strText as string="瘦马"
Me.FontName = "黑体"
Me.FontSize = 72
Me.BackColor = vbRed
BeginPath Me.hdc
TextOut Me.hdc, 0, 0, strText,Len(strText)
EndPath Me.hdc
hRgn = PathToRegion(Me.hdc)
SetWindowRgn Me.hWnd, hRgn, True
DeleteObject hRgn
End Sub
lihonggen0 2003-10-30
  • 打赏
  • 举报
回复
VB6中实现(借助API函数)

做一个古怪的窗口必须要用的也是此程序中最重要的一个函数就是SetWindowRgn

它的功能就是对指定的窗口进行重画,把这个窗口你选择的部分留下其余的部分抹掉

参数:hWnd:你所要重画的窗口的句柄,比如你想重画form1则应该让此参数为form1.hWnd

hRgn:你要保留的区域的句柄,这个句柄是关键,你需要通过别的渠道来获得

在这里的区域是由Combinergn合成的新区域

bRedram:是否要马上重画,一般设为true

函数CombineRgn将两个区域组合为一个新区域

函数Createrectrgn为创建一个由点X1,Y1和X2,Y2描述的矩形区域

函数CreateEllipticRgn为创建一个X1,Y1和X2,Y2的椭圆区域

用DeleteObject这个函数可删除GDI对象,比如画笔、刷子、字体、位图、区域以及调色板等等。对象使用的所有系统资源都会被释放



以下是VB6的代码:

Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long

Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long

Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Private Const RGN_DIFF = 4



Private Sub Form_Load()

Dim rgn As Long

Dim rgnRect As Long

Dim rgnDest As Long



rgn = CreateEllipticRgn(0, 0, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY)

rgnRect = CreateRectRgn((Me.Width / Screen.TwipsPerPixelX - 20) / 2, (Me.Height / Screen.TwipsPerPixelY - 20) / 2, (Me.Width / Screen.TwipsPerPixelX + 20) / 2, (Me.Height / Screen.TwipsPerPixelY + 20) / 2)

rgnDest = CreateRectRgn(0, 0, 1, 1)

CombineRgn rgnDest, rgn, rgnRect, RGN_DIFF

SetWindowRgn Me.hWnd, rgnDest, True

Call DeleteObject(rgnRect)

Call DeleteObject(rgnDest)

End Sub



Private Sub Command1_Click()

End

End Sub



lihonggen0 2003-10-30
  • 打赏
  • 举报
回复
http://www.csdn.net/develop/read_article.asp?id=18774

1,485

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧