Making this puppy full screen!

Started by
7 comments, last by Fredric 23 years, 11 months ago
For some strange reason, the following code won't become full screen/the resolution I specify... what could be wrong? I've been playing around with this for a long time, and I've given up! Here's the full source code (the functions that initialize Ddraw are at the bottom!): // directdraw initialization #include 'ddraw.h' // remember- includes are in ' because of.. #include 'windows.h' // the pesky HTML boards.. LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM); HWND hwnd; int GameMain(); int GameInit(); int Game_Shutdown(); LPDIRECTDRAW lpdd = NULL; // DDraw 1.0 char szWinName[] = "MyWin"; // name of window class int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgs, int nWinMode) { HWND hwnd; WNDCLASSEX wcl; MSG msg; // define the window class wcl.cbSize = sizeof(WNDCLASSEX); wcl.lpszClassName = szWinName; wcl.lpfnWndProc = WinProc; wcl.style = CS_DBLCLKS / CS_OWNDC / CS_HREDRAW / CS_VREDRAW; wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcl.hIconSm = NULL; wcl.hCursor = LoadCursor(NULL, IDC_ARROW); wcl.lpszMenuName = NULL; // no menu wcl.cbClsExtra = 0; wcl.cbWndExtra = 0; wcl.hInstance = hThisInstance; // make the background of the window black wcl.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); // register the window class if(!RegisterClassEx(&wcl)) return 0; // if the class doesn't register, break it // the window has been defined and registered, // but now it's time to create it hwnd = CreateWindow(szWinName, // name of window class "DirectDraw Initialization", //title WS_OVERLAPPEDWINDOW / WS_VISIBLE, //style CW_USEDEFAULT, // x CW_USEDEFAULT, // y CW_USEDEFAULT, // width CW_USEDEFAULT, // height NULL, // no parent window NULL, // no menu hThisInstance, //instance handle NULL // no additional arguments ); // diplay the window GameInit(); // create a message loop while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } GameInit(); return(msg.wParam); } // the message handler LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; switch(message){ case WM_CREATE: return 1; break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); break; case WM_DESTROY: // terminate the program PostQuitMessage(0); return (0); break; default: return DefWindowProc(hwnd, message, wParam, lParam); break; } return 0; } int GameInit() { if(FAILED(DirectDrawCreate(NULL, &lpdd, NULL))) return 0; if ((lpdd->SetCooperativeLevel(hwnd, DDSCL_ALLOWMODEX / DDSCL_FULLSCREEN / DDSCL_EXCLUSIVE / DDSCL_ALLOWREBOOT))!=DD_OK) if ((lpdd->SetDisplayMode(640,480,8))!=DD_OK) return(0); return 1; } // end GameInit int Game_Shutdown() { if(lpdd) { lpdd->Release(); lpdd = NULL; // just to be safe! } return 1; } If this could be resolved I'd very very happy! Edit: I forgot to mention- this compiles with 0 errors or warnings, but the window just doesn't appear right (full screen, right resolution) when it runs... GO LEAFS GO! Edited by - Fredric on 5/4/00 5:48:12 PM
3D Math- The type of mathematics that'll put hair on your chest!
Advertisement
First thing.
You never check your return code from GameInit();

Second you call it within your message loop!
What do you mean, never check the return code? That's simple error handling for easier bug fixing..
so I put the GameInit() in WM_CREATE and Game_Shutdown() in WM_DESTROY?

Well, I did that, but still, the app isn't full screen and in the right resolution!

edit: What do you mean check the return code in GameInit()? I HAVE to have a return statement because the function is an int, is that what you meant? You've confused me!

GO LEAFS GO!

Edited by - Fredric on 5/4/00 7:16:26 PM
3D Math- The type of mathematics that'll put hair on your chest!
May I ask why you call gameinit before AND after your messageloop?

Anyway, in your gameinit you check your setcooperativelevel != dd_ok
The way you''re set up with the next call (to setdisplaymode) you should test setcooperativelevel == dd_ok
or better still, insert a "return 0;" after the first if
A polar bear is a rectangular bear after a coordinate transform.
There's something a little strange about your code - I can't quite place it (I'm kind of out of it today), but event loop doesn't look very real-time to me. (I'm not even sure it works properly?? - Probably way off on that guess, btw). I use PeekMessage for my message loop, like this. (I'll put in where I put the Game_Init() calls.

MSG msg;...Game_Init()while(1){ if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))  {   // Check for a quit   if (msg.message == WM_QUIT)    break;   // Translate accel keys   TranslateMessage&msg);   // Send the message   DispatchMessage(&msg);  }// End the if PeekMessage()  Game_Main();}Game_Shutdown();  


I didn't include the message handler because I didn't think it necessary.

That probably has nothing to do with your problem, but you are going to have a hell of a time getting your game to run in real time without a loop like that.

Anyway,

Trigon

I like food.

Edited by - TrigonLoki on 5/4/00 7:53:21 PM
I like food.
Well, this code here:

if ((lpdd->SetCooperativeLevel(hwnd,
DDSCL_ALLOWMODEX / DDSCL_FULLSCREEN /
DDSCL_EXCLUSIVE / DDSCL_ALLOWREBOOT))!=DD_OK)

I don't know what the '/' is for. There needs to be a '/' in the place of that. Maybe you did this for a reason, I don't know, it's just what i first caught.

EDIT:
Hmmm...the character i wanted in the second spot was supposed to be a bitwise OR sign. But i guess this board didn't like those, so I guess that's not the problem in your code.
email: chickawow@netzero.net

annex software: http://annexsoftware.cjb.net

Edited by - mkoday on 5/4/00 8:05:35 PM
What I meant by not checking your return codes, is that you set you''re return value in GameInit as 0 or 1. But in you''re WinMain, you don''t check for failure.

I was going to give an example from your code, when I spotted an even bigger mistake.

I''m fairly sure this is your problem:
if ((lpdd->SetCooperativeLevel(hwnd,
DDSCL_ALLOWMODEX / DDSCL_FULLSCREEN /
DDSCL_EXCLUSIVE / DDSCL_ALLOWREBOOT))!=DD_OK)

if ((lpdd->SetDisplayMode(640,480,8))!=DD_OK)
return(0);

Note the if statement followed by the if. The second if only gets executed if SetCooperativeLevel Fails!!!!!
You will only Set the display mode in error situations.
Add a return (0); after the first if and you should be better off.

There could be more problems, but that is a big one.
*choke* I can''t believe I missed that! That didn''t fix my problem... but, I''m just going to copy and paste the source right out of the CD and write the actual DX by myself, this is becoming ridiculous! Again, thanks to all of you for trying to get through my thick skull..

GO LEAFS GO!
3D Math- The type of mathematics that'll put hair on your chest!
This forum replaces the pipe character (a pipe going straight up with the / character. Don''t ask me why, it just does. That is not a problem.

This topic is closed to new replies.

Advertisement