?? ewdpingdlg.cpp
字號:
LV_COLUMN lColumn;
lColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
lColumn.fmt = lfmt;
lColumn.cx = lmaxwidth;
lColumn.pszText = ltext;
lColumn.cchTextMax = sizeof (ltext);
lColumn.iSubItem = lsubitem;
int colno = m_TraceList.InsertColumn (lcolumn, &lColumn);
return colno;
}
//////////////////////////////////////////
// //
// Update Trace List Display //
// //
//////////////////////////////////////////
void CEWDPingDlg::UpdateTrace()
{
CString IPAddressMessage;
CString TripTimeMessage;
CString SeqMessage;
CString HostMessage;
if (PingSocket.rcvSockAddr.sin_addr.s_addr == NULL)
{
IPAddressMessage = "***********";
HostMessage.Format("**** No response (TTL = %ld)",
PingSocket.icmpCurSeq);
TripTimeMessage = "*";
}
else
{
TripTimeMessage.Format("%ld",
PingSocket.icmpRoundTripTime);
IPAddressMessage.Format("%s",
inet_ntoa(PingSocket.rcvSockAddr.sin_addr));
HostMessage.Format("%s",
inet_ntoa(PingSocket.rcvSockAddr.sin_addr));
}
SeqMessage.Format ("%ld",
PingSocket.icmpCurSeq);
DisplayTrace (TripTimeMessage,
IPAddressMessage,
HostMessage);
}
//////////////////////////////////////////
// //
// Display Trace //
// //
//////////////////////////////////////////
void CEWDPingDlg::DisplayTrace(LPCSTR TripTimeMessage, LPCSTR IPAddressMessage, LPCSTR HostMessage)
{
int ItemNumber;
ItemNumber = m_TraceList.GetItemCount();
if (ItemNumber > 0)
ItemNumber--;
SetDisplayImage (ItemNumber, Icon_Blank);
m_TraceList.SetItemText(ItemNumber, 1, TripTimeMessage);
m_TraceList.SetItemText(ItemNumber, 2, IPAddressMessage);
m_TraceList.SetItemText(ItemNumber, 3, HostMessage);
}
//////////////////////////////////////////
// //
// Set Display Image //
// //
// Set the selected icon in the //
// trace list box and set the //
// focus to it. //
// //
//////////////////////////////////////////
void CEWDPingDlg::SetDisplayImage(int FocusItem, ImageType FocusImage)
{
LV_ITEM TraceItem;
TraceItem.iItem = FocusItem;
TraceItem.iSubItem = 0;
TraceItem.mask = LVIF_IMAGE;
TraceItem.iImage = FocusImage;
m_TraceList.SetItem (&TraceItem);
}
//////////////////////////////////////////
// //
// Set Trace Focus //
// //
// Set the focus to the TraceList //
// item and exit. //
// //
//////////////////////////////////////////
void CEWDPingDlg::SetTraceFocus(int FocusItem, int FocusSubItem)
{
LV_ITEM TraceItem;
TraceItem.iItem = FocusItem;
TraceItem.iSubItem = FocusSubItem;
TraceItem.mask = LVIF_STATE;
TraceItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
m_TraceList.SetItem (&TraceItem);
m_TraceList.EnsureVisible (FocusItem, FALSE);
}
//////////////////////////////////////////
// //
// Set Trace Sequence //
// //
// Output the current sequence number //
// set focus, and exit. //
// //
//////////////////////////////////////////
void CEWDPingDlg::SetTraceSequence(int Seq, int FocusItem, ImageType FocusImage)
{
CString SeqMessage;
SeqMessage.Format ("%ld", Seq);
m_TraceList.InsertItem (FocusItem, SeqMessage, FocusImage);
SetTraceFocus (FocusItem, 0);
}
//////////////////////////////////////////
// //
// Display Blank Line //
// //
// Display a blank line and exit. //
// //
//////////////////////////////////////////
void CEWDPingDlg::DisplayBlankLine(void)
{
int FocusItem;
FocusItem = m_TraceList.GetItemCount();
if (FocusItem != 0)
{
m_TraceList.InsertItem (FocusItem, " ", Icon_Blank);
SetTraceFocus (FocusItem, 0);
}
}
//////////////////////////////////////////
// //
// Trace Comment //
// //
// Output the comment at the current //
// display line, set focus and exit. //
// //
//////////////////////////////////////////
//插入TRACE信息
void CEWDPingDlg::TraceComment(CString Comment)
{
m_TraceList.InsertItem (m_TraceList.GetItemCount(),
"",
Icon_BlueArrow);
SetTraceFocus (m_TraceList.GetItemCount()-1,
0);
DisplayTrace ("", "", Comment);
}
//////////////////////////////////////////////////////////////////////////
// //
// REGISTRY LOAD AND SAVE SECTION //
// //
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
// //
// Get a raw socket and set message processor //
// Return TRUE if Icmp object allocated //
// //
//////////////////////////////////////////////////////////
//初始化SOCKET
BOOL CEWDPingDlg::InitSockets()
{
if (!PingSocket.OpenNewSocket(GetSafeHwnd(),
WSA_PING_ASYNC,
FD_READ | FD_WRITE,
AF_INET,
SOCK_RAW,
IPPROTO_ICMP))
{
PingSocket.DisplayError ("WSA_PING_ASYNC",
"CEWDPingDlg::InitSockets");
return FALSE;
}
return TRUE;
}
//////////////////////////////////////////////////////////
// //
// Get Windows Winsock settings from Registry //
// //
//////////////////////////////////////////////////////////
BOOL CEWDPingDlg::FetchWinsockSettings()
{
SysTCPIP STcpIp;
if (!STcpIp.WinsockVersion(&wsaData))
{
MessageBox ("No valid winsock.dll detected",
"CEWDPingDlg::OnInitDialog",
MB_OK|MB_SYSTEMMODAL);
return FALSE;
}
if (!STcpIp.GetLocalHostName (&m_LocalHost))
{
gethostname(CurrentHostName, MAXHOSTNAME);
}
else
{
memcpy (CurrentHostName, m_LocalHost, m_LocalHost.GetLength());
CurrentHostName[m_LocalHost.GetLength()] = 0;
}
m_LocalHost = CurrentHostName;
if (!STcpIp.GetDomainName(&LocalDomainName))
LocalDomainName = "";
m_LocalHost += "." + LocalDomainName;
memcpy (CurrentHostName, m_LocalHost, m_LocalHost.GetLength());
CurrentHostName[m_LocalHost.GetLength()] = 0;
if (!STcpIp.GetNSName (&LocalNameServer))
LocalNameServer = "";
m_NameServer = "Name Server: " + LocalNameServer;
SetDlgItemText (IDC_LocalHost, m_LocalHost);
SetDlgItemText (IDC_NameServer, m_NameServer);
LoadRegValues();
SetDlgItemText (IDC_DEST, HostName);
return TRUE;
}
//////////////////////////////////////////
// //
// Load operating options //
// //
//////////////////////////////////////////
BOOL CEWDPingDlg::LoadRegValues(void)
{
RegKey hKey;
DWORD dwType;
icmpDataLen = 64;
memcpy (HostName, CurrentHostName, MAXHOSTNAME);
PingSocket.icmpPingTimer = 3000;
PingSocket.icmpMaxHops = 30;
if (!hKey.GetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"BufferSize",
&icmpDataLen,
&dwType))
{
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"BufferSize",
icmpDataLen,
REG_DWORD))
{
MessageBox ("Unable to access registry entry for ""BufferSize""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
return FALSE;
}
}
if (!hKey.GetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"PingTimeout",
&PingSocket.icmpPingTimer,
&dwType))
{
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"PingTimeout",
PingSocket.icmpPingTimer,
REG_DWORD))
{
MessageBox ("Unable to access registry entry for ""PingTimeout""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
return FALSE;
}
}
if (!hKey.GetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"MaxHops",
&PingSocket.icmpMaxHops,
&dwType))
{
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"MaxHops",
PingSocket.icmpMaxHops,
REG_DWORD))
{
MessageBox ("Unable to access registry entry for ""MaxHops""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
return FALSE;
}
}
if (!hKey.GetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"DefaultHost",
&DefHost,
&dwType))
{
DefHost = HostName;
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"DefaultHost",
HostName,
REG_SZ))
{
MessageBox ("Unable to access registry entry for ""DefaultHost""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
return FALSE;
}
}
memcpy (HostName, DefHost, DefHost.GetLength());
HostName[DefHost.GetLength()] = 0;
return TRUE;
} // End LoadRegValues
//////////////////////////////////////////////
// //
// Save updated operating options //
// //
//////////////////////////////////////////////
void CEWDPingDlg::SaveRegValues()
{
RegKey hKey;
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"BufferSize",
icmpDataLen,
REG_DWORD))
{
MessageBox ("Unable to access registry entry for ""BufferSize""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
}
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"PingTimeout",
PingSocket.icmpPingTimer,
REG_DWORD))
{
MessageBox ("Unable to access registry entry for ""PingTimeout""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
}
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"MaxHops",
PingSocket.icmpMaxHops,
REG_DWORD))
{
MessageBox ("Unable to access registry entry for ""MaxHops""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
}
if (!hKey.SetRegistryValue(HKEY_CURRENT_USER,
"SOFTWARE\\EarthWalk Designs\\EWDPing",
"DefaultHost",
DefHost,
REG_SZ))
{
MessageBox ("Unable to access registry entry for ""DefaultHost""",
"Registry Access Error",
MB_OK|MB_SYSTEMMODAL);
}
} // End SaveRegValues
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -