当前位置: 源码素材网 » VB教程 » 详情页

在VB中图像创建不规则形状控件窗体的新方法.bas

  •   时间:2019-02-08
  • 概述:不规则窗体

在VB中图像创建不规则形状控件窗体的新方法.bas,创建基于非矩形的窗口,比如各种形状的窗体等:这里有一个例子要参考,使用的就是本方法:

Attribute VB_Name = "CreatePicForm"
Option Explicit
Private Const RGN_XOR = 3
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject 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 GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) 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 CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function GetPixel 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
Public Sub CreateRegion(DestPictureBox As Object, Optional frmName As Form)
On Error Resume Next
Dim hRgn As Long, hRect As RECT, hTempRgn As Long, tColour As Long, OldScaleMode As Integer, a As Long, AbsoluteX As Long, AbsoluteY As Long
Dim Color As Long, Hrect1 As RECT
OldScaleMode = DestPictureBox.ScaleMode
DestPictureBox.AutoRedraw = True
DestPictureBox.ScaleMode = 3
        Color = vbBlack ' RGB(255, 255, 255)
a = GetWindowRect(DestPictureBox.hwnd, hRect)
hRgn = CreateRectRgn(0, 0, hRect.Right, hRect.Bottom)
For AbsoluteX = 0 To DestPictureBox.ScaleWidth
    For AbsoluteY = 0 To DestPictureBox.ScaleHeight
        tColour = GetPixel(DestPictureBox.hdc, AbsoluteX, AbsoluteY)
'tColour的参数可为任何RGB颜色(属于这个值会被去掉)
        If tColour = Color Then  'Or tColour > RGB(255, 255, 220) Then
            hTempRgn = CreateRectRgn(AbsoluteX, AbsoluteY, AbsoluteX + 1, AbsoluteY + 1)

            a = CombineRgn(hRgn, hRgn, hTempRgn, RGN_XOR)

            a = DeleteObject(hTempRgn)
        End If
    Next AbsoluteY
Next AbsoluteX
a = SetWindowRgn(DestPictureBox.hwnd, hRgn, True)
DeleteObject hRgn
DestPictureBox.ScaleMode = OldScaleMode
If Err Then MsgBox Error, 16, Err
End Sub

    相关声明:

      若“在VB中图像创建不规则形状控件窗体的新方法.bas”有损您的权益,请告之我们删除内容。
      部分文章来源于网络,版权归原作者所有。