?? ddrawwrapper.cpp
字號:
// DDrawWrapper.cpp : Defines the entry point for the application.
//
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
//-----------------------------------------------------------------------------
// Include files
//-----------------------------------------------------------------------------
#include <windows.h>
#include <ddraw.h>
#include <stdio.h>
#include <stdarg.h>
#include "ddutil.h"
#include "stdafx.h"
#include "HDirectDraw.h"
#include "HDDrawSurf.h"
#define TIMER_ID 1
BOOL g_bActive=FALSE;
BOOL g_bFirst=0;
LPCTSTR szFrontMsg="Front!";
LPCTSTR szBackMsg ="Back!";
const DWORD nFrames=15;
static char * fn[nFrames]={
"ManWalk_0001.bmp","ManWalk_0002.bmp","ManWalk_0003.bmp",
"ManWalk_0004.bmp","ManWalk_0005.bmp","ManWalk_0006.bmp",
"ManWalk_0007.bmp","ManWalk_0008.bmp","ManWalk_0009.bmp",
"ManWalk_0010.bmp","ManWalk_0011.bmp","ManWalk_0012.bmp",
"ManWalk_0013.bmp","ManWalk_0014.bmp","ManWalk_0015.bmp"
};
static char * skyfn="sky1.bmp";
static char * sceneryfn="scenery256.bmp";
CDirectDraw DDraw;
CDDrawSurf Surf[30];
CDDrawSurf Sky;
CDDrawSurf Scenery;
_SURFACE_DATA g_Dat;
void DeleteAllObjects()
{
DDraw.CloseDDraw();
Sky.Delete();
Scenery.Delete();
for(int i=0;i<nFrames;i++)
{
Surf[i].Delete();
}
}
void UpdateFrame(HWND hWnd)
{
static BYTE phase = 0;
static BYTE bc = 0;
static int sx = 0;
static int sy = 337;
static int iframe=0;
DDraw.ClearBackBuffer();
//先貼表面:
Sky.Blit(0,0,FALSE);
Scenery.Blit(sx,0);
Surf[iframe].Blit(320,sy);
//再寫字:
DDraw.GetDC(DDraw.lpDDSBack);
{
DDraw.SetTextColor(RGB(255,255,0));
DDraw.SetBkColor(RGB(0,0,255));
if(phase==0)
{
DDraw.TextOut(400,10,"Primary");
phase=1;
}
else
{
DDraw.TextOut(400,10,"Back");
phase=0;
}
DDraw.TextOut(400,40,"Press the F12 key!");
//畫線:
HPEN op;
HPEN hp=::CreatePen(PS_SOLID,1,RGB(255,255,0));
op=(HPEN)::SelectObject(DDraw.hDC,hp);
DDraw.MoveTo(400,60);
::LineTo(DDraw.hDC,520,60);
::SelectObject(DDraw.hDC,op);
::DeleteObject(hp);
}
DDraw.ReleaseDC();
sx=(sx==-1280?0:sx-4);
iframe=(iframe==(nFrames-1)?0:iframe+1);
}
long FAR PASCAL
WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_ACTIVATEAPP:
{
// Pause if minimized or not the top window
g_bActive = (wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE);
if(g_bActive&&g_bFirst!=0)
{
int i;
if(!DDraw.Restore())
{
SaveInfo("DDraw_Restore失敗.txt","DDraw.Restore()失敗!");
}
if(!Sky.Restore())
{
SaveInfo("Sky_Restore失敗.txt","Sky.Restore()失敗!");
}
if(!Scenery.Restore())
{
SaveInfo("Scenery_Restore失敗.txt","Scenery.Restore()失敗!");
}
for(i=0;i<nFrames;i++)
{
if(!Surf[i].Restore())
{
SaveInfo("Surf_Restore失敗.txt","Surf.Restore()失敗!");
}
}
}
g_bFirst=1;
return 0L;
}
case WM_DESTROY:
// Clean up and close the app
DeleteAllObjects();
PostQuitMessage(0);
return 0L;
case WM_KEYDOWN:
// Handle any non-accelerated key commands
switch (wParam)
{
case VK_ESCAPE:
case VK_F12:
PostMessage(hWnd, WM_CLOSE, 0, 0);
return 0L;
}
break;
case WM_SETCURSOR:
// Turn off the cursor since this is a full-screen app
SetCursor(NULL);
return TRUE;
case WM_TIMER:
// Update and flip surfaces
if (g_bActive && TIMER_ID == wParam)
{
UpdateFrame(hWnd);
DDraw.Flip();
}
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
if (DDraw.CreateDDrawWnd(hInstance, nCmdShow,WindowProc) != TRUE)
{
return FALSE;
}
if(DDraw.InitDDraw(640,480,8)!=TRUE)
{
return FALSE;
}
if(DDraw.BPP==8)
{
if(!DDraw.SetPalette("sky1.BMP"))
{
SaveInfo("創(chuàng)建調(diào)色板失敗.txt","SetPalette()失敗");
return FALSE;
}
}
//初始化表面參數(shù):
//小人:
memset(&g_Dat,0,sizeof(g_Dat));
g_Dat.BPP=8;
g_Dat.DisplayBPP=8;
g_Dat.clrkeyFlags=TRUE;
g_Dat.Height=128;
g_Dat.lpDD=DDraw.lpDD;
g_Dat.Colorkey=RGB(255,255,255);
g_Dat.lpDestSurf=DDraw.lpDDSBack;
g_Dat.m_bFromFile=1;
g_Dat.Width=128;
g_Dat.XS=0;
g_Dat.YS=0;
for(DWORD i=0;i<nFrames;i++)
{
strcpy(g_Dat.fn,fn[i]);
if(!Surf[i].Create(&g_Dat))
{
SaveInfo("創(chuàng)建表面失敗.txt","!Surf[i].Create(&g_Dat)");
return 0;
}
}
//天空:
g_Dat.Height=480;
g_Dat.Width =640;
strcpy(g_Dat.fn,skyfn);
Sky.Create(&g_Dat);
//背景:
g_Dat.Height=480;
g_Dat.Width =1920;
strcpy(g_Dat.fn,sceneryfn);
Scenery.Create(&g_Dat);
if(DDraw.SetTimer(1,1)!=TRUE)
{
return FALSE;
}
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -