游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3904|回复: 2

[求助]关于SetDisplayMode出错的问题

[复制链接]

22

主题

49

帖子

49

积分

注册会员

Rank: 2

积分
49
发表于 2008-6-18 13:51:00 | 显示全部楼层 |阅读模式
#define WIN32_LEAN_AND_MEAN  // just say no to MFC

#define INITGUID

#include <windows.h>   // include important windows stuff
#include <ddraw.h>

#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code)&0x8000) ? 1 : 0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code)&0x8000) ? 0 : 1)
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 24
#define WINDOW_CLASS_NAME "WNDCLASS1"

HWND      main_window_handle = NULL; // globally track main window
HINSTANCE afxInstace = NULL;
LPDIRECTDRAW7 lpdd7 = NULL;
LPDIRECTDRAWSURFACE7 lpdds7 = NULL;

LPDIRECTDRAW7         lpdd         = NULL;   // dd object
LPDIRECTDRAWSURFACE7  lpddsprimary = NULL;   // dd primary surface

inline void Error(const char *stype)
{

        MessageBox(main_window_handle, stype, "ERROR", MB_ABORTRETRYIGNORE);

}

LRESULT CALLBACK WindowProc(HWND hwnd,
                                                    UINT msg,
                            WPARAM wparam,
                            LPARAM lparam)
{

PAINTSTRUCT                ps;                // used in WM_PAINT
HDC                                hdc;        // handle to a device context

// what is the message
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;

    } // end switch

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

} // end WinProc


void GameInit(void)
{

        if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd7, IID_IDirectDraw7, NULL)))
        {
               
                Error("DirectDrawCreateEx error!");
                exit(0);

        }

        if (FAILED(lpdd7->SetCooperativeLevel(main_window_handle,
                DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX |
                DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
        {
               
                Error("SetCooperativeLevel error !");
                exit(0);


        }
//这里SetDisplayMode失败,那是Windows游戏编程大师的代码 SCREEN_BPP 24
        if ((lpdd7->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,0,0)) !=  DD_OK)
        {
               
                Error("SetDisplayMode error !");
                exit(0);

        }



}

void GameShutDown(void)
{

        if (lpdd7 != NULL)
        {

                lpdd7->Release();
                lpdd7 = NULL;

        }

}

int WINAPI WinMain(
  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // command line
  int nCmdShow              // show state
)
{

        WNDCLASSEX winclass;
        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        = WINDOW_CLASS_NAME;
        winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

        if (!RegisterClassEx(&winclass))
                return 0;

        main_window_handle = CreateWindowEx(NULL,                  // extended style
                            WINDOW_CLASS_NAME,     // class
                                                    "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);

        if (main_window_handle == NULL)
        {

                return 0;

        }


        GameInit();

        MSG msg;
        while(TRUE)
        {

                if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
                {

                        if (msg.message == WM_QUIT)
                                break;
                       
                        TranslateMessage(&msg);
                       
                        DispatchMessage(&msg);

                } // end if
               
                if (KEYDOWN(VK_ESCAPE))
                        SendMessage(main_window_handle,WM_CLOSE,0,0);

               
        } // end while


        GameShutDown();


        return int(msg.wParam);

}

使用sabc

22

主题

49

帖子

49

积分

注册会员

Rank: 2

积分
49
 楼主| 发表于 2008-6-18 13:52:00 | 显示全部楼层

Re: [求助]关于SetDisplayMode出错的问题

f ((lpdd7->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,0,0)) !=  DD_OK)
{

Error("SetDisplayMode error !");
exit(0);

}
//程序运行到这里出错

29

主题

81

帖子

85

积分

注册会员

Rank: 2

积分
85
发表于 2008-6-18 19:39:00 | 显示全部楼层

Re:[求助]关于SetDisplayMode出错的问题

显卡不支持24位色模式??
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-22 05:23

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表