Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / MFC

Threads with MFC

Rate me:
Please Sign up or sign in to vote.
4.38/5 (71 votes)
1 Feb 200313 min read 447.7K   21.4K   166  
Multithreading Programming with a MFC environment.
// LoopSlider.cpp : implementation file
//

#include "stdafx.h"

#include "LoopSlider.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLoopSlider



BEGIN_MESSAGE_MAP(CLoopSlider, CSliderCtrl)
	//{{AFX_MSG_MAP(CLoopSlider)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
ON_WM_HSCROLL_REFLECT()
END_MESSAGE_MAP()

//////////////////////////////////////////
CLoopSlider::CLoopSlider() : CSliderCtrl()
{
	
	m_iMax=0;
	m_iMin=0;
	m_iPosition=0;
	
}




CLoopSlider::~CLoopSlider()
{
	

}

///////////////////////////////////////////////////
void CLoopSlider::SetSlidePos( const int pos )
{
	
	m_iPosition = pos;
	
	SetPos( m_iPosition );
}

/////////////////////////////////////////////////////////////////////
void CLoopSlider::SetSlideRange( const int imin, const int imax )
{
	m_iMin = imin;
	m_iMax = imax;
	SetRange( m_iMin, m_iMax );
}




////////////////////////////////////////////////////////////////////
void CLoopSlider::HScroll(UINT ncode, UINT pos )
{
	
	
	if(theApp.m_ThreadsState ==END)
	{
		CSliderCtrl::OnVScroll( ncode, pos, NULL );
		m_iPosition = GetPos();
		CString str,code;
		char buf[2];
		CStdioFile fw;
		itoa(m_iPosition,buf,10);
		int sliderId=GetDlgCtrlID();
		CWnd* pWnd;
		str=(CString)buf;// the current position of the slider in string format
		switch(sliderId)
		{
			case IDC_SLIDER_T1:
				{
					pWnd=theApp.m_pMainWnd ->GetDlgItem(IDC_STATIC_T1);
					fw.Open ("slider1.txt",CFile::modeWrite);
					fw.WriteString (str);// writing the slider position to file
					fw.Close();
					
					//Displaying the code part with the new slider position which is set to the factor in the loop
					code="... ;                                                               ";
					code+="for ( int i = 0 ; i <80 ; i++)                                     ";
					code+="{                                                                      ";
					code+="for ( int p = 0 ; p <";
					code+=buf;
					code+="*800;p++);";
					code+="                         dcObject .TextOut( ThreadsNr ) ;";
					code+="                 ... ;                                                    ";
					code+="      }                                                              ";
					code+="... ;                                                       ";
					pWnd->SetWindowText (code);
					pWnd->ShowWindow (SW_SHOW);
					
					break;
				}
			case IDC_SLIDER_T2:
				{
					pWnd=theApp.m_pMainWnd ->GetDlgItem(IDC_STATIC_T2);
					fw.Open ("slider2.txt",CFile::modeWrite);
					fw.WriteString (str);
					fw.Close();
					//Displaying the code part with the new slider position which is set to the factor in the loop
					code="... ;                                                               ";
					code+="for ( int i = 0 ; i <80 ; i++)                                     ";
					code+="{                                                                      ";
					code+="for ( int p = 0 ; p <";
					code+=buf;
					code+="*800;p++);";
					code+="                         dcObject .TextOut( ThreadsNr ) ;";
					code+="                 ... ;                                                    ";
					code+="      }                                                              ";
					code+="... ;                                                       ";
					pWnd->SetWindowText (code);
					pWnd->ShowWindow (SW_SHOW);
					break;
				}
			case IDC_SLIDER_T3:
				{
					pWnd=theApp.m_pMainWnd ->GetDlgItem(IDC_STATIC_T3);
					fw.Open ("slider3.txt",CFile::modeWrite);
					fw.WriteString (str);
					fw.Close();
					//Displaying the code part with the new slider position which is set to the factor in the loop
					code="... ;                                                               ";
					code+="for ( int i = 0 ; i <80 ; i++)                                     ";
					code+="{                                                                      ";
					code+="for ( int p = 0 ; p <";
					code+=buf;
					code+="*800;p++);";
					code+="                         dcObject .TextOut( ThreadsNr ) ;";
					code+="                 ... ;                                                    ";
					code+="      }                                                              ";
					code+="... ;                                                       ";
					pWnd->SetWindowText (code);
					pWnd->ShowWindow (SW_SHOW);
					break;
				}
				
			case IDC_SLIDER_T4:
				{
					pWnd=theApp.m_pMainWnd ->GetDlgItem(IDC_STATIC_T4);
					fw.Open ("slider4.txt",CFile::modeWrite);
					fw.WriteString (str);
					fw.Close();
					//Displaying the code part with the new slider position which is set to the factor in the loop
					code="... ;                                                               ";
					code+="for ( int i = 0 ; i <80 ; i++)                                     ";
					code+="{                                                                      ";
					code+="for ( int p = 0 ; p <";
					code+=buf;
					code+="*800;p++);";
					code+="                         dcObject .TextOut( ThreadsNr ) ;";
					code+="                 ... ;                                                    ";
					code+="      }                                                              ";
					code+="... ;                                                       ";
					pWnd->SetWindowText (code);
					pWnd->ShowWindow (SW_SHOW);
					break;
				}
			case IDC_SLIDER_T5:
				{
					pWnd=theApp.m_pMainWnd ->GetDlgItem(IDC_STATIC_T5);
					fw.Open ("slider5.txt",CFile::modeWrite);
					fw.WriteString (str);
					fw.Close();
					//Displaying the code part with the new slider position which is set to the factor in the loop
					code="... ;                                                               ";
					code+="for ( int i = 0 ; i <80 ; i++)                                     ";
					code+="{                                                                      ";
					code+="for ( int p = 0 ; p <";
					code+=buf;
					code+="*800;p++);";
					code+="                         dcObject .TextOut( ThreadsNr ) ;";
					code+="                 ... ;                                                    ";
					code+="      }                                                              ";
					code+="... ;                                                       ";
					pWnd->SetWindowText (code);
					pWnd->ShowWindow (SW_SHOW);
					break;
				}
				break;
		}
		
	}
}

		




///////////////////////////////////////
int CLoopSlider::GetSliderPos (){return m_iPosition;}


///////////////////////////////////
void CLoopSlider::initSlider()


{
 SetSlideRange( 1,9 );
 SetSlidePos (1);
}


/////////////////////////////////////////////////////////////////////////////
// CLoopSlider message handlers

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer
Denmark Denmark
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions