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

📄 progisp_assdlg.cpp

📁 熟悉AVR单片机的人一般都知道ZHIFENG的PROGISP软件
💻 CPP
字号:
// PROGISP_ASSDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PROGISP_ASS.h"
#include "PROGISP_ASSDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CPROGISP_ASSDlg dialog

CPROGISP_ASSDlg::CPROGISP_ASSDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPROGISP_ASSDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPROGISP_ASSDlg)
	m_csInfWnd = _T("");
	m_csFileTime = _T("");
	m_bDownloadCheck = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	//m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON2);
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPROGISP_ASSDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPROGISP_ASSDlg)
	DDX_Control(pDX, IDC_DOWNLOAD_CHECK, m_ctDownloadCheck);
	DDX_Control(pDX, IDC_DOWNLOAD_PROGRESS, m_ctDownloadProcess);
	DDX_Control(pDX, IDC_FILETIME_EDIT, m_ceFileTime);
	DDX_Control(pDX, IDC_INF_EDIT, m_ceInfWnd);
	DDX_Text(pDX, IDC_INF_EDIT, m_csInfWnd);
	DDX_Text(pDX, IDC_FILETIME_EDIT, m_csFileTime);
	DDX_Check(pDX, IDC_DOWNLOAD_CHECK, m_bDownloadCheck);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPROGISP_ASSDlg, CDialog)
	//{{AFX_MSG_MAP(CPROGISP_ASSDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_OPEN_BUTTON, OnOpenButton)
	ON_BN_CLICKED(IDC_DOWNLOAD_CHECK, OnDownloadCheck)
	ON_BN_CLICKED(IDC_TEST_BUTTON, OnTestButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPROGISP_ASSDlg message handlers

BOOL CPROGISP_ASSDlg::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
	/*
	g_pFileIni=NULL;
	g_pFileIni=fopen("PGH.ini","r");
	if(g_pFileIni==NULL)
	{
		g_pFileIni=fopen("PGH.ini","w");
	}
	fclose(g_pFileIni);
	*/
	SetWindowPos(&this->wndTopMost ,0,0,0,0,SWP_NOSIZE);
	m_ctDownloadCheck.EnableWindow(FALSE);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPROGISP_ASSDlg::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 CPROGISP_ASSDlg::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 CPROGISP_ASSDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CPROGISP_ASSDlg::OnOpenButton() 
{
	// TODO: Add your control notification handler code here
	char szDir[MAX_PATH];
    memset(szDir,MAX_PATH,sizeof(char));
	//m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON2);
	//OnPaint();
	m_hIcon=AfxGetApp()->LoadIcon(IDI_ICON2);   
	ASSERT(m_hIcon);   
    AfxGetMainWnd()->SendMessage(WM_SETICON,0,0);//WM_SETICON,TRUE,(LPARAM)m_hIcon);
	/*
	TCHAR   Buffer[512]=_T("");    
	BROWSEINFO bi;
	ITEMIDLIST *pidl;
	g_pFileIni=fopen("PGH.ini","r");
	fread(g_cFullPath,sizeof(char),MAX_PATH,g_pFileIni);
	fclose(g_pFileIni);
	bi.hwndOwner = this->m_hWnd;
	bi.pidlRoot = NULL;
	bi.pszDisplayName =g_cFullPath ;
	bi.lpszTitle = "打开你要下载的文件";
	bi.ulFlags = BIF_DONTGOBELOWDOMAIN|BIF_BROWSEINCLUDEFILES|BIF_EDITBOX|BIF_STATUSTEXT;
	bi.lpfn = NULL;
	bi.lParam = 0;
	bi.iImage = 0;
	pidl = SHBrowseForFolder(&bi);
	if(pidl == NULL) return;
	SHGetPathFromIDList(pidl, szDir);
	m_FileFullPath=szDir;
	m_csInfWnd = szDir;
	UpdateData(false); 
	*/
	 OPENFILENAMEA ofn;            
 
	 ZeroMemory(&ofn, sizeof(ofn));
	 ofn.lStructSize = sizeof(ofn);
	 ofn.hwndOwner = NULL;
	 ofn.lpstrFile = szDir;
	 ofn.lpstrFile[0] = '\0';
	 ofn.nMaxFile = sizeof(szDir);
	 ofn.lpstrFilter = "烧写文件(*.hex,*.bin,*.nb0)\0*.hex;*.bin;*.nb0\0文本文件(*.txt)\0*.txt\0所有文件(*.*)\0*.*\0";
	 ofn.nFilterIndex = 1;
	 ofn.lpstrFileTitle = NULL;
	 ofn.nMaxFileTitle = 0;
	 ofn.lpstrInitialDir = NULL;
	 ofn.Flags = 0;
 
 
	 GetOpenFileNameA(&ofn);
 
	 LPTSTR lpstrPath=ofn.lpstrFile;
	 strcpy(szDir,lpstrPath);
	 m_FileFullPath=lpstrPath;


	SYSTEMTIME sysTime;
	if(GetFileSysTime(szDir,sysTime))
	{
		m_csFileTime.Format(TEXT("YEAR=%d,MONTH=%d,DAY=%d,TIME=%d:%d:%d,"),sysTime.wYear,sysTime.wMonth,sysTime.wDay,sysTime.wHour,sysTime.wMinute,sysTime.wSecond);
		m_sysTimeTemp=m_csFileTime;
		UpdateData(false); 
		m_hDetectFileThread=CreateThread(NULL,0,FileDetectThread,this,0,NULL);
		m_ctDownloadCheck.EnableWindow(TRUE);
		m_bDownloadCheck=TRUE;
		UpdateData(false); 

	}
}

BOOL CPROGISP_ASSDlg::GetFileSysTime(CString FileName,SYSTEMTIME &stime)
{
	
	// 打开文件夹
	HANDLE hFile=CreateFile(FileName,GENERIC_READ,
	FILE_SHARE_READ|FILE_SHARE_DELETE,
	NULL,OPEN_EXISTING,
	FILE_FLAG_BACKUP_SEMANTICS,NULL);
	FILETIME lpCreationTime;//文件创建时间
	FILETIME lpLastAccessTime;//文件最近访问时间
	FILETIME lpLastWriteTime;//文件最近修改时间
	if(GetFileTime(hFile,&lpCreationTime,&lpLastAccessTime,&lpLastWriteTime))
	{
		FILETIME ftime;
		FileTimeToLocalFileTime(&lpLastWriteTime,&ftime);//转换成本地时间
		FileTimeToSystemTime(&ftime,&stime);//转换成系统时间
		CloseHandle(hFile);
		return TRUE;
	}
	else 
	{
		CloseHandle(hFile);
		return FALSE;
	}
	
}

DWORD WINAPI CPROGISP_ASSDlg::FileDetectThread(LPVOID lpParameter)
{
	CPROGISP_ASSDlg *pDlg;
	pDlg=(CPROGISP_ASSDlg*)lpParameter;
	while(1)
	{
		Sleep(500);
		
				pDlg->GetFileSysTime(pDlg->m_FileFullPath,pDlg->m_sysTime);
				pDlg->m_csFileTime.Format(TEXT("YEAR=%d,MONTH=%d,DAY=%d,TIME=%d:%d:%d,"),pDlg->m_sysTime.wYear,pDlg->m_sysTime.wMonth,pDlg->m_sysTime.wDay,pDlg->m_sysTime.wHour,pDlg->m_sysTime.wMinute,pDlg->m_sysTime.wSecond);
				//pDlg->m_ceFileTime.SetWindowText(pDlg->m_csFileTime); 
				if((strcmp(pDlg->m_csFileTime,pDlg->m_sysTimeTemp)!=0))
				{
					if(pDlg->m_bDownloadCheck)
					{
							//pDlg->m_ceFileTime.SetWindowText("File has been changed!");
		 					keybd_event( VK_MENU,
									  0x45,
									  KEYEVENTF_EXTENDEDKEY | 0,
									  0 );
							keybd_event( 0X41,
									  0x45,
									  KEYEVENTF_EXTENDEDKEY | 0,
									  0 );

							keybd_event( VK_MENU,
									  0x45,
									  KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
									  0);
							keybd_event( 0X41,
									  0x45,
									  KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
									  0);

							pDlg->m_sysTimeTemp=pDlg->m_csFileTime;
							int i=0;
							pDlg->SetMyIcon(2);
							for(i=0;i<100;i++)
							{
								Sleep(10);
								pDlg->m_ctDownloadProcess.SetPos(i);
							}
							pDlg->SetMyIcon(1);
							pDlg->m_ctDownloadProcess.SetPos(0);
							//AfxGetMainWnd()->SendMessage();
							//AfxMessageBox("PROGISP下载中");
					}
					else
					{
							pDlg->SetMyIcon(2);
							pDlg->m_sysTimeTemp=pDlg->m_csFileTime;
							pDlg->m_ctDownloadProcess.SetPos(100);
							//pDlg->m_ctDownloadProcess.SSetWindowText("文件变动");
							Sleep(300);
							pDlg->m_ctDownloadProcess.SetPos(0);
							Sleep(300);
							pDlg->m_ctDownloadProcess.SetPos(100);
							Sleep(300);
							pDlg->m_ctDownloadProcess.SetPos(0);
							Sleep(300);
							pDlg->m_ctDownloadProcess.SetPos(100);
							Sleep(300);
							pDlg->m_ctDownloadProcess.SetPos(0);
							pDlg->SetMyIcon(1);
					}
				
				}
				else
				{
					pDlg->m_sysTimeTemp=pDlg->m_csFileTime;
				}
	}
	return FALSE;
}

void CPROGISP_ASSDlg::OnDownloadCheck() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
}


void CPROGISP_ASSDlg::OnTestButton() 
{
	// TODO: Add your control notification handler code here
	SetMyIcon(2);
	//m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON2);
	//SetIcon(m_hIcon,FALSE);
}

BOOL CPROGISP_ASSDlg::SetMyIcon(DWORD dwIcon)
{
	if(dwIcon==1)
	{
		m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
		SetIcon(m_hIcon,FALSE);
	}
	if(dwIcon==2)
	{
		m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON2);
		SetIcon(m_hIcon,FALSE);
	}
			
	
	return TRUE;
}

⌨️ 快捷键说明

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