Why can't I make a not-fullscreen window?

Started by
1 comment, last by Skeleton_V@T 18 years, 4 months ago
Hello! I've been working with direct3d for some time and I have always used the same code to make windows. I really have trouble understanding the winAPI so I decided to do a class that would create my window without I having to re-type 200 lines. my class contains these functions: bool RegisterWinClass(HINSTANCE hInstance, char* classname, WNDPROC ProcedureFunction); bool CreateWin(char* title, RECT winrect, bool fullscreen, bool console); Now when I create a window, I ask the user if he wants windowed or fullscreen and which resolution in messageboxes. If fullscreen is selected, I have no problem, all works perfectly. However, if I chose windowed, the console window I requested will appear but no sign of the window itself... I am almost sure my mistake is in CreateWin. Here's my code:

bool D3DY::CD3DYWinManager::RegisterWinClass(HINSTANCE hInstance, char* classname, WNDPROC ProcedureFunction)
{
	if(m_hInstance) return true;
	if(!hInstance)  return false;
	m_hInstance=hInstance;

	m_hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
	m_strClassName=classname;
	
	WNDCLASS	wc;
	wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraw On Size, And Own DC For Window.
	wc.lpfnWndProc   = ProcedureFunction;					// WndProc Handles Messages
	wc.cbClsExtra    = 0;									// No Extra Window Data
	wc.cbWndExtra    = 0;									// No Extra Window Data
	wc.hInstance     = m_hInstance;							// Set The Instance
	wc.hIcon         = LoadIcon(NULL, IDI_WINLOGO);			// Load The Default Icon
	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);			// Load The Arrow Pointer
	wc.hbrBackground = NULL;								// No Background Required For D3D
	wc.lpszMenuName  = NULL;								// We Don't Want A Menu
	wc.lpszClassName = m_strClassName.c_str();				// Set The Class Name


	if(!RegisterClass(&wc))									// Attempt To Register The Window Class
	{
		MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;
	}

	return true;
}




bool D3DY::CD3DYWinManager::CreateWin(char* title, RECT winrect, bool fullscreen, bool console)
{
	if(m_hDC) return true;

	m_strTitle=title;
	m_bFullscreen=fullscreen;

	DWORD		dwExStyle; // Window Extended Style
	DWORD		dwStyle;   // Window Style

	if(m_bFullscreen)
	{
		dwExStyle=WS_EX_APPWINDOW; // Window Extended Style
		dwStyle=WS_POPUP;          // Windows Style
		ShowCursor(FALSE);         // Hide Mouse Pointer
	}
	else
	{
		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
		dwStyle=WS_OVERLAPPEDWINDOW;                  // Windows Style
	}


	AdjustWindowRectEx(&winrect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size
	m_Rect = winrect;

	// Create The Window
	if(!(m_hWnd=CreateWindowEx(dwExStyle,				// Extended Style For The Window
							   m_strClassName.c_str(),	// Class Name
							   m_strTitle.c_str(),		// Window Title
							   dwStyle |				// Defined Window Style
							   WS_CLIPSIBLINGS |		// Required Window Style
							   WS_CLIPCHILDREN,			// Required Window Style
							   m_Rect.left, m_Rect.top,	// Window Position
							   m_Rect.right-m_Rect.left,// Calculate Window Width
							   m_Rect.bottom-m_Rect.top,// Calculate Window Height
							   NULL,					// No Parent Window
							   NULL,					// No Menu
							   m_hInstance,				// Instance
							   NULL)))					// Dont Pass Anything To WM_CREATE
	{
		Release();
		MessageBox(NULL,"Could not create window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;
	}


	if(!(m_hDC=GetDC(m_hWnd))) // Did We Get A Device Context?
	{
		Release();
		MessageBox(NULL,"Could not get device context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;
	}

	if(console)
	{
		AllocConsole();
		freopen( "CONOUT$", "w", stdout );
	}

	return true;
}

Note that the hInstance I use as the argument is the one I get with winMain() I have run the program line-by-line and all my error-checking code never fails. Do you see any problems with that code?
Advertisement
You need to add the line ShowWindow( ... ) to your created window.
Quote:Original post by Deception666
You need to add the line ShowWindow( ... ) to your created window.


Or specify WS_SHOW in CreateWindowEx:
WS_CLIPSIBLINGS |		// Required Window styleWS_SHOW  |               // Window is visible when createdWS_CLIPCHILDREN,		// Required Window style


Specifying FullScreen effectively includes WS_SHOW so you didn't notice that, you may refer to MSDN for more infos.
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--

This topic is closed to new replies.

Advertisement