🔒 Locked
SetDisplayMode
Advertisement
Original Post
Why wont this work?
#include
#include
#include
#define WIN32_LEAN_AND_MEAN
LPDIRECTDRAW lpdd;
HWND hwnd;
MSG msg;
void start(void);
void game(void);
void close(void);
LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg,
WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
} break;
default:break;
}
return(DefWindowProc(hwnd, msg, wparam, lparam));
}
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX myclass;
myclass.cbClsExtra = 0;
myclass.cbSize = sizeof(WNDCLASSEX);
myclass.cbWndExtra = 0;
myclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
myclass.hCursor = LoadCursor(NULL, IDC_ARROW);
myclass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
myclass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
myclass.hInstance = hinstance;
myclass.lpfnWndProc = MsgHandler;
myclass.lpszClassName = "My Class";
myclass.lpszMenuName = NULL;
myclass.style = CS_OWNDC | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;
RegisterClassEx(&myclass);
CreateWindowEx(
NULL,
"My Class",
"Hi Ben",
WS_POPUP | WS_VISIBLE,
0,0, 300, 200,
NULL,
NULL,
hinstance,
NULL);
start();
while(1)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
game();
}
close();
return (0);
}
void start(void)
{
if(DirectDrawCreate(NULL,&lpdd,NULL) != DD_OK)
{
MessageBox(hwnd, "Failed to create DirectDraw object", "Error", MB_OK);
}
if((lpdd->SetCooperativeLevel(hwnd, DDSCL_NORMAL)) != DD_OK)
{
MessageBox(hwnd, "Could not set cooperation level", "Error", MB_OK);
}
if(lpdd->SetDisplayMode(600, 480, 16) != DD_OK)
{
MessageBox(hwnd, "Could not set display mode", "Error", MB_OK);
}
}
void game(void)
{
}
void close(void)
{
lpdd->Release();
}
Most of the DirectX functions return an HRESULT, which is basically a DWORD (I think). If it''s not DD_OK, then print out what number it is (in hexadecimal).
You can either look this up in the DDraw.h file, or use the utility library function D3DXGetErrorString to see what error it was.
You can either look this up in the DDraw.h file, or use the utility library function D3DXGetErrorString to see what error it was.
quote:
Original post by yq
if((lpdd->SetCooperativeLevel(hwnd, DDSCL_NORMAL)) != DD_OK)
{
MessageBox(hwnd, "Could not set cooperation level", "Error", MB_OK);
}
if(lpdd->SetDisplayMode(600, 480, 16) != DD_OK)
{
MessageBox(hwnd, "Could not set display mode", "Error", MB_OK);
}
Are you trying to change the screen mode in a windowed game? If you''re trying to go fullscreen, use DDSCL_EXLUSIVE | DDSCL_FULLSCREEN in SetCooperativeLevel (DDSCL_NORMAL is for windowed mode). The SetDisplayMode call should work then.
If you''re wanting to stay in windowed mode, it''s probably not a good idea to go messing with the resolution. (But if you really want to, try ChangeDisplaySettings.)
Jesse Chounard
Don''t know if this is the problem, but you use CreateWindow
but don''t assign it a window handle....which you CONVENIENTLY
need when making your DirectX Components...
ie. change your code
from:
CreateWindowEx( NULL, "My Class", "Hi Ben",
WS_POPUP | WS_VISIBLE,
0,0, 300, 200,
NULL,
NULL,
hinstance,
NULL);
to
g_hWnd = CreateWindowEx(
NULL,
"My Class",
"Hi Ben",
WS_POPUP | WS_VISIBLE,
0,0, 300, 200,
NULL,
NULL,
hinstance,
NULL);
have g_hWnd declared as a global HWND, then in your start function replace all hwnd with g_hWnd
I have no idea what the effect is, but shouldn''t you also create some DirectDrawSurfaces with this??
that window handle thing could be your only serious error here though...
but don''t assign it a window handle....which you CONVENIENTLY
need when making your DirectX Components...
ie. change your code
from:
CreateWindowEx( NULL, "My Class", "Hi Ben",
WS_POPUP | WS_VISIBLE,
0,0, 300, 200,
NULL,
NULL,
hinstance,
NULL);
to
g_hWnd = CreateWindowEx(
NULL,
"My Class",
"Hi Ben",
WS_POPUP | WS_VISIBLE,
0,0, 300, 200,
NULL,
NULL,
hinstance,
NULL);
have g_hWnd declared as a global HWND, then in your start function replace all hwnd with g_hWnd
I have no idea what the effect is, but shouldn''t you also create some DirectDrawSurfaces with this??
that window handle thing could be your only serious error here though...
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement