|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#define WIN32_LEAN_AND_MEAN
#define INITGUID
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <io.h>
#include <fcntl.h>
#include <ddraw.h>
#define WIN_NAME "fan"
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000)?1:0)
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef unsigned char UCHAR;
typedef unsigned char BYTE;
LPDIRECTDRAW7 lpdd = NULL;
LPDIRECTDRAWPALETTE lpddpal = NULL;
LPDIRECTDRAWSURFACE7 lpddsprimary = NULL;
DDSURFACEDESC2 ddsd;
HWND main_windows_handle = NULL;
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (msg)
{
case WM_CREATE:
{
return 0;
}break;
case WM_PAINT:
{
hdc = BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return 0;
}break;
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}break;
default:break;
}
return( DefWindowProc(hwnd,msg,wparam,lparam) );
}
int Game_Main(void *parms = NULL , int num_parms = 0)
{
if( KEYDOWN(VK_ESCAPE) )
SendMessage(main_windows_handle , WM_CLOSE , 0 , 0);
memset(&ddsd , 0 , sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
if(FAILED(lpddsprimary->Lock(NULL, &ddsd,
DDLOCK_SURFACEMEMORYPTR |
DDLOCK_WAIT,NULL)))
{
return 0;
}
int mempitch = (int)ddsd.lPitch;
UCHAR *video_buffer = (UCHAR *)ddsd.lpSurface;
for(int index = 0;index < 100 ; index++)
{
UCHAR color = rand()%256;
int x = rand()%640;
int y = rand()%480;
video_buffer[x+y*mempitch] = color;
}
if(FAILED(lpddsprimary->Unlock(NULL)))
return 0;
Sleep(30);
return 1;
}
int Game_Init(void *parms = NULL , int num_parms = 0)
{
if(FAILED(DirectDrawCreateEx(NULL,(void **)&lpdd, IID_IDirectDraw7, NULL)))
{
return 0;
}
if(FAILED(lpdd->SetCooperativeLevel(main_windows_handle , DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX
| DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
{
return 0;
}
if (FAILED(lpdd->SetDisplayMode(800, 600, 16,0,0)))
{
return 0;
}
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
if(FAILED(lpdd->CreateSurface(&ddsd , &lpddsprimary , NULL)))
{
return 0;
}
PALETTEENTRY palette[256];
srand(time(NULL));
for(int color = 1; color < 255 ; color++)
{
palette[color].peBlue = rand()%256;
palette[color].peRed = rand()%256;
palette[color].peGreen = rand()%256;
palette[color].peFlags = PC_NOCOLLAPSE;
}
palette[0].peBlue = 0;
palette[0].peRed = 0;
palette[0].peGreen = 0;
palette[0].peFlags = PC_NOCOLLAPSE;
palette[255].peBlue = 255;
palette[255].peRed = 255;
palette[255].peGreen = 255;
palette[255].peFlags = PC_NOCOLLAPSE;
if(FAILED(lpdd->CreatePalette(DDPCAPS_8BIT |
DDPCAPS_ALLOW256 |
DDPCAPS_INITIALIZE,
palette,
&lpddpal,
NULL
)))
{
return 0;
}
if (FAILED(lpddsprimary->SetPalette(lpddpal)))
{
return(0);
}
return 1;
}
int Game_ShutDown(void *parms = NULL , int num_parms = 0)
{
if(lpdd)
{
lpdd->Release();
lpdd = NULL;
}
if(lpddsprimary)
{
lpddsprimary->Release();
lpddsprimary = NULL;
}
if(lpddpal)
{
lpddpal->Release();
lpddpal = NULL;
}
return 1;
}
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int necmshow)
{
WNDCLASSEX winclass;
HWND hwnd;
MSG msg;
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon( NULL ,IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL ,IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WIN_NAME;
winclass.hIconSm = LoadIcon( NULL ,IDI_APPLICATION);
if(!RegisterClassEx(&winclass))
{
return 0;
}
if(!(hwnd = CreateWindowEx(NULL,
WIN_NAME,"cheng",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,0,
640,480,
NULL,
NULL,
hinstance,
NULL)))
{
return 0;
}
main_windows_handle = hwnd;
Game_Init();
while(TRUE)
{
if(PeekMessage(&msg , NULL , 0 , 0 , PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Game_Main();
}
Game_ShutDown();
return (msg.wParam);
}
代码没有bug,但就是运行不出来,没有全屏,也没有随机像素点显示,求大神指教:loveliness:
|
|