excel+vba+APi窗口代码问题。。。急!!!请各位帮帮忙,在此万分感谢!

fcl2008 2008-05-02 09:52:27
请教:
在excel中新建了个窗口,然后在此窗口中有如下代码:
Private Declare Sub ReleaseCapture Lib "user32" ()
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 Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong 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 Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Const GWL_STYLE As Long = (-16)
Private Const WS_CAPTION As Long = &HC00000
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2


Private Sub CommandButton1_Click()
Unload Me
ThisWorkbook.Close False
End Sub

Private Sub UserForm_Initialize()
Dim hwnd, hwnd1, hwnd2, wdc, colorl As Long
Dim I As Integer
If Val(Application.Version) < 9 Then
hwnd = FindWindow("ThunderXFrame", Me.Caption)
Else
hwnd = FindWindow("ThunderDFrame", Me.Caption)
End If

IStyle = GetWindowLong(hwnd, GWL_STYLE)
IStyle = IStyle And Not WS_CAPTION
SetWindowLong hwnd, GWL_STYLE, IStyle
DrawMenuBar hwnd
With Worksheets(1)
hwnd1 = CreateRectRgn(.Cells(1, 2).Value, .Cells(1, 1).Value, .Cells(1, 3).Value, .Cells(1, 1) + 1)
I = 2
Do While .Cells(I, 1).Value <> ""
hwnd2 = CreateRectRgn(.Cells(I, 2).Value, .Cells(I, 1).Value, .Cells(I, 3).Value, .Cells(I, 1) + 1)
CombineRgn hwnd1, hwnd1, hwnd2, 2
I = I + 1
Loop
End With
SetWindowRgn hwnd, hwnd1, True
End Sub

Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then
Dim hwnd As Long
If Val(Application.Version) < 9 Then
hwnd = FindWindow("ThunderXFrame", Me.Caption)
Else
hwnd = FindWindow("ThunderDFrame", Me.Caption)
End If
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End If

End Sub
并在工作簿的第一张表中列出了很多数字,由此所运行出来的便成了个椭圆形的窗口。这是我前段时间看到的一个关于API窗口的运用,但研究了很久,我发觉我还是不懂以上代码具体是什么含义,每一句有什么具体作用。。。
请各位高手帮帮忙,给我注解一下这些代码,行吗?非常非常非常之感谢!
...全文
279 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
fcl2008 2008-05-07
  • 打赏
  • 举报
回复
哦.明白了.谢谢!
icansaymyabc 2008-05-05
  • 打赏
  • 举报
回复
如果你没有掌握 Windows 系统的相关基础知识的话无法给你注释。

没有谁有时间把《Windows编程基础》整本书的内容写到一个程序的注释中去。

如果你懂一点窗口管理的相关概念的话,

hwnd = FindWindow("ThunderDFrame", Me.Caption)

这样的语句是其意自明的,跟本无须注释。否则的话,给你注释成这个样子你也依然一团迷雾:


'查找类型名为 Me.Caption, 类型是 "ThunderDFrame" 的窗口,返回它的句柄
hwnd = FindWindow("ThunderDFrame", Me.Caption)

说实话,上面的这种注释纯属画蛇添足。是被人写文章骂过的那种恶劣风格的无用注释
icansaymyabc 2008-05-05
  • 打赏
  • 举报
回复
Private Declare Sub ReleaseCapture Lib "user32" () 
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 Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong 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 Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Const GWL_STYLE As Long = (-16)
Private Const WS_CAPTION As Long = &HC00000
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2


Private Sub CommandButton1_Click()
Unload Me
ThisWorkbook.Close False
End Sub

Private Sub UserForm_Initialize()
Dim hwnd, hwnd1, hwnd2, wdc, colorl As Long
Dim I As Integer
If Val(Application.Version) < 9 Then
hwnd = FindWindow("ThunderXFrame", Me.Caption)
Else
hwnd = FindWindow("ThunderDFrame", Me.Caption)
End If

IStyle = GetWindowLong(hwnd, GWL_STYLE)
IStyle = IStyle And Not WS_CAPTION
SetWindowLong hwnd, GWL_STYLE, IStyle
DrawMenuBar hwnd
With Worksheets(1)
hwnd1 = CreateRectRgn(.Cells(1, 2).Value, .Cells(1, 1).Value, .Cells(1, 3).Value, .Cells(1, 1) + 1)
I = 2
Do While .Cells(I, 1).Value <> ""
hwnd2 = CreateRectRgn(.Cells(I, 2).Value, .Cells(I, 1).Value, .Cells(I, 3).Value, .Cells(I, 1) + 1)
CombineRgn hwnd1, hwnd1, hwnd2, 2
I = I + 1
Loop
End With
SetWindowRgn hwnd, hwnd1, True
End Sub

Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then
Dim hwnd As Long
If Val(Application.Version) < 9 Then
hwnd = FindWindow("ThunderXFrame", Me.Caption)
Else
hwnd = FindWindow("ThunderDFrame", Me.Caption)
End If
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End If

End Sub
fcl2008 2008-05-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ChinaOBS 的回复:]
建议先看看 API 帮助
[/Quote]
看了还是感觉一团迷雾...
主要我用的是VBA编程,对VB的一些知识可能了解得不够深..还请多指教
在此,同样感谢了!
fcl2008 2008-05-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 arong1234 的回复:]
都有函数名了,你应该去查MSDN,不应该耽误人家时间去做什么“注释”,遇到不懂得再问
[/Quote]
我看了很久,也找了很多相关资料看,但总感觉还很是复杂,还是理解得不够清晰...总也弄不明白所以才问的,并不是说我拿起不懂的就在问,拜托!!!
这也并不说耽误别人的时间吧,如果有懂的朋友,帮助一下,给别人一丝帮助也是检验下自己的真知,给自己积一份德吧?难道说帮助别人是耽误时间????
ChinaOBS 2008-05-03
  • 打赏
  • 举报
回复
建议先看看 API 帮助
arong1234 2008-05-02
  • 打赏
  • 举报
回复
都有函数名了,你应该去查MSDN,不应该耽误人家时间去做什么“注释”,遇到不懂得再问

5,139

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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