Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Kyo

Why won't this work in non-NT windows OS?

This topic is 5650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I can create a window fine on all NT based operating systems but for some reason the window just appears then disappears on Windows 98 or ME. Same for fullscreen mode, it chagnes resolution then back to the desktop with no error messages. Is there any NT specific code in creating my window?
    
bool CWindow::createWindow(char *title, int width, int height, int bits, bool fullscreenflag)
{
	WNDCLASSEX wc;
	DWORD dwExStyle;
	DWORD dwStyle;
	int pixelformat;

	
	WndRect.right = (long) width;
	WndRect.bottom = (long) height;
	WndRect.left = 0;
	WndRect.top = 0;

	hInstance = GetModuleHandle(NULL);
	fullscreen = fullscreenflag;
	
	//register window class

	wc.cbSize		= sizeof(WNDCLASSEX);					//wc size

	wc.style		= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	//force window redraw

	wc.lpfnWndProc	= (WNDPROC) this->MainWndProc;			//specify window procedure

	wc.cbClsExtra	= 0;									//not needed

	wc.cbWndExtra	= 4;									//extra space needed

	wc.hInstance	= hInstance;							//window instance

	wc.hIcon		= LoadIcon(NULL, IDI_WINLOGO);			//default icon logo

	wc.hCursor		= LoadCursor(NULL, IDC_ARROW);			//default cursor

	wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);//black background

	wc.lpszMenuName = NULL;									//no menu

	wc.lpszClassName = "Bomberman";							//class name

	wc.hIconSm		= LoadIcon(NULL, IDI_WINLOGO);			//default small icon


	if (!RegisterClassEx(&wc)) 
	{
		MessageBox(NULL,"Could not register window class","ERROR!",
			MB_OK | MB_ICONINFORMATION);
	}


	//set device mode if in fullscreen

	if (fullscreen)
	{
		DEVMODE screensettings;
		memset(&screensettings, 0, sizeof(screensettings));		//clear memory

		screensettings.dmSize = sizeof(screensettings);			//struct size

		screensettings.dmBitsPerPel = bits;						//bits per pixel

		screensettings.dmPelsHeight = height;					//resolution

		screensettings.dmPelsWidth  = width;					//resolution

		screensettings.dmFields		= DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

		//change display settings to fullscreen device mode

		if (ChangeDisplaySettings(&screensettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
		{
			MessageBox(NULL,"Fullscreen mode failed","ERROR!",
				MB_OK | MB_ICONINFORMATION);
			fullscreen = false; 
		}
	}


	//set window style

	if (fullscreen)
	{
		dwExStyle = WS_EX_APPWINDOW;
		dwStyle = WS_POPUP;
		ShowCursor(false);
	}
	else
	{
		dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
		dwStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; 
	}

	AdjustWindowRectEx(&WndRect, dwStyle, false, dwExStyle);


	//create window

	if (!(hWnd = CreateWindowEx(	dwExStyle,							//window ex style

									"Bomberman",						//class name

									title,								//window title

									WS_CLIPSIBLINGS |					//prevents overdrawing

									WS_CLIPCHILDREN |
									dwStyle,
									0, 0,								//window pos

									WndRect.right - WndRect.left,		//adjuted width

									WndRect.bottom - WndRect.top,		//adjusted height

									NULL,								//no parent window

									NULL,								//no menu

									hInstance,							//window instance

									this)))								//lpParam

	{
		killWindow();
		MessageBox(NULL,"Could not create window","ERROR!",
			MB_OK | MB_ICONINFORMATION);
		return false;
	}



	//describe pixel format

	static PIXELFORMATDESCRIPTOR pfd = 
	{
		sizeof(PIXELFORMATDESCRIPTOR),
		1,									//version number

		PFD_DRAW_TO_WINDOW |				//must support window

		PFD_SUPPORT_GDI |					//must support GDI

		PFD_TYPE_RGBA,						//rgba format

		bits,								//colour depth

		0,0,0,0,0,0,						//ignore colour bits

		0,									//no alpha buffer

		0,									//ignore shift bit

		0,									//no accumulation buffer

		0,0,0,0,							//accumulation bits ignored

		0,									//no z-buffer

		0,									//no stencil buffer

		0,									//no auxiliary buffer

		PFD_MAIN_PLANE,						//main drawing layer

		0,									//reserved

		0,0,0								//ignore layer masks

	};


	//get device context

	if (!(hDC = GetDC(hWnd)))
	{
		killWindow();
		MessageBox(NULL,"Can't Create A Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;
	}


	//find matching pixel format

	if (!(pixelformat = ChoosePixelFormat(hDC, &pfd)))
	{
		killWindow();
		MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;
	}


	//set pixel format

	if (!SetPixelFormat(hDC, pixelformat, &pfd))
	{
		killWindow();
		MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;
	}



	ShowWindow(hWnd, SW_SHOW);
	SetForegroundWindow(hWnd);
	SetFocus(hWnd);

	return true;
}
    
Oh and here's the actual game: www.tevong.pwp.blueyonder.co.uk/Bomberman++.zip [edited by - Kyo on December 4, 2002 11:00:02 AM]

Share this post


Link to post
Share on other sites
Advertisement
If it''s obvious please say so I can''t really try out anything as I don''t have windows 98 or ME and reading over MSDN is confusing me more...

Share this post


Link to post
Share on other sites
if someone could reply saying "your question''s too vague", "couldn''t be bothered to read that long crap", "don''t know why it won''t work, your code looks fine" it would be a lot more helpful. I don''t want to sound like a brat but doesn''t feel good to have a relatively simple question ignored especially when it''s urgent...

Share this post


Link to post
Share on other sites
quote:
Original post by Kyo
if someone could reply saying "your question''s too vague", "couldn''t be bothered to read that long crap", "don''t know why it won''t work, your code looks fine" it would be a lot more helpful. I don''t want to sound like a brat but doesn''t feel good to have a relatively simple question ignored especially when it''s urgent...


ever concidered the fact that maybe people have real lives( Jobs, etc ) besides visiting this site all the time? So post a question, wait a day or two and then check if there''s an answer.




[Cyberdrek | the last true sorcerer | Spirit Mage - mutedfaith.com]

Share this post


Link to post
Share on other sites
Try adding in a bunch of code that logs function call results to a file to see what''s failing.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!