Click here to Skip to main content
11,641,211 members (63,163 online)
Click here to Skip to main content
Add your own
alternative version

Threads with MFC

, 1 Feb 2003 311.9K 18.2K 152
Multithreading Programming with a MFC environment.
threads_and_mfc_demo.zip
Threads.aps
Threads.clw
Threads.dsp
Threads.dsw
Threads.ncb
Threads.opt
Threads.plg
Debug
Threads.res
res
Threads.ico
// 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

Share

About the Author

Aria Ansari
Software Developer
Denmark Denmark
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150731.1 | Last Updated 2 Feb 2003
Article Copyright 2003 by Aria Ansari
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid