Skip to main content
GameDev.net gamedev.net
🔒 Locked

Program Cycle

Started by blanky Sep 5, 2005 at 12:34 PM 8 replies 1.2k views
Original Post
blanky
blanky
Hey guys, I'm working on my opengl window template. For some reason my exiting the program is really slow, it's usually instantly. I think it's because it has to delete the device contect and stuff, but I've seen it exit faster on other opengl programs. Can anyone let me know what's wrong? It also might be the way in which my message pump is made, but I'm not sure, have a look:

#define WIN32_LEAN_AND_MEAN				// trim the excess fat from Windows

#include <windows.h>					// standard Windows app include
#include <gl/gl.h>						// standard OpenGL include
#include <gl/glu.h>						// OpenGL utilities
#include <gl/glaux.h>					// OpenGL auxiliary functions

#include "glfuncs.h"

HDC g_HDC;								// global device context
bool fullscreen = true;					// start off in windowed mode
int width, height;						// window width and height

// end of global variable declarations and preprocessor directives

void cycle(HDC ghdc, MSG gmsg)
{
	// clear screen and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();			// reset modelview matrix

	// Do Rendering here
	// render functions, then...
	SwapBuffers(ghdc);			// ...bring back buffer to foreground

	TranslateMessage(&gmsg);		// translate and dispatch to event queue
	DispatchMessage(&gmsg);
}

// the Windows Procedure event handler
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HGLRC hRC;					// rendering context
	static HDC hDC;						// device context
					
	switch(message)
	{
		case WM_CREATE:					// window is being created

			hDC = GetDC(hwnd);			// get current window's device context
			g_HDC = hDC;				
			SetupPixelFormat(hDC);		// call your pixel format setup function

			// create rendering context and make it current
			hRC = wglCreateContext(hDC);
			wglMakeCurrent(hDC, hRC);

			return 0;
			break;

		case WM_CLOSE:					// windows is closing

			// deselect rendering context and delete it
			wglMakeCurrent(hDC, NULL);
			wglDeleteContext(hRC);

			// send WM_QUIT to message queue
			PostQuitMessage(0);

			return 0;
			break;
			
		case WM_DESTROY:
			PostQuitMessage(0);

			return 0;
			break;

		case WM_SIZE:
			
			UpdateWindow(hwnd);
			height = HIWORD(lParam);	// retrieve width and height
			width =	LOWORD(lParam);

			if (height == 0)			// don't want a divide by zero
				height = 1;

            // reset the viewport to new dimensions
			glViewport(0, 0, width, height);
			glMatrixMode(GL_PROJECTION);// set projection matrix
			glLoadIdentity();			// reset projection matrix

			// calculate aspect ratio of window
			gluPerspective(45.0f, (GLfloat)width/(GLfloat)height,1.0f,1000.0f);

			glMatrixMode(GL_MODELVIEW);	// set modelview matrix
			glLoadIdentity();			// reset modelview matrix

			return 0;
			break;

		case WM_CHAR:
		
			switch (toupper(wParam))
			{
				case VK_ESCAPE:
					// send WM_QUIT to message queue
					PostQuitMessage(0);
					return 0;
			}

			return 0;
			break;

		default:
			break;
	}

	return (DefWindowProc(hwnd, message, wParam, lParam));
}

// the main Windows entry point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	WNDCLASSEX windowClass;		// window class
	HWND	   hwnd;			// window handle
	MSG		   msg;				// message
	RECT	   windowrect;
	DWORD	   dwExstyle;		// window extended style
	DWORD	   dwstyle;
	int bits = 32;

	FullScreenPrompt(&fullscreen, "Would you like to run in fullscreen mode?", "FULLSCREEN");

	width = 800;
	height = 600;

	// fill out the window class structure
	windowClass.cbSize			= sizeof(WNDCLASSEX);						// size of our structure
	windowClass.style			= CS_HREDRAW | CS_VREDRAW;
	windowClass.lpfnWndProc		= WndProc;									// name of your wndproc loop
	windowClass.cbClsExtra		= 0;
	windowClass.cbWndExtra		= 0;
	windowClass.hInstance		= hInstance;
	windowClass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);			// default icon
	windowClass.hCursor			= LoadCursor(NULL, IDC_ARROW);				// default arrow
	windowClass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);		// white background
	windowClass.lpszMenuName	= NULL;										// no menu
	windowClass.lpszClassName	= "ClassName";								// classname
	windowClass.hIconSm			= LoadIcon(NULL, IDI_WINLOGO);				// windows logo small icon

	// register the windows class
	if (!RegisterClassEx(&windowClass))
		return 0;

	if (fullscreen)
	{
		DEVMODE dmScreenSettings;
		memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
		dmScreenSettings.dmSize			= sizeof(dmScreenSettings);
		dmScreenSettings.dmPelsWidth	= width;				// screen width
		dmScreenSettings.dmPelsHeight	= height;				// screen height
		dmScreenSettings.dmBitsPerPel	= bits;					// bits per pixel
		dmScreenSettings.dmFields		= DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
	
		if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
		{
			// setting display mode failed, switch to windowed
			MessageBox(NULL, "Switch to FullScreen Failed", NULL, MB_OK);
			fullscreen = false;
		}
	}


	if (fullscreen)				// are we still in full-screen mode?
	{
		dwExstyle = WS_EX_APPWINDOW;			// window extended style
		dwstyle = WS_POPUP;						// windows style
		ShowCursor(TRUE);						// show cursor
	}

	else if (!fullscreen)
	{
		dwExstyle = NULL;
		// window extended style
		dwstyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;		
	}

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

	// readjust your window
	AdjustWindowRectEx(&windowrect, dwstyle, FALSE, dwExstyle);

	// class registered, so now create our window
	hwnd = CreateWindowEx(NULL,								// extended style
						  "ClassName",						// class name
						  "Taskbar Text",					// app name
						  dwstyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,	// style
						  0, 0,								// x,y coordinate
						  windowrect.right - windowrect.left,// width
						  windowrect.bottom - windowrect.top,// height
						  NULL,								// handle to parent
						  NULL,								// handle to menu
						  hInstance,						// application instance
						  NULL);							// no extra params

	// check if window creation failed (hwnd would equal NULL)
	if (!hwnd)
		return 0;

	ShowWindow(hwnd, SW_SHOW);			// display the window
	UpdateWindow(hwnd);					// update the window

	// main message loop
	while (TRUE)
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if (msg.message == WM_QUIT)
				break;

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			cycle(g_HDC, msg);
		}
	}
	return msg.wParam;
}



Ignore the fullscreen prompt function, I dont think it has anything to do with it. Thanks, it's just that I've never seen any other pump so I can't compare. Thanks again. [Edited by - blankdev on September 5, 2005 3:40:53 PM]
Nychold
Nychold
First off, cycle should not recieve a full MSG structure, but rather a MSG *. You'll thank me for this one later.

I'm concerned about your WM_CHAR message handling. The escape key terminating the program is fine, but notice something: it's not cleaning up the system. Your best bet would be to either use DestroyWindow, and make your WM_CLOSE and WM_DESTROY messages the exact same (adding some safety ifs and NULL setting in there), or to make a special "clean up" routine which turns off OpenGL, as it were and call that when you need it.

Actually why does cycle need to know anything about the messages, or attempt to translate/dispatch them again? You already do that in your WinMain function. Don't do it twice.

Other than that, I didn't find anything wrong with your code.
blanky
blanky
Thanks, I tried doing what you said but it's kind of hard without looking at any actually code, can you please show me a snippet? Thanks for the help.
NamelessEnigma
NamelessEnigma
By not unregistering your window, the program may stay open and hog resources. Also instead of returning msg.wparam, just return 0 at the end of your program.

Do this after your message pump in WinMain():
UnregisterClass("ClassName", hInstance);return 0;


I agree with Nychold on the Translating/Dispatching Messages part. You only need it in the WinMain function. It will get called often enough that you do not need it twice.
blanky
blanky
OH! I'm such a retard I didn't notice I was translating and dispatching the message twice. Okay, now for the Escape key I did it the same as the close and destroy, they're all identical now. The cycle doesn't take a MSG struct but it does take an HDC, which I think is normal (is it? or can I leave it out, it's cause some functions inside the cycle need access to it). The program unregisters the class and returns 0, I hope all is well now, thanks for the help, check it out:

#define WIN32_LEAN_AND_MEAN				// trim the excess fat from Windows#include <windows.h>					// standard Windows app include#include <gl/gl.h>						// standard OpenGL include#include <gl/glu.h>						// OpenGL utilities#include <gl/glaux.h>					// OpenGL auxiliary functions#include "glfuncs.h"					// contains custom functionsHDC g_HDC;								// global device contextbool fullscreen = true;					// start off in windowed modeint width, height;						// window width and height// end of global variable declarations and preprocessor directives// function to prompt for fullscreenvoid FullScreenPrompt(bool *fscreen, LPCSTR bodytext, LPCSTR titlebartext){	/*			assign the messagebox function to an integer to be able to conduct different tests on it without having to		call the function each time a test should be conducted.	*/	int msgbox = MessageBox(NULL, bodytext, titlebartext, MB_YESNOCANCEL | MB_ICONQUESTION);		// if the user clicked yes in the messagebox	if (msgbox == IDYES)		*fscreen = true;	// run in fullscreen	// if the user clicked no in the messagebox	else if (msgbox == IDNO)		*fscreen = false;	// run in windowed mode	// if the user clicked cancel in the messagebox	else if (msgbox == IDCANCEL)		PostQuitMessage(0);	// exit the program}// funtion to set the pixel format for the device contextvoid SetupPixelFormat(HDC hDC){	int nPixelFormat;					// your pixel format index	static PIXELFORMATDESCRIPTOR pfd = {        sizeof(PIXELFORMATDESCRIPTOR),	// size of the structure		1,								// version, always set to 1		PFD_DRAW_TO_WINDOW |			// support window		PFD_SUPPORT_OPENGL |			// support OpenGL		PFD_DOUBLEBUFFER,				// support double buffering		PFD_TYPE_RGBA,					// RGBA color mode		32,								// go for 32 bit color mode		0, 0, 0, 0, 0, 0,				// ignore color bits, not used		0,								// no alpha buffer		0,								// ignore shift bit		0,								// no accumulation buffer		0, 0, 0, 0,						// ignore accumulation bits		16,								// 16-bit z-buffer size		0,								// no stencil buffer		0,								// no auxiliary buffer		PFD_MAIN_PLANE,					// main drawing plane		0,								// reserved		0, 0, 0 };						// layer masks ignored	// choose best matching pixel format, return index	nPixelFormat = ChoosePixelFormat(hDC, &pfd);	// set pixel format to device context	SetPixelFormat(hDC, nPixelFormat, &pfd);}void cycle(HDC ghdc){	// clear screen and depth buffer	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glLoadIdentity();			// reset modelview matrix	// Do Rendering here	// render functions, then...	SwapBuffers(ghdc);			// ...bring back buffer to foreground}// the Windows Procedure event handlerLRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){	static HGLRC hRC;					// rendering context	static HDC hDC;						// device context						switch(message)	{		case WM_CREATE:					// window is being created			hDC = GetDC(hwnd);			// get current window's device context			g_HDC = hDC;							SetupPixelFormat(hDC);		// call your pixel format setup function			// create rendering context and make it current			hRC = wglCreateContext(hDC);			wglMakeCurrent(hDC, hRC);			return 0;			break;		case WM_CLOSE:					// windows is closing			// deselect rendering context and delete it			wglMakeCurrent(hDC, NULL);			wglDeleteContext(hRC);			// send WM_QUIT to message queue			PostQuitMessage(0);			return 0;			break;					case WM_DESTROY:						// deselect rendering context and delete it			wglMakeCurrent(hDC, NULL);			wglDeleteContext(hRC);			// send WM_QUIT to message queue			PostQuitMessage(0);			return 0;			break;		case WM_SIZE:						UpdateWindow(hwnd);			height = HIWORD(lParam);	// retrieve width and height			width =	LOWORD(lParam);			if (height == 0)			// don't want a divide by zero				height = 1;            // reset the viewport to new dimensions			glViewport(0, 0, width, height);			glMatrixMode(GL_PROJECTION);// set projection matrix			glLoadIdentity();			// reset projection matrix			// calculate aspect ratio of window			gluPerspective(45.0f, (GLfloat)width/(GLfloat)height,1.0f,1000.0f);			glMatrixMode(GL_MODELVIEW);	// set modelview matrix			glLoadIdentity();			// reset modelview matrix			return 0;			break;		case WM_CHAR:					switch (toupper(wParam))			{				case VK_ESCAPE:										// deselect rendering context and delete it					wglMakeCurrent(hDC, NULL);					wglDeleteContext(hRC);					// send WM_QUIT to message queue					PostQuitMessage(0);					return 0;			}			return 0;			break;		default:			break;	}	return (DefWindowProc(hwnd, message, wParam, lParam));}// the main Windows entry pointint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){	WNDCLASSEX windowClass;		// window class	HWND	   hwnd;			// window handle	MSG		   msg;				// message	RECT	   windowrect;	DWORD	   dwExStyle;		// window extended style	DWORD	   dwStyle;	int bits = 32;	FullScreenPrompt(&fullscreen, "Would you like to run in fullscreen mode?", "FULLSCREEN");	width = 800;	height = 600;	// fill out the window class structure	windowClass.cbSize			= sizeof(WNDCLASSEX);						// size of our structure	windowClass.style			= CS_HREDRAW | CS_VREDRAW;	windowClass.lpfnWndProc		= WndProc;									// name of your wndproc loop	windowClass.cbClsExtra		= 0;	windowClass.cbWndExtra		= 0;	windowClass.hInstance		= hInstance;	windowClass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);			// default icon	windowClass.hCursor			= LoadCursor(NULL, IDC_ARROW);				// default arrow	windowClass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);		// white background	windowClass.lpszMenuName	= NULL;										// no menu	windowClass.lpszClassName	= "ClassName";								// classname	windowClass.hIconSm			= LoadIcon(NULL, IDI_WINLOGO);				// windows logo small icon	// register the windows class	if (!RegisterClassEx(&windowClass))		return 0;	if (fullscreen)	{		DEVMODE dmScreenSettings;		memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));		dmScreenSettings.dmSize			= sizeof(dmScreenSettings);		dmScreenSettings.dmPelsWidth	= width;				// screen width		dmScreenSettings.dmPelsHeight	= height;				// screen height		dmScreenSettings.dmBitsPerPel	= bits;					// bits per pixel		dmScreenSettings.dmFields		= DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;			if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)		{			// setting display mode failed, switch to windowed			MessageBox(NULL, "Switch to FullScreen Failed", NULL, MB_OK);			fullscreen = false;		}	}	if (fullscreen)				// are we still in full-screen mode?	{		dwExStyle = WS_EX_APPWINDOW;			// window extended style		dwStyle = WS_POPUP;						// windows style		ShowCursor(TRUE);						// show cursor	}	else if (!fullscreen)	{		dwExStyle = NULL;		// window extended style		dwStyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;			}	windowrect.top = (long)0;	windowrect.left = (long)0;	windowrect.bottom = (long)height;	windowrect.right = (long)width;	// readjust your window	AdjustWindowRectEx(&windowrect, dwStyle, FALSE, dwExStyle);	// class registered, so now create our window	hwnd = CreateWindowEx(NULL,								// extended style						  "ClassName",						// class name						  "Taskbar Text",					// app name						  dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,	// style						  0, 0,								// x,y coordinate						  windowrect.right - windowrect.left,// width						  windowrect.bottom - windowrect.top,// height						  NULL,								// handle to parent						  NULL,								// handle to menu						  hInstance,						// application instance						  NULL);							// no extra params	// check if window creation failed (hwnd would equal NULL)	if (!hwnd)		return 0;	ShowWindow(hwnd, SW_SHOW);			// display the window	UpdateWindow(hwnd);					// update the window	// main message loop	while (TRUE)	{		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))		{			if (msg.message == WM_QUIT)				break;			TranslateMessage(&msg);			DispatchMessage(&msg);		}		else		{			cycle(g_HDC);		}	}	UnregisterClass("ClassName", hInstance);	return 0;}
demonkoryu
demonkoryu
In WM_CLOSE you should call DestroyWindow and in WM_DESTROY (as you do it already) PostQuitMessage. Alternative to calling DestroyWindow yourself, you can use DefWindowProc, which does it for you.
blanky
blanky
DestroyWindow() ? So my WM_DESTROY is handled correctly then right? So instead of doing anything in the WM_CLOSE, I just put DestroyWindow() and for the VK_ESCAPE message do I just leave it as is or same, DestroyWindow(). Thanks guys.
blanky
blanky
It works now, thanks! Here's my template, just in case anyone needs help or anything, I'm still not done with beautifying it but it's done as far as the mechanics go, unless the cycle doesnt have to take HDC, does it? Some functions in it does, but are those functions neccessary? Thanks guys, here's the code:

#define WIN32_LEAN_AND_MEAN				// trim the excess fat from Windows#include <windows.h>					// standard Windows app include#include <gl/gl.h>						// standard OpenGL include#include <gl/glu.h>						// OpenGL utilities#include <gl/glaux.h>					// OpenGL auxiliary functions#include "glfuncs.h"					// contains custom functionsHDC g_HDC;								// global device contextint width, height;						// window width and height// end of global variable declarations and preprocessor directives// function to prompt for fullscreenbool FullScreenPrompt(LPCSTR bodytext, LPCSTR titlebartext, HWND blah){	/*			assign the messagebox function to an integer to be able to conduct different tests on it without having to		call the function each time a test should be conducted.	*/	int msgbox = MessageBox(NULL, bodytext, titlebartext, MB_YESNO | MB_ICONQUESTION);		// if the user clicked yes in the messagebox	if (msgbox == IDYES)		return true;	// run in fullscreen	// if the user clicked no in the messagebox	else if (msgbox == IDNO)		return false;	// run in windowed mode}// funtion to set the pixel format for the device contextvoid SetupPixelFormat(HDC hDC){	int nPixelFormat;					// your pixel format index	static PIXELFORMATDESCRIPTOR pfd = {        sizeof(PIXELFORMATDESCRIPTOR),	// size of the structure		1,								// version, always set to 1		PFD_DRAW_TO_WINDOW |			// support window		PFD_SUPPORT_OPENGL |			// support OpenGL		PFD_DOUBLEBUFFER,				// support double buffering		PFD_TYPE_RGBA,					// RGBA color mode		32,								// go for 32 bit color mode		0, 0, 0, 0, 0, 0,				// ignore color bits, not used		0,								// no alpha buffer		0,								// ignore shift bit		0,								// no accumulation buffer		0, 0, 0, 0,						// ignore accumulation bits		16,								// 16-bit z-buffer size		0,								// no stencil buffer		0,								// no auxiliary buffer		PFD_MAIN_PLANE,					// main drawing plane		0,								// reserved		0, 0, 0 };						// layer masks ignored	// choose best matching pixel format, return index	nPixelFormat = ChoosePixelFormat(hDC, &pfd);	// set pixel format to device context	SetPixelFormat(hDC, nPixelFormat, &pfd);}void cycle(HDC ghdc){	// clear screen and depth buffer	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glLoadIdentity();			// reset modelview matrix	// Do Rendering here	// render functions, then...	SwapBuffers(ghdc);			// ...bring back buffer to foreground}// the Windows Procedure event handlerLRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){	static HGLRC hRC;					// rendering context	static HDC hDC;						// device context						switch(message)	{		case WM_CREATE:					// window is being created			hDC = GetDC(hwnd);			// get current window's device context			g_HDC = hDC;							SetupPixelFormat(hDC);		// call your pixel format setup function			// create rendering context and make it current			hRC = wglCreateContext(hDC);			wglMakeCurrent(hDC, hRC);			return 0;			break;		case WM_CLOSE:					// windows is closing			DestroyWindow(hwnd);			return 0;			break;					case WM_DESTROY:						// deselect rendering context and delete it			wglMakeCurrent(hDC, NULL);			wglDeleteContext(hRC);			// send WM_QUIT to message queue			PostQuitMessage(0);			return 0;			break;		case WM_SIZE:						UpdateWindow(hwnd);			height = HIWORD(lParam);	// retrieve width and height			width =	LOWORD(lParam);			if (height == 0)			// don't want a divide by zero				height = 1;            // reset the viewport to new dimensions			glViewport(0, 0, width, height);			glMatrixMode(GL_PROJECTION);// set projection matrix			glLoadIdentity();			// reset projection matrix			// calculate aspect ratio of window			gluPerspective(45.0f, (GLfloat)width/(GLfloat)height,1.0f,1000.0f);			glMatrixMode(GL_MODELVIEW);	// set modelview matrix			glLoadIdentity();			// reset modelview matrix			return 0;			break;		case WM_CHAR:					switch (toupper(wParam))			{				case VK_ESCAPE:										DestroyWindow(hwnd);					return 0;			}			return 0;			break;		default:			break;	}	return (DefWindowProc(hwnd, message, wParam, lParam));}// the main Windows entry pointint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){	WNDCLASSEX windowClass;		// window class	HWND	   hwnd;			// window handle	MSG		   msg;				// message	RECT	   windowrect;	DWORD	   dwExstyle;		// window extended style	DWORD	   dwstyle;	int bits = 32;	bool fullscreen;		if ((fullscreen = FullScreenPrompt("Would you like to run in fullscreen mode?", "FULLSCREEN", hwnd)) == NULL)		DestroyWindow(hwnd);	width = 800;	height = 600;	// fill out the window class structure	windowClass.cbSize			= sizeof(WNDCLASSEX);						// size of our structure	windowClass.style			= CS_HREDRAW | CS_VREDRAW;	windowClass.lpfnWndProc		= WndProc;									// name of your wndproc loop	windowClass.cbClsExtra		= 0;	windowClass.cbWndExtra		= 0;	windowClass.hInstance		= hInstance;	windowClass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);			// default icon	windowClass.hCursor			= LoadCursor(NULL, IDC_ARROW);				// default arrow	windowClass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);		// white background	windowClass.lpszMenuName	= NULL;										// no menu	windowClass.lpszClassName	= "ClassName";								// classname	windowClass.hIconSm			= LoadIcon(NULL, IDI_WINLOGO);				// windows logo small icon	// register the windows class	if (!RegisterClassEx(&windowClass))		return 0;	if (fullscreen)	{		DEVMODE dmScreenSettings;		memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));		dmScreenSettings.dmSize			= sizeof(dmScreenSettings);		dmScreenSettings.dmPelsWidth	= width;				// screen width		dmScreenSettings.dmPelsHeight	= height;				// screen height		dmScreenSettings.dmBitsPerPel	= bits;					// bits per pixel		dmScreenSettings.dmFields		= DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;			if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)		{			// setting display mode failed, switch to windowed			MessageBox(NULL, "Switch to FullScreen Failed", NULL, MB_OK);			fullscreen = false;		}	}	if (fullscreen)				// are we still in full-screen mode?	{		dwExstyle = WS_EX_APPWINDOW;			// window extended style		dwstyle = WS_POPUP;						// windows style		ShowCursor(TRUE);						// show cursor	}	else if (!fullscreen)	{		dwExstyle = NULL;		// window extended style		dwstyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;			}	windowrect.top = (long)0;	windowrect.left = (long)0;	windowrect.bottom = (long)height;	windowrect.right = (long)width;	// readjust your window	AdjustWindowRectEx(&windowrect, dwstyle, FALSE, dwExstyle);	// class registered, so now create our window	hwnd = CreateWindowEx(NULL,								// extended style						  "ClassName",						// class name						  "Taskbar Text",					// app name						  dwstyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,	// style						  0, 0,								// x,y coordinate						  windowrect.right - windowrect.left,// width						  windowrect.bottom - windowrect.top,// height						  NULL,								// handle to parent						  NULL,								// handle to menu						  hInstance,						// application instance						  NULL);							// no extra params	// check if window creation failed (hwnd would equal NULL)	if (!hwnd)		return 0;	ShowWindow(hwnd, SW_SHOW);			// display the window	UpdateWindow(hwnd);					// update the window	// main message loop	while (TRUE)	{		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))		{			if (msg.message == WM_QUIT)				break;			TranslateMessage(&msg);			DispatchMessage(&msg);		}		else		{			cycle(g_HDC);		}	}	UnregisterClass("ClassName", hInstance);	return 0;}

Topic Locked

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

Sign in to reply to this topic.