⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testfirmdlg.cpp

📁 D12 Mcu 凌阳.用BULK传输方式,实现语音播放
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// TestfirmDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Testfirm.h"
#include "TestfirmDlg.h"
//#include "SHFileInfo1.h"

#include "Rwbulk.h"
#include "stdio.h"//for fread()
#include "memory.h"
#include "mmsystem.h"  //play wave
//----------
//#include "CommPort.h"
//#include "CommPort.cpp"
//----------
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern char * P_Dsacm_Path;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestfirmDlg dialog

CTestfirmDlg::CTestfirmDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestfirmDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestfirmDlg)
	m_BinFile_Path = _T("");
	m_Wave_File_Direction = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	hDevice1=INVALID_HANDLE_VALUE;
	hDevice2=INVALID_HANDLE_VALUE;
	ID0=1;
	ID1=2;
	ID2=3;
	ID3=4;
	nRet=10;
	UpLoad_Data_Buffer=NULL;
	DownLoad_Data_Buffer=NULL;

	Len=0;
	// download var set
	m_DownLoadFileLen=0;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestfirmDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestfirmDlg)
	DDX_Control(pDX, IDC_Up_Download_FileName, m_Up_Download_FileName);
	DDX_Control(pDX, IDC_PCFILETREE, m_PCFileTree);
	DDX_Text(pDX, IDC_Up_Download_FileName, m_BinFile_Path);
	DDX_Text(pDX, IDC_Wave_Direction_Filename, m_Wave_File_Direction);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestfirmDlg, CDialog)
	//{{AFX_MSG_MAP(CTestfirmDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_OPENUSB_BUTTON, OnOpenusbButton)
	ON_BN_CLICKED(IDC_CLOSEUSB_BUTTON, OnCloseusbButton)
	ON_BN_CLICKED(IDC_CONNECTTEST_BUTTON, OnConnecttestButton)
//	ON_BN_CLICKED(IDC_RECORD_BUTTON, OnRecordButton)
//	ON_BN_CLICKED(IDC_STOP_BUTTON, OnStopButton)
//	ON_BN_CLICKED(IDC_PLAY_BUTTON, OnPlayButton)
	ON_BN_CLICKED(IDC_DOWNLOAD_BUTTON, OnDownloadButton)
	ON_BN_CLICKED(IDC_UPLOAD_BUTTON, OnUploadButton)
	ON_NOTIFY(TVN_ITEMEXPANDING, IDC_PCFILETREE, OnItemexpandingPcfiletree)
	ON_NOTIFY(TVN_SELCHANGED, IDC_PCFILETREE, OnSelchangedPcfiletree)
	ON_BN_CLICKED(IDC_BIN_TO_WAVE_BUTTON, OnBinToWaveButton)
	ON_BN_CLICKED(IDC_PLAY_WAVE_BUTTON, OnPlayWaveButton)
	ON_BN_CLICKED(IDC_BIN_FILE_DIRECTION_BUTTON, OnBinFileDirectionButton)
	ON_BN_CLICKED(IDC_WAVE_FILE_DIRECTION_BUTTON, OnWaveFileDirectionButton)
	ON_BN_CLICKED(IDC_STOP_WAVE_BUTTON, OnStopWaveButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestfirmDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	Initialize();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTestfirmDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CTestfirmDlg::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();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTestfirmDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CTestfirmDlg::OnOK() 
{


	CDialog::OnOK();
}

void CTestfirmDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}
void CTestfirmDlg::Initialize()
{
	DWORD DriveInfo;
	int offset;
	char Drive[4];
	HTREEITEM itemnow;
	HICON hIcon[11];
	HICON hIconFlash[2];
	int n;
	char Desktop[64];

	m_ImageList.Create(16,16,ILC_MASK,11,11);
	m_ImageList1.Create(16,16,ILC_MASK,2,2);

	hIcon[0] = AfxGetApp()->LoadIcon(IDI_FCLOSE);
	hIcon[1] = AfxGetApp()->LoadIcon(IDI_FOPEN);
	hIcon[2] = AfxGetApp()->LoadIcon(IDI_FLOPY);
    hIcon[3] = AfxGetApp()->LoadIcon(IDI_DRIVE);
	hIcon[4] = AfxGetApp()->LoadIcon(IDI_DESKTOP);
	hIcon[5] = AfxGetApp()->LoadIcon(IDI_DISK);
	hIcon[6] = AfxGetApp()->LoadIcon(IDI_CD);
	hIcon[7] = AfxGetApp()->LoadIcon(IDI_CDDRIVE);
	hIcon[8] = AfxGetApp()->LoadIcon(IDI_IC);
	hIcon[9] = AfxGetApp()->LoadIcon(IDI_NORMAL);
	hIcon[10] = AfxGetApp()->LoadIcon (IDI_MUSIC);


	for (n = 0; n <= 10; n++) {
		m_ImageList.Add(hIcon[n]);//CImageList m_ImageList
	}
	for(n=0;n<=1;n++)
		m_ImageList1.Add(hIconFlash[n]);//CImageList m_ImageList1

	m_PCFileTree.SetImageList(&m_ImageList,TVSIL_NORMAL);//CTreeCtrl	m_PCFileTree;

	itemnow=m_PCFileTree.InsertItem("DeskTop",4,4,TVI_ROOT); 
	::GetWindowsDirectory(Desktop,64);  //char Desktop[64],存入C:\WINDOWS
	strcat(Desktop,"\\desktop\\\0");
	ReadSingleDirectory(Desktop,itemnow); //HTREEITEM itemnow;
	ReadSingleFile(Desktop,itemnow);
	DriveInfo=::GetLogicalDrives();
	
	offset=0;
	Drive[1]=':';//char Drive[4];
	Drive[2]='\\';
	Drive[3]='\0';
	while(DriveInfo)
	{
		int DriveType;

		if(DriveInfo&0x0001)
		{
			Drive[0]='A'+offset;
			switch(DriveType=::GetDriveType(Drive))
			{
			case DRIVE_FIXED:
			case DRIVE_RAMDISK:
				{
					itemnow=m_PCFileTree.InsertItem(Drive,3,3,TVI_ROOT);
					ReadSingleDirectory(Drive,itemnow);
					ReadSingleFile(Drive,itemnow);//
					break;
				}
			case DRIVE_REMOVABLE:
				{
					itemnow=m_PCFileTree.InsertItem(Drive,2,2,TVI_ROOT); 
					ReadSingleDirectory(Drive,itemnow);
					ReadSingleFile(Drive,itemnow);//
					break;	
				}
			case DRIVE_CDROM:
				{
					itemnow=m_PCFileTree.InsertItem(Drive,7,7,TVI_ROOT); 
					ReadSingleDirectory(Drive,itemnow);
					ReadSingleFile(Drive,itemnow);
					break;
				}
			case DRIVE_REMOTE:
			case DRIVE_NO_ROOT_DIR:
			case DRIVE_UNKNOWN:   
			default:
				break;
			}
		}
		
		DriveInfo>>=1;
		offset++;
	}

	
}

void CTestfirmDlg::OnItemexpandingPcfiletree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	HTREEITEM current=pNMTreeView->itemNew.hItem;
	CString FilePath=m_PCFileTree.GetItemText(current);//CTreeCtrl	m_PCFileTree;
	HTREEITEM parent=m_PCFileTree.GetParentItem(current);
	HTREEITEM next;

	while(parent)
	{
		current=parent;
		parent=m_PCFileTree.GetParentItem(current);
		FilePath=m_PCFileTree.GetItemText(current)+"\\"+FilePath;
	}

	current=pNMTreeView->itemNew.hItem;
	for(next=m_PCFileTree.GetChildItem(current);next;next=m_PCFileTree.GetNextSiblingItem(next))
	{
		CString NextPath=FilePath;
		NextPath=NextPath+"\\"+m_PCFileTree.GetItemText(next);
		if(NextPath.GetLength ()>3)
			NextPath.Delete (3);
		else
			NextPath.Delete (2);
		NextPath+="\\";
		if(!m_PCFileTree.ItemHasChildren(next))
		{
			ReadSingleDirectory(NextPath,next);
			//ReadSingleDirectory(NextPath,next);
			ReadSingleFile(NextPath,next);
		}
	}

	*pResult = 0;
} 

void CTestfirmDlg::OnSelchangedPcfiletree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	     // TODO: Add your control notification handler code here
	CString FilePath;
	CString temp;
	HTREEITEM current;
	HTREEITEM parent;
	current=m_PCFileTree.GetSelectedItem();
	FilePath=m_PCFileTree.GetItemText(current);
	if(current)                                  
	{
		temp=m_PCFileTree.GetItemText(current);   
		BinFileName=(LPSTR)(LPCTSTR)(temp);       

	}

	parent=m_PCFileTree.GetParentItem(current);
	if(!FilePath.Compare("DeskTop")&&!parent)
	{
		char Desktop[64];
		::GetWindowsDirectory(Desktop,64);
		strcat(Desktop,"\\desktop\0");
		FilePath=Desktop; 
		FilePath.Insert (3,"\\");
	}
	while(parent)
	{
		current=parent;
		
	

	    parent=m_PCFileTree.GetParentItem(current);//取路径
		FilePath=m_PCFileTree.GetItemText(current)+"\\"+FilePath;//FilePath为文件名

	}

    CString filename=FilePath;
	if(filename.GetLength ()>3)
		 filename.Delete (3);
	else
		filename.Delete (2);
	m_BinFile_Path=filename;
	UpdateData(FALSE);
	*pResult = 0;
}
void CTestfirmDlg::ReadSingleDirectory(const char *szPath, HTREEITEM previous)
{
	WIN32_FIND_DATA fData;
	HANDLE h;
	char szNewPath[MAX_PATH];//Maximum length of full path
	char *pch=NULL;

	strcpy(szNewPath,szPath);
	strcat(szNewPath,"*.*");
	h=::FindFirstFile (szNewPath,&fData);
	if (h == (HANDLE) 0xFFFFFFFF) return;
	do{
		if(!strcmp(fData.cFileName, "..") ||
                !strcmp(fData.cFileName, ".") ) continue;
		while((pch = strchr(fData.cFileName, '!')) != NULL) 
			{
                *pch = '|';
			}
		if (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
	            HTREEITEM itemnow;
				strcpy(szNewPath, szPath);
				strcat(szNewPath,fData.cFileName);
				strcat(szNewPath, "\\");
				itemnow=m_PCFileTree.InsertItem(fData.cFileName,0,1,previous);
		}

	}while (::FindNextFile(h, &fData));
	

}


void CTestfirmDlg::ReadSingleFile(const char *szPath, HTREEITEM previous)
{
	WIN32_FIND_DATA fData;
	HANDLE h;
	char szNewPath[MAX_PATH];
	char *pch=NULL;

	strcpy(szNewPath,szPath);
	strcat(szNewPath,"*.*");
	h=::FindFirstFile (szNewPath,&fData);
	if (h == (HANDLE) 0xFFFFFFFF) return;
	do{
		if(!strcmp(fData.cFileName, "..") ||
                !strcmp(fData.cFileName, ".") ) continue;
		while((pch = strchr(fData.cFileName, '!')) != NULL) 
			{
                *pch = '|';
			}
		if(! (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
	      // It's a file, so make a storage
				HTREEITEM itemnow;
				strcpy(szNewPath, szPath);
				strcat(szNewPath,fData.cFileName);
				strcat(szNewPath, "\\");
				itemnow=m_PCFileTree.InsertItem(fData.cFileName,9,9,previous);
		}
		
	
	}while (::FindNextFile(h, &fData));
}
void CTestfirmDlg::OnOpenusbButton() 
{
	// TODO: Add your control notification handler code here
	char *filename1="PIPE02";
	char *filename2="PIPE03";
	hDevice1=open_file(filename1);//open endpoint2in
	hDevice2=open_file(filename2);//open endpoint2out
	if (hDevice1 == INVALID_HANDLE_VALUE||hDevice2 == INVALID_HANDLE_VALUE)
	{
		//AfxMessageBox("ERROR opening device: (%0d) returned from CreateFile\n", GetLastError());
		AfxMessageBox("ERROR open EndPoint2: returned from open_File\n");
	}
	else
	{
		AfxMessageBox("Device found, EndPoint2  open .\n");
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -