Exemplo n.º 1
0
//*****************************************************************************
//
// Function Name:  RColorDialog::ShowPage
//
// Description:    Helper function for creating/displaying the correct
//						 property sheet in the tab control.
//
// Returns:        VOID
//
// Exceptions:	    None
//
//*****************************************************************************
void RColorDialog::ShowPage( int nPage )
{
	CDialog* pPrevPage  = m_pCurrentPage;
	CDialog* pPages[]   = { &m_dlgColorPalette, &m_dlgColorTexture, &m_dlgColorPhoto };
	int		pPageIDs[] = { DIALOG_COLOR_DIALOG_GRADIENTS, m_dlgColorTexture.IDD, m_dlgColorPhoto.IDD };

	TpsAssert( nPage < NumElements( pPages ), "Invalid page number!" );

	if (m_pCurrentPage != pPages[nPage])
	{
		m_pCurrentPage = pPages[nPage] ;

		if (!IsWindow( m_pCurrentPage->m_hWnd ))
		{
			CRect   rectAdjust(0,0,0,0);
			CRect   rectWindow(0,0,0,0);

			m_ctlTabCtrl.AdjustRect( TRUE, &rectAdjust );
			m_ctlTabCtrl.GetWindowRect( &rectWindow );

			rectWindow.left -= rectAdjust.left;
			rectWindow.top  -= rectAdjust.top;
			ScreenToClient( &rectWindow );

			if (!m_pCurrentPage->Create( pPageIDs[nPage], this ))
			{
				if (!pPrevPage) return ;

				// Restore the current page pointer to the previous one.
				m_pCurrentPage = pPrevPage ;
				pPrevPage = NULL;

				// Find the index of the previous page. (For setting the tab)
				for (int i = 0; i < NumElements( pPages ); i++)
				{
					if (m_pCurrentPage == pPages[i])
					{
						m_ctlTabCtrl.SetCurSel( i ) ;
						break ;
					}
				}
			}

			m_pCurrentPage->SetWindowPos( &wndTop, rectWindow.left,
				rectWindow.top, 0, 0, SWP_NOSIZE ) ;

		} // if (IsWindow())
			
	} // if (new page)

	if (pPrevPage && IsWindow( pPrevPage->m_hWnd ))
		pPrevPage->ShowWindow( SW_HIDE ) ;

	m_pCurrentPage->ShowWindow( SW_SHOW ) ;

	GetDlgItem( IDC_COLOR_MORE )->EnableWindow( m_pCurrentPage == &m_dlgColorPalette );
}
Exemplo n.º 2
0
/*	This Code Creates Our OpenGL Window.  Parameters Are:
 *	lpszTitle		- Title to Appear at the Top of the Window
 *	nWidth			- Width of the GL Window or Fullscreen Mode
 *	nHeight			- Height of the GL Window or Fullscreen Mode
 *	nBits			- Number of Bits to Use for Color (8/16/24/32)
 *	nZBuffer		- Number of Bits to Use for Z-Buffer (16/32)
 *	bFullScreen		- Use Fullscreen Mode (true) Or Windowed Mode (false)
 */
bool CGL::Create(char* lpszTitle, int nWidth, int nHeight, int nBits=16, int nZBuffer=16, bool bFullScreen=true) : m_bFullScreen(bFullScreen)
{
	GLuint		PixelFormat;							// Holds The Results After Searching For A Match
	WNDCLASS	wc;										// Windows Class Structure
	DWORD		dwExStyle;								// Window Extended Style
	DWORD		dwStyle;								// Window Style
	RECT		rectWindow(0, nWidth, 0, nHeight);		// Grabs Rectangle Upper Left / Lower Right Values

	m_hInstance			= GetModuleHandle(NULL);		// Grab An Instance For Our Window
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
	wc.lpfnWndProc		= (WNDPROC) WndProc;			// 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 GL
	wc.lpszMenuName		= NULL;							// We Don't Want A Menu
	wc.lpszClassName	= "OpenGL";						// Set The Class Name

	if (!RegisterClass(&wc))							// Attempt To Register The Window Class
	{
		MessageBox(m_hWnd,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}
	
	if (m_bFullScreen)									// Attempt Fullscreen Mode?
	{
		DEVMODE dmScreenSettings;						// Device Mode
		memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));	// Makes Sure Memory's Cleared
		dmScreenSettings.dmSize		 = sizeof(dmScreenSettings);	// Size Of The Devmode Structure
		dmScreenSettings.dmPelsWidth  = nWidth;			// Selected Screen Width
		dmScreenSettings.dmPelsHeight = nHeight;		// Selected Screen Height
		dmScreenSettings.dmBitsPerPel = nBits;			// Selected Bits Per Pixel
		dmScreenSettings.dmFields	  = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

		// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
		if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
		{
			// If The Mode Fails, Offer Two Options.  Quit Or Use Windowed Mode.
			if (MessageBox(m_hWnd,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
				m_bFullScreen = false;					// Windowed Mode Selected.  Fullscreen = false
			else
			{
				// Pop Up A Message Box Letting User Know The Program Is Closing.
				MessageBox(m_hWnd,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
				return false;							// Return false
			}
		}
	}

	if (m_bFullScreen)									// Are We Still In Fullscreen Mode?
	{
		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(&rectWindow, dwStyle, false, dwExStyle);		// Adjust Window To true Requested Size

	// Create The Window
	if (!(m_hWnd=CreateWindowEx(dwExStyle,				// Extended Style For The Window
								"OpenGL",				// Class Name
								lpszTitle,				// Window Title
								dwStyle |				// Defined Window Style
								WS_CLIPSIBLINGS |		// Required Window Style
								WS_CLIPCHILDREN,		// Required Window Style
								0, 0,					// Window Position
								WindowRect.right-WindowRect.left,	// Calculate Window Width
								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
								NULL,					// No Parent Window
								NULL,					// No Menu
								m_hInstance,			// Instance
								NULL)))					// Dont Pass Anything To WM_CREATE
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	static	PIXELFORMATDESCRIPTOR pfd =					// pfd Tells Windows How We Want Things To Be
	{
		sizeof(PIXELFORMATDESCRIPTOR),					// Size Of This Pixel Format Descriptor
		1,												// Version Number
		PFD_DRAW_TO_WINDOW |							// Format Must Support Window
		PFD_SUPPORT_OPENGL |							// Format Must Support OpenGL
		PFD_DOUBLEBUFFER,								// Must Support Double Buffering
		PFD_TYPE_RGBA,									// Request An RGBA Format
		nBits,											// Select Our Color Depth
		0, 0, 0, 0, 0, 0,								// Color Bits Ignored
		0,												// No Alpha Buffer
		0,												// Shift Bit Ignored
		0,												// No Accumulation Buffer
		0, 0, 0, 0,										// Accumulation Bits Ignored
		nZBuffer,										// 16/32Bit Z-Buffer (Depth Buffer)  
		0,												// No Stencil Buffer
		0,												// No Auxiliary Buffer
		PFD_MAIN_PLANE,									// Main Drawing Layer
		0,												// Reserved
		0, 0, 0											// Layer Masks Ignored
	};
	
	if (!(m_hDC=GetDC(m_hWnd)))							// Did We Get A Device Context?
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	if (!(PixelFormat=ChoosePixelFormat(m_hDC,&pfd)))	// Did Windows Find A Matching Pixel Format?
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	if(!SetPixelFormat(m_hDC,PixelFormat,&pfd))			// Are We Able To Set The Pixel Format?
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	if (!(hRC=wglCreateContext(m_hDC)))					// Are We Able To Get A Rendering Context?
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	if(!wglMakeCurrent(m_hDC,hRC))						// Try To Activate The Rendering Context
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	ShowWindow(m_hWnd, SW_SHOW);						// Show The Window
	SetForegroundWindow(m_hWnd);						// Slightly Higher Priority
	SetFocus(m_hWnd);									// Sets Keyboard Focus To The Window
	Resize(nWidth, nHeight);							// Set Up Our Perspective GL Screen

	if (!Init())										// Initialize Our Newly Created GL Window
	{
		KillGLWindow();									// Reset The Display
		MessageBox(m_hWnd,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;									// Return false
	}

	return true;										// Success
}