api.bas

来自「电脑编程技巧和源码。很不错的。」· BAS 代码 · 共 68 行

BAS
68
字号
Attribute VB_Name = "Module1"
 

 
 Public Const SRCCOPY = &HCC0020
 


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

 Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
 Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
 Public Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
 Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
 Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
 Public Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
 Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
 Public Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
 Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
 Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

 
'取色彩中的Red的值
Public Function GetRed(ByVal n As Long) As Integer
   GetRed = n Mod 256&
End Function

'取色彩中的Green的值
Public Function GetGreen(ByVal n As Long) As Integer
   GetGreen = (n \ 256&) Mod 256&
End Function

'取色彩中的Blue的值
Public Function GetBlue(ByVal n As Long) As Integer
   GetBlue = n \ 65536
End Function

  
'获取渐变色彩值
'入口参数:SrcColor 原色彩
'          Steps 步骤数
'          CurStep 当前的步子
'          DstColor 目标色彩
'返回值:当月前的色彩值
Public Function GetTrienColor(ByVal scrColor As Long, ByVal dstColor As Long, ByVal Steps As Integer, ByVal curStep As Integer) As Long
  Dim sR, sG, sB, dR, dG, dB As Integer
  
  sR = GetRed(scrColor)
  sG = GetGreen(scrColor)
  sB = GetBlue(scrColor)
  
  dR = GetRed(dstColor)
  dG = GetGreen(dstColor)
  dB = GetBlue(dstColor)
  
  sR = sR + curStep * (dR - sR) / Steps
  sG = sG + curStep * (dG - sG) / Steps
  sB = sB + curStep * (dB - sB) / Steps
  GetTrienColor = RGB(sR, sG, sB)
End Function

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?