An example of a DirectX

zhaozj2021-02-08  269

Sender: Winson (Ah), Write Area: Programming Title: A DirectX Example Send Station: BBS Shuimu Tsinghua Station (WED JAN 14 16:49:07 1998) #include #include #include IDirectDraw * dd; IDirectDrawSurface * dds0, * dds1, * dds2, * dds3; IDirectDrawClipper * ddc; IDirectSound * ds; IDirectSoundBuffer * dsb1, * dsb2; int x = 20, y = 20 ; Int vx = 5, VY = 3; Void Moveball (HWND HWND, BOOL BMOVE) {BOOL BBOUNCE = False; Rect RectSrc, RectDest; Int Ox, Oy, Nx, Ny; GetClientRect (HWnd, & Redst); Clienttoscreen (hwnd, (Point *) & recthDest.Left; ClientToscreen (hwnd, (point *) & reviewdst.right); if (bmove) {ox = RectDest.Left Muldiv (RectDest.right - RectDest.Left - 32, x, 500); = RectDest.top Muldiv (RectDest.Bottom - RectDest.top - 32, y, 500); x = vx; y = Vy; if (x <0) {x = 0; vx = -VX; bbounce = True;} = f (x> = 500) {x = 1000 - x; vx = -VX; bbounce = true;} if (y <0) {y = -y; vy = -vy; Bbounce = true;} if (y> = 500) {y = 1000 - y; vy = -vy; bbounce = true;}} (bbounce) {dsb1-> setCurrentPosition (0); dsb1-> play (0, 0 , 0);}} nx = RectDest.LEFT MULDIV (RectDest.right - RectDest.Left - 32, x, 500); NY = RectDest.top Muldiv (RectDest.Bottom - RectDest.top - 32, Y, 500 RectSrc.Left = RectSrc.top = 0; RectSrc.right = RectSrc.bottom = 32; if (bmove) {recth = RectDest.top = 0; RectDest.Right =

RectDest.Bottom = 32; DDS2-> BLT (& RectDest, DDS3, & RectSrc, DDBLT_WAIT, NULL); IF (ABS (NX - OX) <32 && ABS (NY - OY) <32) {IF (NX Blt (& rectDest, dds1, & rectSrc, DDBLT_WAIT, NULL);} rectSrc.left = rectSrc.top = 0; rectSrc.right = rectSrc.bottom = 32; rectDest.left = ox; rectDest.top = oy; rectDest .right = RectDest.Left 32; RectDest.Bottom = RectDest.top 32; DDS0-> BLT (& RectDest, DDS2, & RectSrc, DDBLT_WAIT, NULL);} RectDest.LEFT = Nx; RectDest.top = Ny; RectDest. Right = RectDest.LEFT 32; RectDest.Bottom = RectDest.top 32; DDS0-> BLT (& RectDest, DDS1, &)

rectSrc, DDBLT_WAIT, NULL);} LRESULT CALLBACK WndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {HDC hDC; PAINTSTRUCT paintStruct; switch (uMsg) {case WM_PAINT: hDC = BeginPaint (hwnd, & paintStruct); if ( HDC! = NULL) {Moveball (hwnd, false); endpaint (hwnd, & paintstruct);} Break; Case WM_TIMER: Moveball (hwnd, true); Break; Case WM_KeyDown: Switch (wparam) {Case VK_LEFT: VX -; break; case VK_UP: vy--; break; case VK_RIGHT: vx ; break; case VK_DOWN: vy ; break; case VK_ESCAPE: PostMessage (hwnd, WM_CLOSE, 0, 0);} break; case WM_DESTROY: PostQuitMessage (0); Break; Default: Return DefwindowProc (HWND, UMSG, WPARAM, LPARAM) ;} Return 0;} int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR d3, int nCmdShow) {MSG msg; HWND hwnd; WNDCLASS wndClass; DDSURFACEDESC ddsd; DSBUFFERDESC dsbd; HDC hddDC; RECT rect; HRSRC hrsrc; HGLOBAL hRData; DWORD * pRData; LPBYTE pMem1, pMem2; DWORD dwSize1, dwSize2; if (hPrevInstance == NULL) {memset (& wndClass, 0, sizeof (wndClass)); wndClass.style = CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = WndProc; wndClass. Hinstance = hinstance; wndclass.hcursor = loadingcursor (null, idc_arrow);

wndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW 1); wndClass.lpszClassName = "BOUNCE"; if (RegisterClass (& wndClass)!) return FALSE;} hwnd = CreateWindow ( "BOUNCE", "BOUNCE", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0 , CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); DirectDrawCreate (NULL, & dd, NULL); dd-> SetCooperativeLevel (hwnd, DDSCL_NORMAL | DDSCL_NOWINDOWCHANGES); memset (& ddsd, 0, sizeof (DDSURFACEDESC)); ddsd.dwSize = sizeof (DDSURFACEDESC); ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; ddsd.dwFlags = DDSD_CAPS; dd-> CreateSurface (& ddsd, & dds0, NULL); dd-> CreateClipper (0, & ddc, NULL); dds0-> SetClipper (ddc ); ddc-> SetHWnd (0, hwnd); ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwHeight = 32; ddsd.dwWidth = 32; ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; dd-> CreateSurface (& ddsd, & dds1 NULL); DD-> CreateSurface (& DDSD, & DDS2, NULL); DD-> CreateSurface (& DDSD, & DDS3, NULL); DDS1-> Getdc (& HDDDC); Savedc (HDDDC); Rect.Lep = Rect.top = 0; Rect.right = rect.bottom = 32; FillRect (hddDC, & rect, (HBRUSH) (COLOR_WINDOW 1)); SelectObject (hddDC, GetStockObject (BLACK_BRUSH)); SelectObject (hddDC, GetStockObject (BLACK_PEN)); Ellipse (hddDC, 0, 0 , 32, 32); RestoredC (HDDDC, -1); DDS1-> ReleaseDC (HDDC); DDS3-> Getdc (& HDDDC); FillRect (HDDDC, & Rect, (Hbrush) (color_window 1)); DDS3->

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

New Post(0)