📄 armupdatedlg.cpp
字号:
// ARMUpdateDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ARMUpdate.h"
#include "ARMUpdateDlg.h"
#include "DlgProxy.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()
/////////////////////////////////////////////////////////////////////////////
// CARMUpdateDlg dialog
IMPLEMENT_DYNAMIC(CARMUpdateDlg, CDialog);
CARMUpdateDlg::CARMUpdateDlg(CWnd* pParent /*=NULL*/)
: CDialog(CARMUpdateDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CARMUpdateDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pAutoProxy = NULL;
isAddrShow=true;
isStringShow=true;
m_NKThread=m_BootLoadThread=NULL;
}
CARMUpdateDlg::~CARMUpdateDlg()
{
// If there is an automation proxy for this dialog, set
// its back pointer to this dialog to NULL, so it knows
// the dialog has been deleted.
if (m_pAutoProxy != NULL)
m_pAutoProxy->m_pDialog = NULL;
TerminateThread(m_hThread,0);
if(m_hThread)CloseHandle(m_hThread);
}
void CARMUpdateDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CARMUpdateDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_Prograss);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CARMUpdateDlg, CDialog)
//{{AFX_MSG_MAP(CARMUpdateDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CLOSE()
ON_WM_SIZE()
ON_COMMAND(ID_MENU_COMSETUP, OnMenuComsetup)
ON_COMMAND(ID_MENU_FTPSETUP, OnMenuFtpsetup)
ON_COMMAND(ID_MENU_BINTOHEX, OnMenuBintohex)
ON_COMMAND(ID_MENU_SHOWADDR, OnMenuShowaddr)
ON_COMMAND(ID_MENU_SHOWSTRING, OnMenuShowstring)
ON_COMMAND(ID_MENU_BOOTLOADUPDATE, OnMenuBootloadupdate)
ON_COMMAND(ID_MENU_NKUPDATE, OnMenuNkupdate)
ON_COMMAND(ID_MENU_UPDATECANCEL, OnMenuUpdatecancel)
ON_COMMAND(ID_MENU_EXIT, OnMenuExit)
ON_COMMAND(ID_MENU_ABOUT, OnMenuAbout)
ON_WM_DESTROY()
ON_COMMAND(ID_MENU_SAVENB0, OnMenuSavenb0)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CARMUpdateDlg message handlers
static UINT indicators[] =
{
// ID_SEPARATOR, // status line indicator
ID_INDICATOR_CLOCK,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
ULONG __stdcall ComPro(void * param1)
{
HANDLE handle=(HANDLE)param1;
DWORD lpErrors,wlen;
COMSTAT comstat;
char *ReciBuf;
char *buf;
ULONG i,j;
CRichEditCtrl *p=(CRichEditCtrl *)AfxGetApp()->m_pMainWnd->GetDlgItem(IDC_CHARWINDWS);
while(1)
{
ClearCommError(handle,&lpErrors,&comstat);
if(comstat.cbInQue>0)
{
ReciBuf=(char *)malloc(comstat.cbInQue);
buf=(char *)malloc(comstat.cbInQue+1);
memset(buf,0,comstat.cbInQue+1);
if(ReadFile(handle,ReciBuf,comstat.cbInQue,&wlen,NULL))
{
for(i=0,j=0;i<wlen;i++)
{
if(ReciBuf[i]>0 && ReciBuf[i] <='z')
{
if(ReciBuf[i]=='\b')
{ CHARRANGE cr;
p->GetSel(cr);
if(cr.cpMax)
{ p->SetSel(cr.cpMax-1,-1);
p->ReplaceSel(NULL);
}
if(j)
j--;
continue;
}
buf[j++]=ReciBuf[i];
//j++;
}
else
continue;
}
buf[j]=0;
p->SetSel(-1,-1);
p->ReplaceSel(buf);
}
free(ReciBuf);
free(buf);
}
Sleep(10);
}
ExitThread(0);
return 0;
}
BOOL CARMUpdateDlg::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
StatusBar.Create(this);
StatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT));
StatusBar.SetPaneInfo(StatusBar.CommandToIndex(ID_INDICATOR_CLOCK),ID_INDICATOR_CLOCK,SBPS_NORMAL,125);
StatusBar.SetPaneInfo(StatusBar.CommandToIndex(ID_INDICATOR_CAPS),ID_INDICATOR_CAPS,SBPS_NORMAL,125);
StatusBar.SetPaneInfo(StatusBar.CommandToIndex(ID_INDICATOR_NUM),ID_INDICATOR_NUM,SBPS_NORMAL,125);
StatusBar.SetPaneInfo(StatusBar.CommandToIndex(ID_INDICATOR_SCRL),ID_INDICATOR_SCRL,SBPS_NORMAL,125);
CRect rt;
rt.SetRect(0,0,100,100);
RichEdit.Create(ES_MULTILINE|ES_AUTOVSCROLL|WS_VSCROLL|WS_HSCROLL|ES_AUTOHSCROLL ,rt,this,IDC_CHARWINDWS);
RichEdit.ShowWindow(SW_SHOWNORMAL);
CFont font;
font.CreatePointFont(9,"Fixedsys");
RichEdit.SetFont(&font,TRUE);
RichEdit.SetBackgroundColor(0,GetSysColor(COLOR_BTNFACE));
GetClientRect(&rt);
rt.top=rt.bottom-20;
StatusBar.MoveWindow(rt);
m_Prograss.SetParent(&StatusBar);
m_Prograss.SetRange(0,100);
CRichEditCtrl *p=(CRichEditCtrl *)GetDlgItem(IDC_CHARWINDWS);
p->SetEventMask(ENM_CHANGE|ENM_UPDATE);
// TODO: Add extra initialization here
this->SetWindowPos(&wndTop,0,0,640,480,SWP_NOMOVE);
ReSetupCom();
return TRUE; // return TRUE unless you set the focus to a control
}
void CARMUpdateDlg::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 CARMUpdateDlg::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 CARMUpdateDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
// Automation servers should not exit when a user closes the UI
// if a controller still holds on to one of its objects. These
// message handlers make sure that if the proxy is still in use,
// then the UI is hidden but the dialog remains around if it
// is dismissed.
void CARMUpdateDlg::OnClose()
{
if (CanExit())
CDialog::OnClose();
}
void CARMUpdateDlg::OnOK()
{
if (CanExit())
CDialog::OnOK();
}
void CARMUpdateDlg::OnCancel()
{
if (CanExit())
CDialog::OnCancel();
}
BOOL CARMUpdateDlg::CanExit()
{
// If the proxy object is still around, then the automation
// controller is still holding on to this application. Leave
// the dialog around, but hide its UI.
if (m_pAutoProxy != NULL)
{
ShowWindow(SW_HIDE);
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -