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

📄 netfinderdlg.cpp

📁 F340+CP2200的汉化版NETFINDER源代码,增加了串口设置
💻 CPP
字号:
// netfinderDlg.cpp : implementation file
//

#include "stdafx.h"
#include "netfinder.h"
#include "netfinderDlg.h"
#include "PortConfigDlg.h"

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


extern CNetfinderApp theApp;

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

/////////////////////////////////////////////////////////////////////////////
// CNetfinderDlg dialog

CNetfinderDlg::CNetfinderDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNetfinderDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNetfinderDlg)
	m_sortby_selected = -1;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_SILABS_LOGO);
}

void CNetfinderDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNetfinderDlg)
	DDX_Control(pDX, IDC_SORTBY, m_sortby_combo);
	DDX_Control(pDX, IDC_SHOWEV2, m_check_ev2);
	DDX_Control(pDX, IDC_SHOWEV1, m_checkbox_ev1);
	DDX_CBIndex(pDX, IDC_SORTBY, m_sortby_selected);
		DDX_Control(pDX, IDC_CUSTOM1, m_netdisplay);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CNetfinderDlg, CDialog)
	//{{AFX_MSG_MAP(CNetfinderDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_ADD_ENTRY, OnAddEntry)
	ON_BN_CLICKED(IDC_CLEAR_ALL, OnClearAll)
	ON_BN_CLICKED(IDC_SEARCH, OnSearch)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_SHOWMACADDR, OnShowmacaddr)
	ON_BN_CLICKED(IDC_SHOWEV1, OnShowev1)
	ON_BN_CLICKED(IDC_SHOWEV2, OnShowev2)
	ON_CBN_SELCHANGE(IDC_SORTBY, OnSelchangeSortby)
	ON_BN_CLICKED(IDC_CONFIGPORTS, OnConfigports)
	ON_BN_CLICKED(IDC_ASSIGN, OnAssign)
	ON_BN_CLICKED(IDC_LAUNCH_BROWSER, OnLaunchBrowser)
	ON_BN_CLICKED(IDC_LAUNCH_BROWSER2, OnLaunchBootload)
	ON_BN_CLICKED(IDC_LAUNCH_HYPERTERM, OnLaunchHyperterm)
	ON_BN_CLICKED(IDC_UART, OnUart)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNetfinderDlg message handlers

BOOL CNetfinderDlg::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
	//-----------------------------------------------------------------------
	
	// Add pointer to this dialog to <theApp> to provide global access
	theApp.pMainDlg = this;

	// Initialize the netdisplay (Select Visible Fields)
	m_netdisplay.Init();
	m_netdisplay.m_mac_visible = 0;
	CheckDlgButton(IDC_SHOWMACADDR, m_netdisplay.m_mac_visible);
	m_netdisplay.m_ev1_visible = 1;
	CheckDlgButton(IDC_SHOWEV1, m_netdisplay.m_ev1_visible);
	m_netdisplay.m_ev2_visible = 1;
	CheckDlgButton(IDC_SHOWEV2, m_netdisplay.m_ev2_visible);
	m_netdisplay.Refresh();
	
	// Initialize the Sort By List and Sort Type
	m_sortby_selected = 3;	// Unsorted
	m_netdisplay.m_sortmethod = m_sortby_selected;
	UpdateData(FALSE);

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

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

void CNetfinderDlg::OnAddEntry() 
{
	// TODO: Add your control notification handler code here
	
	static unsigned char color = 0;

	color++;
	if(color == 0x03) color = 0xFF;
	
	NETDISPLAY_ENTRY entry;
	
	entry.alert_level = color;

	entry.event1_days = 5;
	entry.event1_hours = 20;
	entry.event1_minutes = 15;
	entry.event1_seconds = 21;

	entry.event2_days = 1;
	entry.event2_hours = 0;
	entry.event2_minutes = 0;
	entry.event2_seconds = 3;

	entry.mac[0] = 25;
	entry.mac[1] = 25;
	entry.mac[2] = 25;
	entry.mac[3] = 25;
	entry.mac[4] = 25;
	entry.mac[5] = 25;

	entry.ip[0] = 25;
	entry.ip[1] = 25;
	entry.ip[2] = 255;
	entry.ip[3] = 25;

	entry.subnet[0] = 25;
	entry.subnet[1] = 25;
	entry.subnet[2] = 255;
	entry.subnet[3] = 25;

	entry.gateway[0] = 25;
	entry.gateway[1] = 25;
	entry.gateway[2] = 255;
	entry.gateway[3] = 25;

	entry.str_type = "Unknown Device";
	entry.str_description = "Unknown Description";
	entry.str_ev1 = "Event1:";
	entry.str_ev2 = "Event2:";
	m_netdisplay.AddEntry(&entry);

}

void CNetfinderDlg::OnClearAll() 
{
	// TODO: Add your control notification handler code here
	m_netdisplay.RemoveAllEntries();
}

void CNetfinderDlg::OnSearch() 
{	
	CSearchDlg dlg;
	
	m_netdisplay.RemoveAllEntries();

	dlg.DoModal();
	
}

void CNetfinderDlg::ReceivePacket()
{
	

}

void CNetfinderDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnClose();
}

void CNetfinderDlg::OnShowmacaddr() 
{
	// TODO: Add your control notification handler code here
	if(IsDlgButtonChecked(IDC_SHOWMACADDR)){
		m_netdisplay.m_mac_visible = 1;	
	} else {
		m_netdisplay.m_mac_visible = 0;
	}

	// Refresh netdiplay
	m_netdisplay.Refresh();
}

void CNetfinderDlg::OnShowev1() 
{
	// TODO: Add your control notification handler code here
	if(IsDlgButtonChecked(IDC_SHOWEV1)){
		m_netdisplay.m_ev1_visible = 1;	
	} else {
		m_netdisplay.m_ev1_visible = 0;
	}

	// Refresh netdiplay
	m_netdisplay.Refresh();	
}

void CNetfinderDlg::OnShowev2() 
{
	// TODO: Add your control notification handler code here
	if(IsDlgButtonChecked(IDC_SHOWEV2)){
		m_netdisplay.m_ev2_visible = 1;	
	} else {
		m_netdisplay.m_ev2_visible = 0;
	}

	// Refresh netdiplay
	m_netdisplay.Refresh();	
}

void CNetfinderDlg::OnSelchangeSortby() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_netdisplay.m_sortmethod = m_sortby_selected;
	m_netdisplay.Refresh();
}

void CNetfinderDlg::OnConfigports() 
{
	// TODO: Add your control notification handler code here
	CPortConfigDlg pc_dlg;
	pc_dlg.DoModal();
}

//DEL void CNetfinderDlg::OnTest() 
//DEL {
//DEL 	// TODO: Add your control notification handler code here
//DEL 
//DEL }

void CNetfinderDlg::OnAssign() 
{
	// TODO: Add your control notification handler code here
	if(theApp.pMainDlg->m_netdisplay.IsCellSelected()){

		CAssignDlg dlg;
        dlg.DoModal();
	    AfxMessageBox("请重新搜索!");
		
		
	}else {

		AfxMessageBox("请首先选择一个嵌入装置.");
	}
}

void CNetfinderDlg::OnLaunchBrowser() 
{
	
	// TODO: Add your control notification handler code here
	if(theApp.pMainDlg->m_netdisplay.IsCellSelected()){
		
		unsigned char IP[4];
		CString cmd_line;
		
		// Fill IP Address
		m_netdisplay.GetIPAddress(IP);
		
		// Fill Command Line
		cmd_line.Format("explorer http://%d.%d.%d.%d/", (unsigned int) IP[0], (unsigned int) IP[1], (unsigned int) IP[2], (unsigned int) IP[3]);

		WinExec(cmd_line, SW_HIDE);

	} else {

		AfxMessageBox("请首先选择一个嵌入装置.");
	}
}


void CNetfinderDlg::OnLaunchBootload() 
{
	// TODO: Add your control notification handler code here
	if(theApp.pMainDlg->m_netdisplay.IsCellSelected()){
		
		unsigned char IP[4];
		CString cmd_line;
		
		// Fill IP Address
		m_netdisplay.GetIPAddress(IP);
		
		//-------------------------------------------------------------------------
		// Prompt for input IMG file
		//-------------------------------------------------------------------------
		CString input_file_name;
		CString drive;
		int i;

		CFileDialog fd(	true,		// file open
						NULL,
						NULL, 
						OFN_HIDEREADONLY  | OFN_OVERWRITEPROMPT | 
						OFN_FILEMUSTEXIST | OFN_ENABLESIZING
					  );
		fd.m_ofn.lpstrTitle = "Browse for Input IMG File...";
		fd.m_ofn.lpstrFilter = "IMG Files\0*.img;\0All Files\0*.*\0";
		int ret = fd.DoModal();
		
		if(ret == IDOK){

			input_file_name = fd.GetPathName();	
			this->UpdateData(FALSE); // False to initialize
		} else {	
			return;						// user pressed cancel
		}
		

		// Get the current drive;
		drive = input_file_name;
		i = drive.Find(":", 0);
		drive = drive.Mid(0, i+1);
		

		// Fill Command Line
		cmd_line.Format("CMD /K ECHO Starting TFTP Bootloader... && ECHO Please wait 10 - 15 seconds for firmware update to complete... && %s && tftp -i %d.%d.%d.%d PUT \"%s\" boot.img", drive, (unsigned int) IP[0], (unsigned int) IP[1], (unsigned int) IP[2], (unsigned int) IP[3], input_file_name);

		WinExec(cmd_line, SW_SHOW);

	} else {

		AfxMessageBox("请首先选择一个嵌入装置.");
	}
}

void CNetfinderDlg::OnLaunchHyperterm() 
{
	// TODO: Add your control notification handler code here
	if(theApp.pMainDlg->m_netdisplay.IsCellSelected()){
		
		unsigned char IP[4];
		CString cmd_line;
		
		// Fill IP Address
		m_netdisplay.GetIPAddress(IP);
		
		// Fill Command Line
		cmd_line.Format("explorer telnet://%i.%i.%i.%i", (unsigned int) IP[0], (unsigned int) IP[1], (unsigned int) IP[2], (unsigned int) IP[3]);

		WinExec(cmd_line, SW_SHOW);

	} else {

		AfxMessageBox("请首先选择一个嵌入装置.");
	}
	
}

void CNetfinderDlg::OnUart() 
{
	// TODO: Add your control notification handler code here
	if(theApp.pMainDlg->m_netdisplay.IsCellSelected()){

		CUartConfigDlg dlg;
		dlg.DoModal();
	}else {

		AfxMessageBox("请首先选择一个嵌入装置.");
	}
}

⌨️ 快捷键说明

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