首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • excel+vba+APi窗口代码问题。。。急!!!请各位帮帮忙,在此万分感谢! [无满意答案结贴,结贴人:fcl2008]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-02 21: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窗口的运用,但研究了很久,我发觉我还是不懂以上代码具体是什么含义,每一句有什么具体作用。。。
    请各位高手帮帮忙,给我注解一下这些代码,行吗?非常非常非常之感谢!
    20  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-02 23:00:521楼 得分:0
    都有函数名了,你应该去查MSDN,不应该耽误人家时间去做什么“注释”,遇到不懂得再问
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • ChinaOBS
    • 等级:
    发表于:2008-05-03 11:04:082楼 得分:0
    建议先看看 API 帮助
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-04 23:08:473楼 得分:0
    引用 1 楼 arong1234 的回复:
    都有函数名了,你应该去查MSDN,不应该耽误人家时间去做什么“注释”,遇到不懂得再问

    我看了很久,也找了很多相关资料看,但总感觉还很是复杂,还是理解得不够清晰...总也弄不明白所以才问的,并不是说我拿起不懂的就在问,拜托!!!
    这也并不说耽误别人的时间吧,如果有懂的朋友,帮助一下,给别人一丝帮助也是检验下自己的真知,给自己积一份德吧?难道说帮助别人是耽误时间????
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-04 23:10:194楼 得分:0
    引用 2 楼 ChinaOBS 的回复:
    建议先看看 API 帮助

    看了还是感觉一团迷雾...
    主要我用的是VBA编程,对VB的一些知识可能了解得不够深..还请多指教
    在此,同样感谢了!
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-05 17:34:305楼 得分:0
    VBScript code
    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
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-05 18:01:036楼 得分:0
    如果你没有掌握 Windows 系统的相关基础知识的话无法给你注释。

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

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

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

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

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

    说实话,上面的这种注释纯属画蛇添足。是被人写文章骂过的那种恶劣风格的无用注释
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-07 11:39:137楼 得分:0
    哦.明白了.谢谢!
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • bjsun
    • 等级:
    发表于:2008-05-08 16:33:298楼 得分:0
    该回复于2008-05-09 09:40:45被管理员删除
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    北京创新乐知广告有限公司 版权所有 京 ICP 证 070598 号
    世纪乐知(北京)网络技术有限公司 提供技术支持
    Copyright © 2000-2008, CSDN.NET, All Rights Reserved