Due to time rush, translation is not very good, I hope everyone will take a look.
The load GIFs, JPGs files to the surface Author: W-Buffer relatively speaking, not very difficult, we do not need a decoder to get every byte JPG or any similar times, on the contrary, we will use a picture Box to open a picture, then pass it to the surface, but first I 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 LongPublic Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As LongPublic Declare Function DeleteDC Lib "gdi32 "(ByVal hdc As Long) As LongPublic Declare Function SelectObject Lib" gdi32 "(ByVal hdc As Long, ByVal hObject As Long) As LongPublic 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 NSRCHEIGHT As Long, Byval DWROP As Long AS Long now We want to load pictures Well prepared DIM PICT1 AS stdpicture Pict1 = loadingPicture ("MyPict.jpg") creates surface: DIM TDESC AS DDSURFACEDESC 2TDesc.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTHTDesc.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAINTDesc.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 LongSurfDC = Surf.GetDCPictDC = CreateCompatibleDC (0) SelectObject Pict1.Handle, PictDC Dcs and we will use to copy the StretchBlt Bitblt or to a surface Pic1 Copy only as the size: Bitblt Surfdc, 0, 0, TDesc.LWidth, TDesc.LHEight, Pictdc, 0, 0, VBSRCCPY
Now copy and change the image size StretchBlt SurfDC, 0, 0, StretchWidth, StretchHeight, PictDC, 0, 0, TDesc.lWidth, TDesc.lWidth, vbSrcCopy release DC: Surf.ReleaseDC SurfDCDelecteDC PictDCSet Pict1 = Nothing next step how to do it? Download Surfutil. BAS, I will use this skill to create and load the picture Note: Sometimes Stretchblt does not display GIF normally, that is, I added a Bitblt this function.
Special effects you will be lazy, don't want to use C / C or compile to create a dynamic connection library, use the dynamic connection library to complete the special effect? Let Blitter (I don't know, you can't find it, may be GLITTER, flash) Grating operation (ROP) work! My motto is to make the smallest effort to bring you the biggest remuneration! There are many ROP constants available in VB: vbsrcpaint - logic or operation, source, and target pictures, make a simulated alpha mixing effect. VBSRCAND - Logic and operation, grayscale effect. VBSRCINVERT - Logic Visual or Operation. VBSRCERASE - Follow the target picture, then logically with the source picture and the operation vbsrccopy - copy the original picture directly to the target picture, replace it is replaced? (Replacing it ") VBDSTINVERT - flip the target picture, all ignore the original picture. VBNOTSRCCOPY - flip the source image, and then copy directly to the target, is it a complete replacement? (Replacing it completely) VBNOTSRCERASE - logically or operations on the source image and target pictures, flip. Now we use these ROPs with two ways to perform destruction. We can use the APIBITBLT function, or you can use DirectX's BLTFX function. Only the user's graphics card can use hardware to support ROP instead of software to simulate ROP, BLTFX can work, otherwise the BLTFX will fail! In any case, when the BLTFX fails, the API's Bitblt is still called. In the software, when everything is ready, Bitblt will never fail! (Relatives: When using BLTFX, it can make the surface into the surface in memory to quickly access the Blitter of the graphics (and the same, not knowing it, it can't be found), and when other use API functions Bitblt, It is perfectly placed on the system memory, otherwise the data will be changed from the memory, then it will return to the memory, no efficiency!) Easy to know if the user's graphics card is hardware supports special ROP It's a good thing, I wrote a simple function to confirm: Private function Testrop (Byref Surfback As Directdrawsurface7, LNGrop as long) AS Boolean
Dim objbltfx as DDBLTFXDIM RectTemp As Rectdim Surftemp as DirectDrawSurface7Dim Udtdsd AS DDSurfaceDesc2
'Creating a temporary surface udtDDSD.lFlags = DDSD_HEIGHT Or DDSD_WIDTHudtDDSD.lHeight = 1udtDDSD.lWidth = 1Set surfTemp = mdd.CreateSurface (udtDDSD)' provided BltFx the ROP opcodes objBltFx.lROP = lngROP
'Source and target rectangular RectTemp.right = 1RectTemp.Bottom = 1
'Test BLTFX's Ability IF SurfBack.bltfx (RectTemp, Surftemp, RectTemp, DDBLT_ROP or DDBLT_WAIT, OBJBLTFX) <> 0 THENTESTROP = falseelseteStrop = trueEnd IF
End function is simple to pass this function a reference to your current backup cache and the ROP constant you are interested in, it will give you the user hardware to tell you to tell you, it performs a blit example of a BLTFX and the test error and return error. (Note: If you know if you know, you don't have to read it. There are some English phrases that are not easy to translate into Chinese) SIMPLY PASS THIS FUNCTION A Reference to your current backbuffer and it rop constant you're interested in and it Will Inform you IT does this by performing a sample bltfx blit and examining the error code Returned. Now I know if we want ROP has been supported, we can continue and implement our blit, if ROP Support, we can also use BLTFX like this:
Objbltfx.lrop = lnGropmsurfBack.bltfx RectDest, SurfDisplay, RectSource, DDBLT_ROP OR DDBLT_WAIT, OBJBLTFXOBJBLTFX definition type is DDBLTFX, which must be loaded with the ROP we want to perform (stored in LNGROP). Once, we have our DDBLTFX type fill, we can use the backup cached BLTFX method, transfer source and target rectangle, our desired surface, a point constant (DDBLT_ROP, and DDBLT_WAIT) and ObjblTFX, constant ddblt_rop is necessary, it will notify Bltfx We want to use the DDBLTFX structure of the member LROP. IF We're Forced to Use the Bitblt API, IT Can Be Handled In this fashion:
'Lock main surface DCSLNGDESTDC = msurfback.getdclngsrcdc = surfdisplay.getdc
'Do the fancy old-fashioned blitbitblt lngdestdddc, intx, ines, intWidth, Intheight, LNGSRCDC, 0, 0, LNGROP
'Release dcssrcdisplay.releasedc lngsrcdcmsurfback.releaseDC LNGDESTDC first we need to get the source (related to Blitte's surface, and Blitter, may be DirectX's DC) and target (backup cache) DC, once we all have, us Take them as a Bitblt parameter, then define (? Sprite's true monster) and our expectative ROP (LNGROP), then you must release DC to avoid the computer. (First we need to acquire the source (surface to be blitted) and destination (backbuffer) DCs. Once we have them, we feed this data into the BitBlt call, along with our sprite dimensions and the ROP we desire (lngROP). Afterward We Must Release The DCS, LEST WE FREEZE THE Computer now you got it! A little magic function allows you to use these beautiful gratings in your program or game, download the source code down, let's take a look at all different ROP effects! So there you have it! A few Magic Little Functions and You Can Employ Nifty Raster Operations in Your Games and Programs. Download The Source To See All of The Different Rops In Action.
Recommended DirectInput Mouse Have a lot of things that you look familiar here, then because most of my learning is from the DirectX7 using the mouse is from the DirectInput tutorial from Lucky, I only exceed a little bit of the tutorial, in this tutorial You see how to "cut" mouse when it is leaving from the screen, how to "Hot Spots" (About Hot Spots, please refer to People's Posts Publishing House "Visual Basic 6.0 and Windows API lecture Chapter 15 Page 597 "Add to the mouse's pointer, put the mouse pointer on the surface of the mouse pointer is really good, it can first help you read the Lucky DirectInput tutorial, if you haven't, I don't want to explain what you can learn here. .
You will notice that when you move your mouse in Windows, you will notice that you can only move it to the bottom or right, until there is only one pixel left (the X, Y coordinate left of the mouse). If you try to paint your mouse pointer (or even the part) with the mouse pointer in DX, when leaving the screen / DX surface, it seems to ignore the line, that's because you can't be This is not possible to happen from any stuff. So we need to see us and cut it on the screen outside the screen.
In fact, in Windows, if you really have mentioned more, you will hide your mouse "Hot Spot", your mouse pointer will stop up and down, in fact, Hotspot is your mouse pointer One pixel on Windows, your mouse refers to Windows, not 32 × 32 pixels, it is just a single pixel, Windows only places the mouse pointer around this pixel to make you look like a mouse pointer Just look like, if your mouse's HotSpot size is 32 × 32 pixels, then you will be more likely to click more than one button, if the button is very close to each other, then in turn, a hotspot is a mouse The most important pixels in the pointer, the rest, as the accompanying lining, such as the arrow, the top of the pen, or the middle of the pointer to the form size is its hotspot. OK, let's try to get HotSpot from a mouse pointer. You will need these variables and statements:
'Detection and shearing mouse DECLARE FUNCTRECTRECT LIB "User32" (LPSRC1RECT AS Rect, LPSRC2RECT AS RECT) AS Long
'Variable declared as DirectX7! Global DXMouse As New DirectX7' The DirectInput object! DOUBLE-DUH! Global DXMouseInput As DirectInput 'Input Device object we'll use for the mouse Global DXMouseInputDev As DirectInputDevice' Mouse state type Global DXMouseState As DIMOUSESTATE
'Mouse moving speed global const mouse_speed = 1' Mouse mobile rectangular Range Global Mouse_Rect As Rect 'Mouse Pointer X (horizontal) Coordinate Global DXMOUSEX AS INTEGER' Mouse Pointer Y (vertical) Coordinate Global DXMOUSEY AS INTEGER 'mouse left Is the key to press? Global DXLEFTMOUSEBUTTON AS BOOLEAN 'mouse right button is pressed? Global DXRightmouseButton as Boolean
'On the rectangle where the mouse HotSpot Mouse Hot Spot Rectangle Global HotSpot_Rect As RECT' X-coordinate of the mouse HotSpot Global DXMouseHotX As Integer 'HotSpot the Y coordinate of the mouse Global DXMouseHotY' whether mouse Global DXMouseVisible As Boolean
Those are the evaluation of Lucky's source file tutorial. I don't want to copy Lucky, just like the foregoing "" Most of what I have learned is about the DirectX7 mouse is from the Directinput tutorial from Lucky ", I did a little about variables The change is because his variable name is not what I feel.
Now, 4 new Dongdong is HotSpot_Rect, Dxmousehotx, Dxmousehoty, and DXMouseVisible.
Hotspot_rect is to let us change the RECT to the stuff: When HotSpot is on the screen, he will only have a pixel as big. DXMousehotX and DXMousehoty are the X and Y coordinates of the mouse pointer: the top of the left is defined as (1, 1) DXMousevisible is just a boolean value tells us if we are ready to draw the mouse to the screen, because sometimes we don't want to This is the new THE CHE CHE CHE CHE CHE CHE CHE CAN All Unded The Variable Names So We Can All Understand Them. Now there is an initialization process, which is as accurate as Lucky's source code (in fact, Same), but I changed the variable name, so we can understand it easier. Sub Initialize () 'If we can not properly initialized, caught errors On Error Resume Next' to create a DirectInput component Set DXMouseInput = DXMouse.DirectInputCreate () 'mouse tracking device as diMouse Set DXMouseInputDev = DXMouseInput.CreateDevice ( "GUID_SysMouse" ) 'uniqueness receive mouse input device, but only when prospects mode is active DXMouseInputDev.SetCommonDataFormat DIFORMAT_MOUSE DXMouseInputDev.SetCooperativeLevel frmMain.hWnd, DISCL_FOREGROUND Or DISCL_EXCLUSIVE DXMouseInputDev.Acquire
'Initialized mouse variables DXMOUSEX = 0 DXMOUSEY = 0 DXLEFTMOUSEBUTTON = false DXRightmouseButton = FALSE
End Sub
Here I don't want to explain anything, you will have to look at the Lucky tutorial and source code to explain your own, add some old materials to the new material Sub DXMOUSEREFRESH () 'refresh mouse variable' to get the current mouse state DXMOUSEINPUTDEV. GetDeviceStateMouse DXMOUSTATE
'Forced tracking is worse than re-track if Err.Number <> 0 Then DXMOUSEINPUTDEV.ACQUIRE
'If you fail, exit this process if err.Number <> 0 Then Exit Sub on Error Goto 0
'According to HotSpot Support to calibrate the mouse X coordinate DXMOUSEX = DXMOUSEX DXMOUSESTATE.X * mouse_speed if DXMousex <0 Then DXMOUSEX = 0 if DXMousex> 640 - DXMousehotX Then DXMOUSEX = 640 - DXMousehotx
'According to HotSpot Support to calibrate mouse y coordinate DXMOUSEY = DXMOUSEY DXMOUSESTATE.Y * MOUSE_SPEED IF DXMOUSEY <0 THEN DXMOUSEY = 0 if DXMOUSEY> 480 - DXMOUSEHOTY THEN DXMOUSEY = 480 - DXMousehoty
'State detecting left mouse button If DXMouseState.buttons (0) <> 0 Then DXLeftMouseButton = True If DXMouseState.buttons (0) = 0 Then DXLeftMouseButton = False' right-state detecting If DXMouseState.buttons (1) <> 0 Then DXRightMouseButton = True if DXMOUSSTATE.BUTTONS (1) = 0 THEN DXRIGHTMOUSEBUTTON = FALSE
'If the mouse icon removes the surface, it cannot be displayed, so when the mouse is close to the edge, the mouse is calibrated if DXMOUSEX <= 608 Then Let Mouse_Rect.Right = 32 else let mouse_rect.right = 640 - DXMOUSEX END IF
IF DXMOUSEY <= 448 Then let mouse_rect.bottom = 32 else let mouse_rect.bottom = 480 - DXMOUSEY END IF
Hotspot_Rect.Left = DXMOUSEX HotSpot_Rect.top = DXMOUSEY HotSpot_Rect.Right = DXMOUSEX 1 Hotspot_Rect.Bottom = DXMOUSEY 1
'If the timing is mature, let the mouse display. If DXMousevisible = TRUE THEN DRAWMOUSE END IF
End Sub
Don't forget to set DXMousehotx, DXMousehoty, and DXMouseVisible variables before calling this process. WOW, that code is very much, you will notice half of the number of people in front of the code and Lucky's RefreshmouseState, which only changes support for screen size and Hot spot, in Lucky tutorial In the source code, you remove your mouse pointer out of the screen (I am not the Lucky language attack, don't make a mistake). If DXMousehotx is subtracted from the width of the screen, minus DXMousehot from the screen, you have to admit that you move the mouse to the screen, when DXMousehotx is on the right side of the screen, the mouse will stop moving to the right, The same is true for the left.
However, that is just a part, we must still "cut" down the mouse pointer, otherwise the mouse pointer will not be disappeared, that is why if ... The reason is there. Those code will change mouse_rect.right and mouse_rect.bottom, because when the mouse is moved out of the screen, the size of the Mouse_rect is changed after the changed Mouse_rect is the correct size. After the mouse is cut, we want to move the position of HotSpot_Rect, we can change his Left, Top, Right, and Bottom to achieve.
If you can see the mouse, the last two lines are visible to check the mouse, if visible, draw it out
This is a small process, and it uses Bltfast to uptrate the mouse on the screen, use the correct shear method to cut the size of Mouse_rect, I don't want to be too detailed, how to complete, you are best in Lucky I found it in the tutorial.
Public Sub DrawMouse () SurfBack.bltfast DXMousex, Dxmounty, Surfmain, Mouse_Rect, DDBLTFAST_SRCCOLORKEY OR DDBLTFAST_WAIT END SUB
Surfback is my backup cache, SurfMain is an invisible surface, SurfMain is used to store mouse pointer pictures
Special thanks to Lucky and his DirectX tutorial
Happy programming,