💾 Archived View for blitter.com › OLGA › OLGA › AUTO › AUTODLG.CPP captured on 2022-06-04 at 01:36:13.

View Raw

More Information

⬅️ Previous capture (2021-12-17)

-=-=-=-=-=-=-

// autoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "auto.h"
#include "autoDlg.h"
#include "winbase.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

UINT MyThreadProc( LPVOID pParam );
#define BITMAP_WIDTH	16
#define BITMAP_HEIGHT	16
#define NUM_BITMAPS		5

/////////////////////////////////////////////////////////////////////////////
// CAutoDlg dialog

CAutoDlg::CAutoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAutoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAutoDlg)
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	LineCount();
	m_can_resize = FALSE;

}

void CAutoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAutoDlg)
	DDX_Control(pDX, IDC_PS, m_ps);
	DDX_Control(pDX, IDCANCEL, m_Quit);
	DDX_Control(pDX, ID_CANCEL_SEARCH, m_Stop);
	DDX_Control(pDX, ID_START_SEARCH, m_Start);
	DDX_Control(pDX, IDC_PROGRESS1, m_progress);
	DDX_Control(pDX, IDC_SEARCH_STR, m_search_string);
	DDX_Control(pDX, IDC_CHECK_ALL, m_check_all);
	DDX_Control(pDX, IDC_CHECK_TAB, m_check_tab);
	DDX_Control(pDX, IDC_CHECK_CHORD, m_check_chord);
	DDX_Control(pDX, IDC_CHECK_BTAB, m_check_btab);
	DDX_Control(pDX, IDC_LIST1, m_list);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAutoDlg, CDialog)
	//{{AFX_MSG_MAP(CAutoDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(ID_START_SEARCH, OnStartSearch)
	ON_BN_CLICKED(IDC_CHECK_ALL, OnCheckAll)
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_CHECK_BTAB, OnCheckBtab)
	ON_BN_CLICKED(IDC_CHECK_CHORD, OnCheckChord)
	ON_BN_CLICKED(IDC_CHECK_TAB, OnCheckTab)
	ON_BN_CLICKED(ID_CANCEL_SEARCH, OnCancelSearch)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST1, OnColumnclickList1)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_USER+100,OnThreadDone)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAutoDlg message handlers

BOOL CAutoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	m_check_tab.SetCheck(1);

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	int			i;
	CString		s;
	LV_COLUMN	lv;
  
	m_list.ModifyStyle(LVS_SORTASCENDING | LVS_SORTDESCENDING,  LVS_REPORT|LVS_SINGLESEL|LVS_NOSORTHEADER);

  
    lv.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
	lv.fmt = LVCFMT_LEFT;
	// Create columns in the list control and
	// give each column a header string.
	for (i = IDS_FILE; i <= IDS_DIRECTORY; i++)
	{
		s.LoadString(i); 
		//lv.cx = 20 * m_list.GetStringWidth(s) / 10;
		if (i==IDS_FILE)lv.cx = 160;
		if (i==IDS_TYPE)lv.cx = 40;
		if (i==IDS_DIRECTORY)lv.cx = 200;
		lv.pszText = (char *) (const char *)s;
		m_list.InsertColumn(i - IDS_FILE, &lv);
	}
  
	CheckRadioButton(
    IDC_RADIO_NAME,	// identifier of first radio button in group
    IDC_RADIO_CONTENTS,// identifier of last radio button in group
	
	// identifier of radio button to select
    IDC_RADIO_NAME);	

	// Disable the stop button (stop search)
	m_Stop.EnableWindow(FALSE);


	//	Insert the image list
	CreateImageList();

	m_can_resize = TRUE;
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CAutoDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

HCURSOR CAutoDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CAutoDlg::OnStartSearch() 
{
	char* pszFileName = ".\\filelist.txt";
	CStdioFile myFile;
	CFileException fileException;
	CString inputLine;	
	CString dir;	
	CString fileName;	

	UpdateData(TRUE);

	// Get the string and start the search
	m_search_string.GetWindowText(m_text);

	// disable the controls before we start the search
	m_search_string.SetReadOnly(TRUE);

	//disable check boxes
	m_check_all.EnableWindow(FALSE);
	m_check_tab.EnableWindow(FALSE);
	m_check_chord.EnableWindow(FALSE);
	m_check_btab.EnableWindow(FALSE);

	// disable radio buttons
	GetDlgItem(IDC_RADIO_NAME)->EnableWindow(FALSE);
	GetDlgItem(IDC_RADIO_CONTENTS)->EnableWindow(FALSE);

	m_Start.EnableWindow(FALSE);
	m_Quit.EnableWindow(FALSE);
	m_Stop.EnableWindow(TRUE);

	
	UpdateData(FALSE);

	m_searchOk = TRUE;

	AfxBeginThread(MyThreadProc, this);

}


  
UINT MyThreadProc( LPVOID pParam )
{
	char* pszFileName = ".\\filelist.txt";
	CStdioFile myFile;
	CFileException fileException;
	CString inputLine;	
	CString dir;	
	CString fileName;	
	CString typeString;

    CAutoDlg* pObject = (CAutoDlg*)pParam;

    // do something with 'pObject'
	pObject->m_progress.SetRange(0,pObject->m_lineCount);


	// Delete everything in the list
	pObject->m_list.DeleteAllItems();


	// OK open the file...

	int x=0;
	int row = 0;
	if ( !myFile.Open( pszFileName, CFile::modeRead | CFile::typeText, &fileException ))
	{
		pObject->PostMessage(WM_USER+100);

		CString wonk;
		wonk.Format( "Can't open file %s, error = %u\n",	pszFileName, fileException.m_cause );
		AfxMessageBox(wonk);
		return 0;
	}
  
	//go through the thing line by line looking for the string
	CString direc;
	direc = "Directory";
	CString curDir;
	CString stripped;
	int type;

	while(myFile.ReadString( inputLine ) && pObject->m_searchOk ){

		type = IDS_OTHER;
		if (inputLine.Left(9) == direc){
			curDir = inputLine.Mid(15);
			type = IDS_DIR;
		}
		

		if (inputLine.Find(pObject->m_text) >= 0) {



			if (type != IDS_DIR) {
				if (inputLine.Find(".tab")>=0) type = IDS_TAB;
				else if (inputLine.Find(".crd")>=0) type = IDS_CRD;
				else if (inputLine.Find(".btab")>=0) type = IDS_BTAB;
				else if (inputLine.Find(".pro")>=0) type = IDS_PRO;
				else if (inputLine.Find(".num")>=0) type = IDS_NASH;
				else if (inputLine.Find(".tab")>=0) type = IDS_TAB;
			}
			stripped = inputLine;
			if (type == IDS_DIR) {
				// strip off the prefix of the directories
				stripped = inputLine.Mid(inputLine.ReverseFind('\\')+1);
			} else if (type != IDS_OTHER) {
				// strip off the suffix
				stripped = inputLine.Left(inputLine.ReverseFind('.'));
			}

			if (  !(pObject->m_check_btab.GetCheck()&&type==IDS_BTAB) &&
				  !(pObject->m_check_tab.GetCheck()&&type==IDS_TAB) &&
				  !(pObject->m_check_chord.GetCheck()&&type==IDS_CRD) &&
				  !pObject->m_check_all.GetCheck()){
				continue;
			}

			
			typeString.LoadString(type);
			if (type != IDS_DIR){
				pObject->m_list.InsertItem(row, stripped, type-IDS_TAB);
				pObject->m_list.SetItemText(row, IDS_TYPE-IDS_FILE, typeString);
				pObject->m_list.SetItemText(row++, IDS_DIRECTORY-IDS_FILE, curDir);
			}else{
				pObject->m_list.InsertItem(row, stripped, type-IDS_TAB);
				pObject->m_list.SetItemText(row, IDS_TYPE-IDS_FILE, typeString);
				pObject->m_list.SetItemText(row++, IDS_DIRECTORY-IDS_FILE, curDir);
			}
		}
		x++;
		if (x % 150 == 0) pObject->m_progress.SetPos(x);
	}

	myFile.Close();


	pObject->PostMessage(WM_USER+100);


    return 0;	// thread completed successfully
}




void CAutoDlg::LineCount()
{
	char* pszFileName = ".\\filelist.txt";
	CStdioFile myFile;
	CFileException fileException;
	CString inputLine;	
	CString dir;	
	CString fileName;	


	// OK open the file...

	m_lineCount=0;
	if ( !myFile.Open( pszFileName, CFile::modeRead | CFile::typeText, &fileException ))
	{
		CString wonk;
		wonk.Format( "Can't open file %s, error = %u\n",	pszFileName, fileException.m_cause );
		//AfxMessageBox(wonk);
		return ;
	}
  
	//go through the thing line by line counting the lines
	while(myFile.ReadString( inputLine ) ){

		m_lineCount++;
	}

	myFile.Close();
}

  





















void CAutoDlg::OnCheckAll() 
{
	if (m_check_all.GetCheck() == 1){
		m_check_btab.SetCheck(1);
		m_check_chord.SetCheck(1);
		m_check_tab.SetCheck(1);
	}
	SetStartButton();
}

void CAutoDlg::OnSize(UINT nType, int cx, int cy) 
{

	if (cx < 392) cx = 392;
	if (cy < 405) cy = 405;
	if (m_can_resize) {
		m_list.SetWindowPos( &wndTop,  275, 10,  cx-275-10,  cy-40-10, SWP_SHOWWINDOW );
		m_progress.SetWindowPos( &wndTop,  10, cy-25,  cx-10-10,  15 , SWP_SHOWWINDOW );
//		m_ps.SetWindowPos(&wndTop,10,450,100, 100, SWP_SHOWWINDOW);
	}
	CDialog::OnSize(nType, cx, cy);
}

void CAutoDlg::OnCheckBtab() 
{
	if (m_check_btab.GetCheck() == 0){
		m_check_all.SetCheck(0);
	}
	SetStartButton();

}

void CAutoDlg::OnCheckChord() 
{
	if (m_check_chord.GetCheck() == 0){
		m_check_all.SetCheck(0);
	}
	SetStartButton();
	
}

void CAutoDlg::OnCheckTab() 
{
	if (m_check_tab.GetCheck() == 0){
		m_check_all.SetCheck(0);
	}
	SetStartButton();
}

void CAutoDlg::SetStartButton(){
	if (m_check_tab.GetCheck() == 0 &&
		m_check_btab.GetCheck() == 0 &&
		m_check_chord.GetCheck() == 0 &&
		m_check_all.GetCheck() == 0){
			m_Start.EnableWindow(FALSE);
	} else {
			m_Start.EnableWindow(TRUE);
	}
}


afx_msg LONG CAutoDlg::OnThreadDone( UINT, LONG ){

	// enable the controls before we start the search
	m_search_string.SetReadOnly(FALSE);

	//enable check boxes
	m_check_all.EnableWindow(TRUE);
	m_check_tab.EnableWindow(TRUE);
	m_check_chord.EnableWindow(TRUE);
	m_check_btab.EnableWindow(TRUE);

	// enable radio buttons
	GetDlgItem(IDC_RADIO_NAME)->EnableWindow(TRUE);
	GetDlgItem(IDC_RADIO_CONTENTS)->EnableWindow(TRUE);

	m_Start.EnableWindow(TRUE);
	m_Quit.EnableWindow(TRUE);
	m_Stop.EnableWindow(FALSE);

	
	UpdateData(FALSE);
	return 0;
}

void CAutoDlg::OnCancelSearch() 
{
	m_searchOk = FALSE;

}



/******************************************************************************

  
void CAutoDlg::CreateImageList()
{
	m_ImageList = new CImageList();	//dynamically allocate list
	m_ImageList->Create(BITMAP_WIDTH, BITMAP_HEIGHT, TRUE,
				IDS_DIR-IDS_TAB+1, 0);
  
	CBitmap bitmap;	// Temporary holding area for current
					// for bitmap being loaded

int x;
	// note the FFFFFFF means to create the mask out of the Black pixels
x=	bitmap.LoadBitmap(IDB_TAB);
x=	m_ImageList->Add(&bitmap, (COLORREF)0xFF00FF);
	bitmap.DeleteObject();
x=	bitmap.LoadBitmap(IDB_BTAB);
x=	m_ImageList->Add(&bitmap, (COLORREF)0xFF00FF);
	bitmap.DeleteObject();
x=	bitmap.LoadBitmap(IDB_CRD);
x=	m_ImageList->Add(&bitmap, (COLORREF)0xFF00FF);
	bitmap.DeleteObject();
x=	bitmap.LoadBitmap(IDB_PRO);
x=	m_ImageList->Add(&bitmap, (COLORREF)0xFF00FF);
	bitmap.DeleteObject();
x=	bitmap.LoadBitmap(IDB_NASH);
x=	m_ImageList->Add(&bitmap, (COLORREF)0xFF00FF);
	bitmap.DeleteObject();
x=	bitmap.LoadBitmap(IDB_OTHER);
x=	m_ImageList->Add(&bitmap, (COLORREF)0xFF00FF);
	bitmap.DeleteObject();
x=	bitmap.LoadBitmap(IDB_DIR);
x=	m_ImageList->Add(&bitmap, (COLORREF)0xFF00FF);
	bitmap.DeleteObject();


	// Associate the image list with the list control.
	m_list.SetImageList(m_ImageList, LVSIL_SMALL);
}



void CAutoDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int z = m_list.GetNextItem(-1,LVNI_SELECTED);

	if (z ==-1)
		return;

	CString x;
	if (m_list.GetItemText(z,1)=="other")
		x.Format(".\\Music\\%s\\%s",m_list.GetItemText(z,2),m_list.GetItemText(z,0));
	else
		x.Format(".\\Music\\%s\\%s.%s",m_list.GetItemText(z,2),m_list.GetItemText(z,0),m_list.GetItemText(z,1));

	CString				fileViewerApp;
	CString				logFilePath;
	STARTUPINFO			startupInfo;
	PROCESS_INFORMATION	processInfo;

	TCHAR y[100];

	if (m_ps.GetCheck() == FALSE){

		GetWindowsDirectory(y, 100);
		fileViewerApp = y;
		fileViewerApp+="\\notepad.exe";

		
		logFilePath  = " " + x;	// needs space to recognize arg1

		startupInfo.cb = sizeof( STARTUPINFO );
		startupInfo.lpReserved = NULL;
		startupInfo.dwFlags    = 0;
		startupInfo.lpTitle    = NULL;
		startupInfo.dwX        = 0;
		startupInfo.dwY        = 0;
		startupInfo.dwXSize    = 0;
		startupInfo.dwYSize    = 0;

		if( !CreateProcess(	(LPCTSTR) fileViewerApp,
							(LPTSTR) (LPCTSTR) logFilePath,
							NULL,			// do not inherit returned handles
							NULL,
							FALSE,
							CREATE_NEW_PROCESS_GROUP | NORMAL_PRIORITY_CLASS,
							NULL,			// Use our environment
							NULL,			// Use our current working directory
							&startupInfo,
							&processInfo ) )
		{
			AfxMessageBox( "*** Unable to launch notepad" );
		}

	// Chord filter
	} else {
		GetWindowsDirectory(y, 100);
		fileViewerApp = y;
		fileViewerApp = "chord";

		
		logFilePath  = " " + x;	// needs space to recognize arg1
		logFilePath	 += " > temp.ps";


		startupInfo.cb = sizeof( STARTUPINFO );
		startupInfo.lpReserved = NULL;
		startupInfo.dwFlags    = 0;
		startupInfo.lpTitle    = NULL;
		startupInfo.dwX        = 0;
		startupInfo.dwY        = 0;
		startupInfo.dwXSize    = 0;
		startupInfo.dwYSize    = 0;

		if( !CreateProcess(	(LPCTSTR) fileViewerApp,
							(LPTSTR) (LPCTSTR) logFilePath,
							NULL,			// do not inherit returned handles
							NULL,
							FALSE,
							CREATE_NEW_PROCESS_GROUP | NORMAL_PRIORITY_CLASS,
							NULL,			// Use our environment
							NULL,			// Use our current working directory
							&startupInfo,
							&processInfo ) )
		{
			AfxMessageBox( "*** Unable to launch chord.exe" );
			return;
		}

		logFilePath	 += "gsview temp.ps";

		startupInfo.cb = sizeof( STARTUPINFO );
		startupInfo.lpReserved = NULL;
		startupInfo.dwFlags    = 0;
		startupInfo.lpTitle    = NULL;
		startupInfo.dwX        = 0;
		startupInfo.dwY        = 0;
		startupInfo.dwXSize    = 0;
		startupInfo.dwYSize    = 0;

		if( !CreateProcess(	(LPCTSTR) fileViewerApp,
							(LPTSTR) (LPCTSTR) logFilePath,
							NULL,			// do not inherit returned handles
							NULL,
							FALSE,
							CREATE_NEW_PROCESS_GROUP | NORMAL_PRIORITY_CLASS,
							NULL,			// Use our environment
							NULL,			// Use our current working directory
							&startupInfo,
							&processInfo ) )
		{
			AfxMessageBox( "*** Unable to launch gsview" );
		}
	}

}

void CAutoDlg::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	m_list_ptr = &m_list;
//	m_list.SortItems(AutoSort,(DWORD)0);
	*pResult = 0;
	
}

int CALLBACK CAutoDlg::AutoSort(LPARAM one, LPARAM two, LPARAM col){
	
	return (m_list_ptr->GetItemText(one,col).Compare(m_list_ptr->GetItemText(two,col)));
}

CListCtrl *CAutoDlg::m_list_ptr;