Skip to main content
gamedev.net
🔒 Locked

SetDisplayMode

Started by yq Nov 18, 2000 at 8:23 AM 11 replies 1.4k views
Original Post
yq
yq
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(); }
TwoFlower
TwoFlower
quote:

Why wont this work?



You haven''t included any header files for windows or DirectX

But what do you mean ''Why wont this work?''. Which bit doesn''t work? what''s going wrong? What''s the actual problem?
yq
yq
The Header files are there but when i post they dont show up. They are windows.h windowsx.h and ddraw.h.

My program compiles but when i run it it wont change resolutions.
TwoFlower
TwoFlower
hmmmm, ok

What error is SetDisplayMode returning?
yq
yq
how can i check?
TwoFlower
TwoFlower
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.
Jesse Chounard
Jesse Chounard
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
yq
yq
So i would do something like

HRESULT hr;

if(hr = lpdd->SetDisplayMode(800,600,16) != DD_OK)

But then how would i read the value.
yq
yq
I changed it to DDSCL_EXLUSIVE | DDSCL_FULLSCREEN but i got another error. Would somebody else please try to compile this.

Edited by - yq on November 18, 2000 10:09:38 AM
wazoo69
wazoo69
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...

wazoo69
wazoo69
D''oh! I JUST noticed that you already HAVE a global HWND declared...but you still need to assign it with your CreateWindow routine..

wazoo
yq
yq
thanks that fixed my SetCooperativeLevel problem but it still wont change resolutions.
yq
yq
DOH I feel like an idiot I was trying to set it to 600 by 480 instead of 640 by 480. Anyways thanks fo the help and if any knows where i could find some good tuorials on error handling I''d appreciate it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.