bluesky1986yang 2017-07-23 04:14 采纳率: 0%
浏览 826

C++问题 从光盘中拷出来了 运行 一直报错 求大神帮忙

#define WIN32_LEAN_AND_MEAN // just say no to MFC

#define INITGUID

#include // include important windows stuff
#include
#include
#include // include important C/C++ stuff
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#include // include directdraw

// DEFINES ////////////////////////////////////////////////

// defines for windows
#define WINDOW_CLASS_NAME "WINCLASS1"

// default screen size
#define SCREEN_WIDTH 640 // size of screen
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 16 // bits per pixel

// TYPES //////////////////////////////////////////////////////

// basic unsigned types
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef unsigned char UCHAR;
typedef unsigned char BYTE;

// MACROS /////////////////////////////////////////////////

#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

// this builds a 16 bit color value in 5.5.5 format (1-bit alpha mode)
#define _RGB16BIT555(r,g,b) ((b & 31) + ((g & 31) << 5) + ((r & 31) << 10))

// this builds a 16 bit color value in 5.6.5 format (green dominate mode)
#define _RGB16BIT565(r,g,b) ((b & 31) + ((g & 63) << 5) + ((r & 31) << 11))

// initializes a direct draw struct
#define DDRAW_INIT_STRUCT(ddstruct) { memset(&ddstruct,0,sizeof(ddstruct)); ddstruct.dwSize=sizeof(ddstruct); }

// GLOBALS ////////////////////////////////////////////////
HWND main_window_handle = NULL; // globally track main window
HINSTANCE hinstance_app = NULL; // globally track hinstance

                            // directdraw stuff
                            //LPDIRECTGRAPHICS      lp;

LPDIRECTDRAW7 lpdd = NULL; // dd object
LPDIRECTDRAWSURFACE7 lpddsprimary = NULL; // dd primary surface
LPDIRECTDRAWSURFACE7 lpddsback = NULL; // dd back surface
LPDIRECTDRAWPALETTE lpddpal = NULL; // a pointer to the created dd palette
LPDIRECTDRAWCLIPPER lpddclipper = NULL; // dd clipper
PALETTEENTRY palette[256]; // color palette
PALETTEENTRY save_palette[256]; // used to save palettes
DDSURFACEDESC2 ddsd; // a direct draw surface description struct
DDBLTFX ddbltfx; // used to fill
DDSCAPS2 ddscaps; // a direct draw surface capabilities struct
HRESULT ddrval; // result back from dd calls
DWORD start_clock_count = 0; // used for timing

char buffer[80]; // general printing buffer

                                 // FUNCTIONS //////////////////////////////////////////////

LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
// this is the main message handler of the system
PAINTSTRUCT ps; // used in WM_PAINT
HDC hdc; // handle to a device context
char buffer[80]; // used to print strings

                        // what is the message 
switch (msg)
{
case WM_CREATE:
{
    // do initialization stuff here
    // return success
    return(0);
} break;

case WM_PAINT:
{
    // simply validate the window 
    hdc = BeginPaint(hwnd, &ps);

    // end painting
    EndPaint(hwnd, &ps);

    // return success
    return(0);
} break;

case WM_DESTROY:
{

    // kill the application, this sends a WM_QUIT message 
    PostQuitMessage(0);

    // return success
    return(0);
} break;

default:break;

} // end switch

  // process any messages that we didn't take care of 
return (DefWindowProc(hwnd, msg, wparam, lparam));

} // end WinProc

////////////////////////////////////////////////////////////

// WINMAIN ////////////////////////////////////////////////

int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{

WNDCLASSEX winclass; // this will hold the class we create
HWND       hwnd;     // generic window handle
MSG        msg;      // generic message
HDC        hdc;      // graphics device context

                     // first fill in the window class stucture
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 = NULL;// LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = NULL;// LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = TEXT(WINDOW_CLASS_NAME);
winclass.hIconSm = NULL;// LoadIcon(NULL, IDI_APPLICATION);

                        // save hinstance in global
hinstance_app = hinstance;

// register the window class
if (!RegisterClassEx(&winclass))
    return(0);

// create the window
if (!(hwnd = CreateWindowEx(NULL,                  // extended style
    TEXT(WINDOW_CLASS_NAME),     // class
    TEXT("DirectDraw 16-Bit Full-Screen Demo"), // title
    WS_POPUP | WS_VISIBLE,
    0, 0,     // initial x,y
    SCREEN_WIDTH, SCREEN_HEIGHT,  // initial width, height
    NULL,     // handle to parent 
    NULL,     // handle to menu
    hinstance,// instance of this application
    NULL))) // extra creation parms
    return(0);

// save main window handle
main_window_handle = hwnd;

// initialize  here
    // this is called once after the initial window is created and
    // before the main event loop is entered, do all your initialization
    // here

    // create IDirectDraw interface 7.0 object and test for error
    if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
        return(0);


    // set cooperation to full screen
    if (FAILED(lpdd->SetCooperativeLevel(main_window_handle,
        DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
        return(0);

    // set display mode to 640x480x16
    if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, 0, 0)))
        return(0);

    // clear ddsd and set size
    memset(&ddsd, 0, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);

    // enable valid fields
    ddsd.dwFlags = DDSD_CAPS;

    // request primary surface
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP;// DDSCAPS_PRIMARYSURFACE;

    // create the primary surface
    if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL)))
        return(0);

 // end Init

 // enter main event loop
    while (TRUE)
{
    // test if there is a message in queue, if so get it
    if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
        // test if this is a quit
        if (msg.message == WM_QUIT)
            break;

        // translate any accelerator keys
        TranslateMessage(&msg);

        // send the message to the window proc
        DispatchMessage(&msg);
    } // end if

      // main  processing goes here
        // this is the main loop of the game, do all your processing
        // here

        // for now test if user is hitting ESC and send WM_CLOSE
        if (KEYDOWN(VK_ESCAPE))
            SendMessage(main_window_handle, WM_CLOSE, 0, 0);

        // plot 1000 random pixels to the primary surface and return
        // clear ddsd and set size, never assume it's clean

        // lock the primary surface
        if (FAILED(lpddsprimary->Lock(NULL, &ddsd,
            DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT | DDLOCK_WRITEONLY,
            NULL)))
            return(0);

        // now ddsd.lPitch is valid and so is ddsd.lpSurface

        // make a couple aliases to make code cleaner, so we don't
        // have to cast
        int lpitch16 = (int)(ddsd.lPitch >> 1);
        USHORT *video_buffer = (USHORT *)ddsd.lpSurface;

        // plot 1000 random pixels with random colors on the
        // primary surface, they will be instantly visible
        for (int index = 0; index < 1000; index++)
        {
            // select random position and color for 640x480x16
            int red = rand() % 256;
            int green = rand() % 256;
            int blue = rand() % 256;
            int x = rand() % 640;
            int y = rand() % 480;

            // first build up color WORD
            USHORT pixel = _RGB16BIT565(red, green, blue);

            // write the data写入数据
            video_buffer[x + y*lpitch16] = pixel;
        } // end for index
          // now unlock the primary surface
        if (FAILED(lpddsprimary->Unlock(NULL)))
            return(0);

} // end while

  // closedown  here
    // this is called after the  is exited and the main event
    // loop while is exited, do all you cleanup and shutdown here

    // now the primary surface
    if (lpddsprimary)
    {
        lpddsprimary->Release();
        lpddsprimary = NULL;
    } // end if

      // now blow away the IDirectDraw4 interface
    if (lpdd)
    {
        lpdd->Release();
        lpdd = NULL;
    } // end if

// return to Windows like this
return(msg.wParam);

} // end

报的这个错
图片说明

  • 写回答

3条回答 默认 最新

  • qiji_2013 2017-07-23 07:33
    关注

    楼主最起码得把报的错误 截个图贴上来呀!这么长的代码~

    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突