Click here to Skip to main content
15,891,431 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Just a quickie Pin
Waldermort29-Mar-06 23:22
Waldermort29-Mar-06 23:22 
GeneralRe: Just a quickie Pin
Nibu babu thomas29-Mar-06 23:49
Nibu babu thomas29-Mar-06 23:49 
GeneralRe: Just a quickie Pin
Waldermort30-Mar-06 0:00
Waldermort30-Mar-06 0:00 
GeneralRe: Just a quickie Pin
Rage30-Mar-06 0:06
professionalRage30-Mar-06 0:06 
GeneralRe: Just a quickie Pin
Waldermort30-Mar-06 2:01
Waldermort30-Mar-06 2:01 
QuestionOpenGL & MFC & setfocus Pin
braveheartkenya29-Mar-06 21:59
braveheartkenya29-Mar-06 21:59 
AnswerRe: OpenGL & MFC & setfocus Pin
FarPointer30-Mar-06 2:19
FarPointer30-Mar-06 2:19 
GeneralRe: OpenGL & MFC & setfocus Pin
braveheartkenya30-Mar-06 6:04
braveheartkenya30-Mar-06 6:04 
This is the DrawGLScene() function called by onPaint()
void COpenGLControl::DrawGLScene()<br />
{<br />
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);<br />
   glLoadIdentity();<br />
   glRotatef(80.0f,-1.0f,0.0f,0.0f);<br />
<br />
   //GLfloat x_m, y_m, z_m, u_m, v_m;<br />
	GLfloat xTrans = -xpos;<br />
	GLfloat zTrans = -zpos;<br />
	GLfloat yTrans = -walkBias-0.25f;<br />
	GLfloat sceneRoty = 360.0f - yRotation;<br />
<br />
	glRotatef(lookUpDown,1.0f,0.0f,0.0f);<br />
	glRotatef(sceneRoty,0.0f,1.0f,0.0f);<br />
<br />
	glTranslatef(xTrans, yTrans, zTrans);<br />
<br />
   /**/<br />
	//Turn RIGHT<br />
   if(myRightButton==true){<br />
	   	//::MessageBox(0,(CString)yRotation,"Turn Right",MB_OK|MB_ICONINFORMATION |MB_DEFAULT_DESKTOP_ONLY);<br />
		//glRotatef(yRotation,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y axis<br />
		heading -= 10.0f; //0.22f;<br />
		yRotation = heading;<br />
		::SetFocus(m_hWnd);<br />
		//DrawGLScene();<br />
		//::MessageBox(0,(CString)yRotation,"Turn Right",MB_OK|MB_ICONINFORMATION |MB_DEFAULT_DESKTOP_ONLY);<br />
<br />
	}<br />
	//Turn LEFT<br />
	if(myLeftButton==true){<br />
		//::MessageBox(0,(CString)yRotation,"Turn Left",MB_OK|MB_ICONINFORMATION |MB_DEFAULT_DESKTOP_ONLY);<br />
		heading += 10.0f;	//0.22f;	<br />
		yRotation = heading;<br />
		::SetFocus(m_hWnd);<br />
		//::SetFocus(this);<br />
		//glRotatef(yRotation,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y axis		<br />
	}/**/<br />
<br />
	if(myUpButton==true){<br />
		xpos -= (float)sin(heading*piover180) * 0.05f;		//0.05f<br />
		zpos -= (float)cos(heading*piover180) * 0.05f;<br />
		if (walkBiasAngle >= 359.0f)<br />
		{<br />
			walkBiasAngle = 0.0f;<br />
		}<br />
		else<br />
		{<br />
			walkBiasAngle+= 10;<br />
		}<br />
		walkBias = (float)sin(walkBiasAngle * piover180)/20.0f;<br />
<br />
		::MessageBox(0,"Moving Forward","Move Forward",MB_OK|MB_ICONINFORMATION |MB_DEFAULT_DESKTOP_ONLY);<br />
<br />
	}<br />
<br />
	if(myDownButton==true){<br />
		xpos += (float)sin(heading*piover180) * 0.05f;		//0.05f;<br />
		zpos += (float)cos(heading*piover180) * 0.05f;		//0.05f;<br />
		if (walkBiasAngle <= 1.0f)<br />
		{<br />
			walkBiasAngle = 359.0f;<br />
		}<br />
		else<br />
		{<br />
			walkBiasAngle-= 10;<br />
		}<br />
		walkBias = (float)sin(walkBiasAngle * piover180)/20.0f;<br />
<br />
	}<br />
<br />
	if(myPageUpButton==true){	//VK_PRIOR<br />
		lookUpDown-=20.0f;<br />
		//z-=0.02f;<br />
	}<br />
<br />
	if(myPageDownButton==true){	//VK_NEXT<br />
		lookUpDown+=20.0f;<br />
		//z+=0.02f;<br />
	}<br />
 <br />
   //***************************<br />
   // DRAWING CODE<br />
   //***************************<br />
   /**************DATABASE CONNECTION*************/<br />
/*	*/<br />
	HRESULT hr;<br />
	CoInitialize(NULL);<br />
	<br />
	try{<br />
		//Create a pointer to a Connection in memory<br />
		//ADODB::_ConnectionPtr cnSURMPtr;<br />
		hr = cnSURMPtr2.CreateInstance(__uuidof(ADODB::Connection));<br />
		if (FAILED(hr))<br />
		{<br />
			throw _com_error(hr);<br />
		}<br />
		<br />
		//Create a pointer to a Recordset in memory<br />
		hr = rsObjectsPtr.CreateInstance(__uuidof(ADODB::Recordset));<br />
		if (FAILED(hr))<br />
		{<br />
			throw _com_error(hr);<br />
		}<br />
		<br />
		//Set Connection properties<br />
		cnSURMPtr2->CursorLocation = ADODB::adUseClient;<br />
		<br />
		//Generate connection string<br />
		_bstr_t dbLocation(L"");<br />
		dbLocation = (L".\\SURM.mdb");<br />
		<br />
		//Open the connection<br />
		cnSURMPtr2->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ dbLocation +";Persist Security Info=False","","",ADODB::adConnectUnspecified);<br />
<br />
		//Open Objects recordset<br />
		rsObjectsPtr->Open("SELECT * from Objects", cnSURMPtr2.GetInterfacePtr(),<br />
		ADODB::adOpenDynamic, ADODB::adLockOptimistic, ADODB::adCmdText);<br />
		<br />
		//Read from First to Last Record to load into GLWindow<br />
		if(!rsObjectsPtr->ADOEOF){<br />
			if(rsObjectsPtr->GetRecordCount()>0){<br />
				//Move to the FIRST record<br />
				//rsObjectsPtr->MoveFirst();<br />
				while (rsObjectsPtr->ADOEOF == false){<br />
					//Code to load cordinates in GLWindow<br />
					_variant_t myCoordinates;<br />
					<br />
					//Read from DB<br />
					myCoordinates = rsObjectsPtr->GetCollect(L"Coordinates");<br />
					//myCoordinates = rsObjectsPtr->Fields->GetItem(L"Coordinates")->GetValue();<br />
<br />
					if(myCoordinates.vt != VT_NULL){<br />
						//Change to String and pick each vertex coordinate<br />
						CString myStrCoords;<br />
<br />
						myStrCoords = static_cast<char *>(_bstr_t(myCoordinates.bstrVal));<br />
						<br />
						//if(myStrCoords != ""){<br />
						//Determine array size<br />
						int myArraySize = (myStrCoords.GetLength()/15);<br />
						//CString singleCoord[myArraySize] = new CString[myArraySize];<br />
						CString *singleCoord = new CString[myArraySize];<br />
						int tokenCounter = 0;<br />
						<br />
						//Put each token into an array element <br />
						while(myStrCoords.GetLength()>=15){<br />
							singleCoord[tokenCounter] = myStrCoords.Left(15);<br />
							//myStrCoords.TrimLeft(10);<br />
							myStrCoords.Delete(0,15);<br />
							tokenCounter++;<br />
						}<br />
						<br />
						//Draw the LINES or QUADS<br />
						if(tokenCounter==2){<br />
							//srand(int(time(NULL)));<br />
							drawLine(singleCoord[0],singleCoord[1]);<br />
						}<br />
						else if(tokenCounter>2){<br />
							//srand(int(time(NULL)));<br />
							drawQuad(singleCoord[0],singleCoord[1],singleCoord[2],singleCoord[3]);							<br />
						}<br />
					}//IF statement end bracket<br />
					//Move to next record if not EOF<br />
					rsObjectsPtr->MoveNext();<br />
				}<br />
				if(rsObjectsPtr->BOF){<br />
					rsObjectsPtr->MoveFirst();<br />
				}<br />
				if(rsObjectsPtr->ADOEOF){<br />
					rsObjectsPtr->MoveLast();<br />
				}<br />
			};<br />
		}<br />
	}<br />
	catch(_com_error &e)<br />
	{<br />
		AfxMessageBox(static_cast<char *>(e.Description()));<br />
		//ShowWindow(1);<br />
	}<br />
	catch(...)<br />
	{<br />
		//std::cerr << "Unhandled Exception";<br />
		AfxMessageBox("Unhandled Exception");<br />
	};<br />
<br />
	myRightButton = false;<br />
	myLeftButton = false;<br />
	myUpButton = false;<br />
	myDownButton = false;<br />
	myPageUpButton = false;<br />
	myPageDownButton = false;<br />
	myHomeButton = false;<br />
<br />
   SwapBuffers(dc->m_hDC);<br />
   //::MessageBox(0,"The End","Ha?",MB_ICONINFORMATION | MB_DEFAULT_DESKTOP_ONLY);<br />
}


Since i would like the rotation and translation to happen either by pressing buttons or key-presses, i have the following code: (NB: Without the message boxes it doesn't work, but with them ... it seems to send the focus back to the correct control - which i'm not too sure whether it's the dialog itself or the GLWindow within the dialog)
BOOL COpenGLMFCDlg::PreTranslateMessage(MSG* pMsg) <br />
{<br />
	/*WORKS<br />
	if( pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_DIVIDE || pMsg->wParam == VK_DELETE) ){<br />
		m_Txt_ObjectTypeName.SetWindowText("Another Event fired");<br />
		AfxMessageBox("Testing");<br />
	*/<br />
<br />
	if (pMsg->message == WM_KEYDOWN)<br />
	{<br />
		if (pMsg->wParam == VK_RIGHT){	//Right button<br />
			//m_Txt_ObjectTypeName.SetWindowText("One More Event fired");<br />
			openGLControl.myRightButton = true;<br />
			//::MessageBox(0,"One more Event fired","My fired Event",MB_ICONINFORMATION |MB_SYSTEMMODAL|MB_DEFAULT_DESKTOP_ONLY);<br />
<br />
			m_Txt_ObjectTypeName.SetWindowText("Right fired"+(CString)(openGLControl.yRotation));<br />
		}<br />
<br />
		if (pMsg->wParam == VK_LEFT){	//Left Button<br />
			//m_Txt_ObjectTypeName.SetWindowText("One More Event fired");<br />
			openGLControl.myLeftButton = true;<br />
			::MessageBox(0,"One more Event fired","My fired Event",MB_ICONINFORMATION |MB_SYSTEMMODAL|MB_DEFAULT_DESKTOP_ONLY);<br />
		}<br />
		<br />
		if (pMsg->wParam == VK_UP){	//UP Button<br />
			//m_Txt_ObjectTypeName.SetWindowText("One More Event fired");<br />
			openGLControl.myUpButton = true;<br />
			::MessageBox(0,"Up Event Fired","Up Event",MB_ICONINFORMATION |MB_SYSTEMMODAL|MB_DEFAULT_DESKTOP_ONLY);<br />
<br />
		}<br />
<br />
		if (pMsg->wParam == VK_DOWN){	//Down Button<br />
			//m_Txt_ObjectTypeName.SetWindowText("One More Event fired");<br />
			//::MessageBox(0,"One more Event fired","My fired Event",MB_ICONINFORMATION |MB_SYSTEMMODAL|MB_DEFAULT_DESKTOP_ONLY);<br />
			openGLControl.myDownButton = true;<br />
		}<br />
		if (pMsg->wParam == VK_PRIOR){	//PageUp Button<br />
			//m_Txt_ObjectTypeName.SetWindowText("One More Event fired");<br />
			openGLControl.myPageUpButton = true;<br />
			::MessageBox(0,"Page Up Event fired","PageUp Event",MB_ICONINFORMATION |MB_SYSTEMMODAL|MB_DEFAULT_DESKTOP_ONLY);<br />
<br />
		}<br />
		if (pMsg->wParam == VK_NEXT){	//PageDown Button<br />
			//m_Txt_ObjectTypeName.SetWindowText("One More Event fired");<br />
			//AfxMessageBox("One More Event fired");<br />
			//::MessageBox(0,"One more Event fired","My fired Event",MB_ICONINFORMATION |MB_SYSTEMMODAL|MB_DEFAULT_DESKTOP_ONLY);<br />
			openGLControl.myPageDownButton = true;<br />
<br />
		}<br />
<br />
	}<br />
	//return TRUE;<br />
	return CDialog::PreTranslateMessage(pMsg);<br />
}


Above was the code for keypresses... now for the buttons events code
void COpenGLMFCDlg::OnCmdUp() <br />
{<br />
	// TODO: Add your control notification handler code here<br />
	openGLControl.myUpButton = true;<br />
  	::MessageBox(0,"Up Button Event Fired"/*+(CString)yRotation*/,"Move Forwards",MB_OK|MB_ICONINFORMATION |MB_DEFAULT_DESKTOP_ONLY);<br />
<br />
	<br />
}<br />
<br />
void COpenGLMFCDlg::OnCmdRight() <br />
{<br />
	// TODO: Add your control notification handler code here<br />
	<br />
	openGLControl.myRightButton = true;<br />
	/*<br />
	openGLControl.yRotation += 20.0f;<br />
<br />
	*/<br />
<br />
   	::MessageBox(0,"Right Button Event Fired"/*+(CString)yRotation*/,"Turn Right",MB_OK|MB_ICONINFORMATION |MB_DEFAULT_DESKTOP_ONLY);<br />
<br />
}<br />
<br />
void COpenGLMFCDlg::OnCmdLeft() <br />
{<br />
	// TODO: Add your control notification handler code here<br />
	openGLControl.myLeftButton = true;<br />
  	::MessageBox(0,"Left Button Event Fired"/*+(CString)yRotation*/,"Turn Left",MB_OK|MB_ICONINFORMATION |MB_DEFAULT_DESKTOP_ONLY);<br />
<br />
	<br />
}<br />
<br />
void COpenGLMFCDlg::OnCmdDown() <br />
{<br />
	// TODO: Add your control notification handler code here<br />
	openGLControl.myDownButton = true;<br />
  	::MessageBox(0,"Down Button Event Fired"/*+(CString)yRotation*/,"Move backwards",MB_OK|MB_ICONINFORMATION |MB_DEFAULT_DESKTOP_ONLY);<br />
<br />
	<br />
}

This is the onPaint() function
void COpenGLControl::OnPaint() <br />
{	<br />
	// Draw objects with polygon offset.	//So as to get the outlines<br />
	/**/<br />
	glEnable( GL_POLYGON_OFFSET_FILL );<br />
		glPolygonOffset( 1.0, 1.0 );<br />
		//DrawObjects();<br />
		DrawGLScene();<br />
	glDisable( GL_POLYGON_OFFSET_FILL );<br />
<br />
	// Draw smooth anti-aliased outline over polygons.<br />
	glEnable( GL_BLEND );<br />
	glEnable( GL_LINE_SMOOTH );<br />
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );<br />
	glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );<br />
		DrawGLScene();<br />
	glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );<br />
	glDisable( GL_LINE_SMOOTH );<br />
	glDisable( GL_BLEND );<br />
	/**/<br />
<br />
	//DrawGLScene();<br />
	<br />
	CWnd::OnPaint();<br />
	myRightButton = false;<br />
	myLeftButton = false;<br />
	// Do not call CWnd::OnPaint() for painting messages<br />
}

I think the issue is something to do with the focus being lost somewhere to some control. onPaint an drawGLscene are in the OpenGLControl functions

Hope this helps...

-- modified at 12:16 Thursday 30th March, 2006
QuestionNeed your help! About CWebBrowser2. Pin
figer29-Mar-06 21:56
figer29-Mar-06 21:56 
AnswerRe: Need your help! About CWebBrowser2. Pin
Sheng Jiang 蒋晟30-Mar-06 11:52
Sheng Jiang 蒋晟30-Mar-06 11:52 
QuestionVery simple question Pin
hanno2529-Mar-06 21:04
hanno2529-Mar-06 21:04 
AnswerRe: Very simple question Pin
benjymous29-Mar-06 21:08
benjymous29-Mar-06 21:08 
AnswerRe: Very simple question Pin
Trollslayer29-Mar-06 21:49
mentorTrollslayer29-Mar-06 21:49 
Answer[OT] Pin
Rage29-Mar-06 23:12
professionalRage29-Mar-06 23:12 
QuestionWhy does this simple dynamic array experiment crash? Pin
Cristoff29-Mar-06 20:48
Cristoff29-Mar-06 20:48 
AnswerRe: Why does this simple dynamic array experiment crash? Pin
RockyJames29-Mar-06 21:03
RockyJames29-Mar-06 21:03 
GeneralRe: Why does this simple dynamic array experiment crash? Pin
Cristoff29-Mar-06 21:33
Cristoff29-Mar-06 21:33 
AnswerRe: Why does this simple dynamic array experiment crash? Pin
Taka Muraoka29-Mar-06 21:37
Taka Muraoka29-Mar-06 21:37 
GeneralRe: Why does this simple dynamic array experiment crash? Pin
Cristoff29-Mar-06 21:53
Cristoff29-Mar-06 21:53 
GeneralRe: Why does this simple dynamic array experiment crash? Pin
Cristoff29-Mar-06 21:55
Cristoff29-Mar-06 21:55 
GeneralRe: Why does this simple dynamic array experiment crash? Pin
Taka Muraoka30-Mar-06 3:47
Taka Muraoka30-Mar-06 3:47 
QuestionCheck box background color Pin
snir_ya29-Mar-06 20:42
snir_ya29-Mar-06 20:42 
AnswerRe: Check box background color Pin
RockyJames29-Mar-06 21:05
RockyJames29-Mar-06 21:05 
GeneralRe: Check box background color Pin
Nibu babu thomas29-Mar-06 22:17
Nibu babu thomas29-Mar-06 22:17 
GeneralRe: Check box background color Pin
snir_ya29-Mar-06 22:29
snir_ya29-Mar-06 22:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.