网上有如下代码,生成字体窗体
'API声明
Private Declare Function MoveTo Lib "gdi32" Alias "MoveToEx" ( _
ByVal hdc As Long, ByVal x As Long, ByVal y As Long, _
Optional lpPoint As Any = 0) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function BeginPath 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 EndPath Lib "gdi32" _
(ByVal hdc As Long) As Long
Private Declare Function PathToRegion Lib "gdi32" _
(ByVal hdc As Long) As Long
Private Declare Function GetRgnBox Lib "gdi32" _
(ByVal hRgn As Long, lpRect As RECT) As Long
Private Declare Function CreateRectRgnIndirect Lib "gdi32" _
(lpRect As RECT) 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 Const RGN_AND = 1
Private Declare Function DeleteObject Lib "gdi32" _
(ByVal hObject 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 ReleaseCapture Lib "user32" _
() As Long
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
'窗体代码
Private Sub Form_Load()
Dim hRgn1, hRgn2 As Long
Dim rct As RECT
With Me
.Font.Name = "宋体"
.Font.Size = 200
.FontTransparent = True
'读者可设置为False观察其效果
End With
BeginPath hdc
'为窗体形状产生路径
'******************************************
'* TextOut hdc, 20, 20, "国", 2 '*
'******************************************
EndPath hdc
hRgn1 = PathToRegion(hdc)
'将指定路径转换为区域
GetRgnBox hRgn1, rct
'获取完全包含指定区域的最小矩形
hRgn2 = CreateRectRgnIndirect(rct) '创建rct确定的矩形区域
CombineRgn hRgn2, hRgn2, hRgn1, RGN_AND
DeleteObject hRgn1
'删除GDI对象,释放占用的系统资源
SetWindowRgn hwnd, hRgn2, 1
End Sub
本人把用星号(*)包装的一句替换成以下代码,却不能生成矩形窗体,请问何解?
'***************************
'* For y = 30 To 200 '*
'* MoveTo hdc, 30, y '*
'* LineTo hdc, 200, y '*
'* Next y '*
'***************************
'API声明
Private Declare Function MoveTo Lib "gdi32" Alias "MoveToEx" ( _
ByVal hdc As Long, ByVal x As Long, ByVal y As Long, _
Optional lpPoint As Any = 0) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function BeginPath 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 EndPath Lib "gdi32" _
(ByVal hdc As Long) As Long
Private Declare Function PathToRegion Lib "gdi32" _
(ByVal hdc As Long) As Long
Private Declare Function GetRgnBox Lib "gdi32" _
(ByVal hRgn As Long, lpRect As RECT) As Long
Private Declare Function CreateRectRgnIndirect Lib "gdi32" _
(lpRect As RECT) 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 Const RGN_AND = 1
Private Declare Function DeleteObject Lib "gdi32" _
(ByVal hObject 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 ReleaseCapture Lib "user32" _
() As Long
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
'窗体代码
Private Sub Form_Load()
Dim hRgn1, hRgn2 As Long
Dim rct As RECT
With Me
.Font.Name = "宋体"
.Font.Size = 200
.FontTransparent = True
'读者可设置为False观察其效果
End With
BeginPath hdc
'为窗体形状产生路径
'******************************************
'* TextOut hdc, 20, 20, "国", 2 '*
'******************************************
EndPath hdc
hRgn1 = PathToRegion(hdc)
'将指定路径转换为区域
GetRgnBox hRgn1, rct
'获取完全包含指定区域的最小矩形
hRgn2 = CreateRectRgnIndirect(rct) '创建rct确定的矩形区域
CombineRgn hRgn2, hRgn2, hRgn1, RGN_AND
DeleteObject hRgn1
'删除GDI对象,释放占用的系统资源
SetWindowRgn hwnd, hRgn2, 1
End Sub
本人把用星号(*)包装的一句替换成以下代码,却不能生成矩形窗体,请问何解?
'***************************
'* For y = 30 To 200 '*
'* MoveTo hdc, 30, y '*
'* LineTo hdc, 200, y '*
'* Next y '*
'***************************
解决方案 »
- 对单机设备数据的读取问题!谢谢!
- 如何实现 MSFlexGrid 多层表头
- pictureBox加载网络上的图片的问题或其它解决方案,大家快来帮忙或学习呀!
- bit型数据在DataGrid中的显示问题
- playyuer、foolishtiger、songyangk三位斑竹请回答我的问题!!急!!论文要答辩拉!!
- 求助:怎样读取excel中的一列数,并求这一列数的方差。下面是自己编的输数的的程序。
- 求救!如何获得其他程序的中的Listview控件中添加的其他控件的句柄?
- 请看程序,如何按日期排序(万分急)谢
- 有人传给我一个带宏命令的excel 在他的电脑上能运行 但是在我的电脑上却提示内存溢出
- 十万火急求助:读数据库生成表格(用Excel),字段超出页面,如何使超出字段输出?
- 除了文件操作有没其他方法
- 救命! 如何将RTF文挡换为多个大小相同的位图
LineTo Me.hdc, 200, 200
LineTo Me.hdc, 0, 200
LineTo Me.hdc, 0, 0
Dim pp as POINTAPI
For x=0 to 200
For y=0 to 200
MovetoEx hdc,x,y,pp
Lineto hdc,x,y
Next x
Next y这样为何不行?
GetRgnBox hRgn1, rct
后面加上一句:
If IsRectEmpty(rct) Then
MsgBox "Empty Rect"
End If可以看到获得的外接矩形是空的。