The application of GIFs, JPGs and Directinputmouse in VB game programming

Source: Internet
Author: User

Relatively speaking, it's not hard, we don't need a decoder to get every byte of jpg, or anything like that, instead, we'll use a picture frame to open a picture and then upload it to the surface, but first we need to declare the API function:

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 CreateCompatibleDC Lib "GDI32" (ByVal hdc as long) as long

Public Declare Function DeleteDC Lib "GDI32" (ByVal hdc as long) as long

Public Declare Function SelectObject Lib "GDI32" (ByVal hdc as Long, ByVal hobject as long) as long

Public Declare Function StretchBlt Lib "GDI32" (ByVal hdc 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 nsrcwidth as Long, ByVal Nsrch Eight as long, ByVal Dwrop as Long

Now we're ready to load the picture.

Dim Pict1 as StdPicture

Set Pict1 = LoadPicture ("mypict.jpg")

Create the Surface:

Dim Tdesc as DDSurfaceDesc2

Tdesc.lflags = Ddsd_caps or Ddsd_height or ddsd_width

TDesc.ddsCaps.lCaps = Ddscaps_offscreenplain

Tdesc.lheight = CLng (pict1.height * 0.001) * 567/screen.twipsperpixely)

Tdesc.lwidth = CLng (tpict.width * 0.001) * 567/screen.twipsperpixelx)

Set Surf = Ddraw.createsurface (TDESC)

Dim SURFDC as Long, pictdc as Long

SURFDC = Surf.getdc

PICTDC = CreateCompatibleDC (0)

SelectObject Pict1.handle, PICTDC

We will use DCs and BitBlt or StretchBlt to copy the Pic1 to the surface

Copy only the same size:

BitBlt SURFDC, 0, 0, tdesc.lwidth, tdesc.lheight, PICTDC, 0, 0, vbsrccopy

Now copy and change the picture size

StretchBlt SURFDC, 0, 0, stretchwidth, stretchheight, PICTDC, 0, 0, tdesc.lwidth, Tdesc.lwidth, vbsrccopy

Free DC:

Surf.releasedc SURFDC

Delectedc PICTDC

Set Pict1 = Nothing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.