1. 引用 API 函数

' API函数
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Public Declare Function ShowWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Declare Function SetWindowPos Lib "user32" ( _
ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Public Declare Function SetLayeredWindowAttributes Lib "user32" ( _
ByVal hwnd As Long, _
ByVal crKey As Long, _
ByVal bAlpha As Byte, _
ByVal dwFlags As Long) As Long
Public Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetMenuItemCount Lib "user32" (ByVal hmenu As Long) As Long
Public Declare Function RemoveMenu Lib "user32" ( _
ByVal hmenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long) As Long
Public Declare Function DeleteMenu Lib "user32" ( _
ByVal hmenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long) As Long
Public Declare Function GetSystemMenu Lib "user32" ( _
ByVal hwnd As Long, _
ByVal bRevert As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
'获取 屏幕高、宽
Public Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Const SM_CXSCREEN = 0 'Width of screen
Const SM_CYSCREEN = 1 'Height of screen

Public Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function AnimateWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal dwTime As Long, _
ByVal dwFlags As Long) As Long
Public Declare Function MoveWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

' API常量
Public Const GWL_STYLE = (-16)
Public Const GWL_EXSTYLE = (-20)

Public Const WS_MAXIMIZEBOX = &H10000
Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_THICKFRAME = &H40000
Public Const WS_EX_LAYERED = &H80000
Public Const WS_SYSMENU = &H80000
Public Const WS_CAPTION = &HC00000

Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3

Public Const LWA_ALPHA = &H2

Public Const MF_BYCOMMAND = &H0
Public Const MF_BYPOSITION = &H400&
Public Const MF_DISABLED = &H2&
Public Const MF_REMOVE = &H1000&

Public Const SC_CLOSE = &HF060
Public Const SC_MOVE = &HF010

Public Const WM_SYSCOMMAND = &H112

Public Const AW_ACTIVATE = &H20000
Public Const AW_BLEND = &H80000

Public Enum ESetWindowPosStyles
SWP_SHOWWINDOW = &H40
SWP_HIDEWINDOW = &H80
SWP_FRAMECHANGED = &H20
SWP_NOACTIVATE = &H10
SWP_NOCOPYBITS = &H100
SWP_NOMOVE = &H2
SWP_NOOWNERZORDER = &H200
SWP_NOREDRAW = &H8
SWP_NOREPOSITION = SWP_NOOWNERZORDER
SWP_NOSIZE = &H1
SWP_NOZORDER = &H4
SWP_DRAWFRAME = SWP_FRAMECHANGED
HWND_TOPMOST = -1
HWND_NOTOPMOST = -2
End Enum

Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

'API判断数组为空或没有初始化
Public Declare Function SafeArrayGetDim Lib "oleaut32.dll" (ByRef saArray() As Any) As Long


2. 窗体 中……

  2.1 定义全局变量

    Dim hwnd As Long
    Dim lStyleOld As Long

  2.2 '窗体是否透明?

    Me.ToggleButton1 = Sheets("setting").Range("C17")
    hwnd = FindWindow(vbNullString, Me.Caption)
    ToggleButton1_Click

    Private Sub ToggleButton1_Click()

      Dim rtn As Long
      Dim touming As Integer

      touming = Sheets("setting").Range("C16")
      ' 保存旧的窗体风格
      lStyleOld = GetWindowLong(hwnd, GWL_EXSTYLE)

      rtn = lStyleOld Or WS_EX_LAYERED
      SetWindowLong hwnd, GWL_EXSTYLE, rtn

      If Me.ToggleButton1.Value = True Then
        SetLayeredWindowAttributes hwnd, 0, touming, LWA_ALPHA
      Else
        SetLayeredWindowAttributes hwnd, 0, 255, LWA_ALPHA
      End If

    End Sub

VBA Excel 引用 API,以实现“透明”的更多相关文章

  1. Excel引用

    Excel引用 1.绝对引用  相对引用 A:A   左右拉的话会自动变为  B:B,C:C等等 $A:$A  左右拉的话仍然是A列 A$1:A1  上下拉的话,会变成A$1:A2,A$1:A3等等

  2. POI操作Excel的API注意点总结

    本篇是关于POI.jar操作Excel的API注意事项 基数问题 说明:我使用的是POI 3.15版本的,在版本问题上建议大家,在版本稳定的基础上尽量使用高版本的 看过很多帖子在问一个问题:假设原来有 ...

  3. EXCEL 引用autocad vba,自动加载其类型库

    Sub AutoADDAutoCADTypeLib() Dim Ref As Variant Dim hasAutoTypeLib As Boolean, hasAXDBLib As Boolean, ...

  4. VBA Excel 常用 自定义函数

    1. 将 互换 Excel 列号(数字/字母) Public Function excelColumn_numLetter_interchange(numOrLetter) As String Dim ...

  5. Excel poi API基础教程!

    原文转子: http://blog.csdn.net/yellowd1/article/details/44628701 登录|注册     yellowd1的专栏       目录视图 摘要视图 订 ...

  6. VBA Excel WideCharToMultiByte Compile error on 64-bit System

    Compile Error: The code in this project must be updated for use on64-bit systems. Please review and ...

  7. java excel Workbook API

    此文摘自:http://blog.sina.com.cn/zenyunhai 1. int getNumberOfSheets() 获得工作薄(Workbook)中工作表(Sheet)的个数,示例: ...

  8. Excel引用和数学函数

    1.indirect函数--引用函数 indirect 英 [ˌɪndəˈrekt] 美 [ˌɪndəˈrekt] adj. 间接的;附带的;闪烁其词的;拐弯抹角的;迂回的;弯曲的 indirect函 ...

  9. 1.VBA Excel宏

    Excel VBA宏 在这一章中,让我们了解如何编写一个简单的宏.让我们一步一步来. 第1步:首先,让我们能够在Excel20XX'开发'菜单.做同样的,点击 File >> Option ...

随机推荐

  1. 使用PHP绘制统计图

    使用PHP画统计图的方法 第一种方法 <?php //最后一次修改:2004-6-21 //一个生成矩形图,曲线图的图形分析类 //作者:tonera //说明: //任何人可在任何场合自由使用 ...

  2. Linux下用Intel编译器编译安装NetCDF-Fortan库(4.2以后版本)

    本来这个问题真的没必要写的,可是真的困扰我太久%>_<%,决定还是记录一下. 首先,最权威清晰的安装文档还是官方的: Building the NetCDF-4.2 and later F ...

  3. Xcode 6 越狱开发基础

    最近接触到XCode越狱开发的问题,越狱开发首先iphone设备得越狱,然后安装Appsync,安装之后,安装ipa将不再验证程序签名的有效性,不签名的程序也可以直接在设备上运行,只需要保证IPA本身 ...

  4. <Chapter 2>2-1-2.安装Java SDK

    Java运行时环境的App Engine SDK运行在任何运行了Java SE开发工具(JDK)的电脑上.Java SDK App Engine 支持JDK 6,并且当运行App Engine的时候, ...

  5. Windwos Server 2008: 当网卡有多个IP地址时,如何指定缺省地址?

    这实际是一个当应用向外发起连接时,协议栈对源IP地址的选择问题.如果你的应用没有显式绑定一个本地地址,协议栈会选择一个"最佳"的本地地址来使用. 从 Vista 之后这个选择策略发 ...

  6. 第二百五十九天 how can I 坚持

    晚上,弟弟给我说了下他前几天发生的事,这孩子,有事就不知道说下,自己闷在心里. 刘松打算最近买房了,弟弟和建哥也考虑买,让他俩商量着来吧,早晚都得买. 有点揪心.想结婚不知道该和谁结... 睡觉.烦.

  7. Java设计模式系列之命令模式

    命令模式(Command)的定义 将一个请求封装为一个对象,从而可用不同的请求对客户进行参数化:对请求排队或记录日志,以及支持可撤销的操作,将”发出请求的对象”和”接收与执行这些请求的对象”分隔开来. ...

  8. 采用现代Objective-C

    多年来,Objective-C语言已经有了革命性的发展.虽然核心理念和实践保持不变,但语言中的部分内容经历了重大的变化和改进.现代化的Objective-C在类型安全.内存管理.性能.和其他方面都得到 ...

  9. UVALive 7454 Parentheses (栈+模拟)

    Parentheses 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/A Description http://7xjob4.c ...

  10. Spring EL Lists, Maps example

    In this article, we show you how to use Spring EL to get value from Map and List. Actually, the way ...