?? pc_applicationdlg.cpp
字號:
// pc_applicationDlg.cpp : implementation file
//
#include "stdafx.h"
#include "pc_application.h"
#include "pc_applicationDlg.h"
#include "usbdrv.h"
#include "usartdrv.h"
#include "jtagdrv.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()
/////////////////////////////////////////////////////////////////////////////
// CPc_applicationDlg dialog
CPc_applicationDlg::CPc_applicationDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPc_applicationDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPc_applicationDlg)
m_fileName = _T("");
m_target = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_target = _T("USB");
b_configcom1 = FALSE;
b_configcom2 = FALSE;
}
void CPc_applicationDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPc_applicationDlg)
DDX_Text(pDX, IDC_FILENAME, m_fileName);
DDX_CBString(pDX, IDC_TARGETNAME, m_target);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPc_applicationDlg, CDialog)
//{{AFX_MSG_MAP(CPc_applicationDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
ON_BN_CLICKED(ID_EXIT, OnExit)
ON_BN_CLICKED(IDDOWNLOAD, OnDownload)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPc_applicationDlg message handlers
BOOL CPc_applicationDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CPc_applicationDlg::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 CPc_applicationDlg::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 CPc_applicationDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPc_applicationDlg::OnBrowse()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(
true,
NULL,
NULL,
OFN_FILEMUSTEXIST,
_T("Binary files (.bin; .mem)|*.bin;*.mem|")
_T("|")
);
if (IDOK != dlg.DoModal())
return;
m_fileName = dlg.GetPathName();
SetDlgItemText(IDC_FILENAME, m_fileName);
}
void CPc_applicationDlg::OnExit()
{
// TODO: Add your control notification handler code here
EndDialog(1);
}
void CPc_applicationDlg::OnDownload()
{
CFile file;
unsigned int bufferSize;
unsigned int bytesSent;
char *buffer;
char statusMsg[100];
UpdateData();
if (!file.Open(m_fileName, CFile::modeRead)) {
MessageBox("Can not open file", "ERROR", MB_OK);
return;
}
bufferSize = file.GetLength();
buffer = new char[bufferSize];
file.SeekToBegin();
file.Read(buffer, bufferSize);
file.Close();
// TODO: Add your control notification handler code here
if (m_target == _T("USB"))
bytesSent = Usb_Download((BYTE *)buffer, bufferSize);
if (m_target == _T("JTAG"))
bytesSent = Jtag_Download(NULL, buffer, bufferSize);
if (m_target == _T("COM1"))
{
if (!b_configcom1)
if (!ConfigCom1(m_target)) {
delete [] buffer;
return;
}
bytesSent = Usart_Download("COM1", buffer, bufferSize);
}
if (m_target == _T("COM2"))
{
if (!b_configcom2)
if (!ConfigCom2(m_target)) {
delete [] buffer;
return ;
}
bytesSent = Usart_Download("COM2", buffer, bufferSize);
}
if (bytesSent == bufferSize) {
sprintf(statusMsg, "%d bytes have been downloaded successfully", bytesSent);
MessageBox(statusMsg, "Download Succeed", MB_OK);
}
else if (bytesSent) {
sprintf(statusMsg, "Only %d bytes vs. %d bytes have been downloaded", bytesSent, bufferSize);
MessageBox(statusMsg, "Download failed", MB_OK);
}
delete [] buffer;
}
BOOL CPc_applicationDlg::ConfigCom1(CString& target)
{
COMMCONFIG commConfig;
commConfig.dwSize = sizeof(COMMCONFIG);
commConfig.wVersion = 0x100;
if(!CommConfigDialog("COM1",NULL , &commConfig))
{
MessageBox("Unable to configure COM0", "ERROR", MB_OK);
return FALSE;
}
else
b_configcom1 = TRUE;
return TRUE;
}
BOOL CPc_applicationDlg::ConfigCom2(CString& target)
{
COMMCONFIG commConfig;
commConfig.dwSize = sizeof(COMMCONFIG);
commConfig.wVersion = 0x100;
if(!CommConfigDialog("COM2", NULL, &commConfig))
MessageBox("Unable to configure COM1", "ERROR", MB_OK);
else
b_configcom2 = TRUE;
return TRUE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -