Making a graphic form with an API

zhaozj2021-02-16  59

Program description:

Using the getBitMapBits function, read the color information of the picture in an array, then scan the data of the array, use the CreateRectrGn function to generate each useful point chart form, and use the COMBinerGN function to merge the useful image, make up the desired Form, finally use setWindowRgn to set the form

code:

Module1

Public Declare Function GetObjectApi Lib "GDI32" Alias ​​"getObject As long, Byval Ncount As long, LPOBJECT AS ANY) AS Long

Public Declare Function DeleteObject Lib "GDI32" (Byval Hobject As Long) AS Long

Public Declare Function SetWindowRgn LIB "User32" (Byval HRGN As Long, Byval Bredraw As Boolean) AS Long, BYVAL BREDRAW AS BOOLEAN

Public Declare Function CreateRectrGn LIB "GDI32" (Byval Y1 As Long, Byval x2 As long, Byval Y2 as long) AS Long

Public Declare Function Combinergn LIB "GDI32" (Byval Hsrcrgn1 As Long, Byval Hsrcrgn2 As Long, Byval NCombinemode As long) AS Long

Public const rgn_or = 2

Public Declare Function GetBitmapBits LIB "GDI32" (Byval DWCount As Long, LPBITS AS ANY) AS Long

Public Type Bitmap Note: 14 Bytes

BMTYPE AS long

BMWIDTH AS long

Bmheight as long

BMWIDTHBYTES AS Long

BMPLANES AS INTEGER

BMBITSPIEL AS INTEGER

BMBITS As Long

End Type

DIM BMBYTE () AS BYTE

Public Declare Function ReleaseCapture LIB "User32" () AS Long

Public Declare Function SendMessage Lib "User32" Alias ​​"SendMessagea" (Byval Hwnd As Long, Byval WParam As Long, LParam as Any) AS Long

Note: public const wm_syscommand = & h112

Note: Public const sc_move = & hf012

Public const htcaption = 2

Public const wm_nclbuttondown = & ha1

Public Sub SetAutorgn (HFORM AS FORM, OPTIONAL TRANSCOLOR AS BYTE = VBNULL)

DIM X as long, y as long

DIM RGN1 AS Long, RGN2 As Longdim Spos As Long, EPOS As Long

DIM BM As Bitmap

DIM HBM As Long

DIM WID AS Long, HGT As Long

DIM Xoff as long, yoff as long

Get a form background image size

HBM = HFORM.PICTURE

GetObjectApi HBM, LEN (BM), BM

WID = BM.BMWIDTH

HGT = BM.BMHEIGHT

Redim Bmbyte (1 to wid, 1 to HGT)

GetBitmapBits HBM, WID * HGT, BMBYTE (1, 1) Get image array

If there is no incoming transcolor parameter, use the first pixel as a transparent color.

IF transcolor = vbnull damcolor = BMBYTE (1, 1)

RGN1 = CreateRectrGN (0, 0, 0, 0)

For y = 1 to HGT progressive scan

X = 0

DO

X = x 1

While (BMByte (x, y) = transcolor) and (x

X = x 1 Skip is a point of transparent color

Wend

Spos = x

While (BMBYTE (X, Y) <> transcolor) and (x

X = x 1 Skip is not a transparent color point

Wend

EPOS = X - 1

Note: This section is a merger area

IF spos <= epos Then

RGN2 = CreateRectrgn (Spos - 1, Y - 1, EPOS, Y)

Combinergn RGN1, RGN1, RGN2, RGN_OR

DeleteObject RGN2

END IF

Loop unsil x> = WID

Next y

SetwindowRGN HFORM.HWND, RGN1, TRUE Set Form Shape Area

DeleteObject RGN1

End Sub

Form1

Private sub flow_load ()

Form1.Left = Screen.width / 2 - Form1.Width / 2

Form1.top = Screen.height / 2 - Form1.Height / 2

If Me.Picture <> 0 THEN CALL SetAutorgn (ME)

End Sub

Private Sub Form_MouseDown (Button As Integer, Shift As Integer, x as single, y as single)

Mobile form

If Button = Vbleftbutton Then

ReleaseCapture

SendMessage Me.hwnd, WM_NCLButtondown, HTCAPTION, 0 &

END IF

End Sub

转载请注明原文地址:https://www.9cbs.com/read-24262.html

New Post(0)