return TRUE; // return TRUE unless you set the focus to a control }// 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 CServerDlg::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 CServerDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; }BOOL CServerDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if (pMsg->message == WM_KEYDOWN) { if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE) return TRUE; }
if(nFailNum >= 3) { strSql.Format("delete from list where id = %ld", nid); } else { strSql.Format("update list set FailNum = %ld, FailTime = %ld where id = %ld", nFailNum+1, CTime::GetCurrentTime().GetTime(), nid); } pConnection->Execute((_bstr_t)strSql, NULL, adCmdText); pConnection->Close();
if(nFailNum >= 3) { strSql.Format("delete from list where id = %ld", nid); } else { strSql.Format("update list set FailNum = %ld, FailTime = %ld where id = %ld", nFailNum+1, CTime::GetCurrentTime().GetTime(), nid); } pConnection->Execute((_bstr_t)strSql, NULL, adCmdText); pConnection->Close();
代码如下:(serverDlg.cpp)
// ServerDlg.cpp : implementation file
//#include "stdafx.h"
#include "Server.h"
#include "ServerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MINSPACE ((unsigned long)3*1024*1024*1024)
#define SRV_PORT 5538 //与各个车站通讯的监听端口
#define SqlSrv_Ip "127.0.0.1" //服务器本地IP
#define FileOperation_PORT 6532#include "imagehlp.h"
#pragma comment(lib, "imagehlp.lib")
#define WM_NOTIFYICON WM_USER+188
#include "include\server.h"/////////////////////////////////////////////////////////////////////////////
// CServerDlg dialogint CALLBACK NotifyANewConnection(bool badd,const char* clientip,unsigned short port, const char* url)
{
return 0;
}
CServerDlg::CServerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CServerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CServerDlg)
// 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_sockSrv = NULL;
m_bStarted = FALSE;
m_hThread[0] = m_hThread[1] = 0; m_sockFileOperation = NULL;
}void CServerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CServerDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CServerDlg, CDialog)
//{{AFX_MSG_MAP(CServerDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CLOSE()
ON_WM_SYSCOMMAND()
ON_MESSAGE(WM_NOTIFYICON,OnIconNotify)
ON_COMMAND(ID_EXIT, OnExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CServerDlg message handlersBOOL CServerDlg::OnInitDialog() //初始化函数
{
CDialog::OnInitDialog(); // 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 PostMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
TaskBarAddIcon();
///----------------------------------------------------------------------------------
m_sockSrv = socket(AF_INET,SOCK_STREAM,0);//建立socket,TCP/IP协议族
if(m_sockSrv==INVALID_SOCKET)
{
MessageBox("与车站通讯的监听套接字创建失败!","错误",MB_ICONERROR|MB_OK);
m_sockSrv = NULL;
SendMessage(WM_CLOSE);
return TRUE;
}
SOCKADDR_IN srvAddr; //定义的结构
srvAddr.sin_family = AF_INET;//地址族地址顺序
srvAddr.sin_addr.s_addr = INADDR_ANY;//本机IP地址
srvAddr.sin_port = htons(SRV_PORT);//端口号
if( bind(m_sockSrv,(sockaddr*)&srvAddr,sizeof(srvAddr))==SOCKET_ERROR)
{
MessageBox("与车站通讯的套接字绑定失败!","错误",MB_ICONERROR|MB_OK);
closesocket(m_sockSrv);
m_sockSrv = NULL;
SendMessage(WM_CLOSE);
return TRUE;
} if(listen(m_sockSrv,SOMAXCONN)==SOCKET_ERROR)
{
MessageBox("与车站通讯的套接字监听失败!","错误",MB_ICONERROR|MB_OK);
closesocket(m_sockSrv);
m_sockSrv = NULL;
SendMessage(WM_CLOSE);
return TRUE;
} m_bStarted = TRUE;
AfxBeginThread(SrvThread,this);
///-----------------------------------------------------------------------------------
m_sockFileOperation = socket(AF_INET,SOCK_STREAM,0);//建立socket文件操作
if(m_sockFileOperation==INVALID_SOCKET)
{
MessageBox("用于文件操作的监听套接字创建失败!","错误",MB_ICONERROR|MB_OK);
m_sockFileOperation = NULL;
SendMessage(WM_CLOSE);
return TRUE;
}
SOCKADDR_IN addr;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = htons(FileOperation_PORT);
if( bind(m_sockFileOperation,(sockaddr*)&addr,sizeof(addr))==SOCKET_ERROR)
{
MessageBox("用于文件操作的套接字绑定失败!","错误",MB_ICONERROR|MB_OK);
closesocket(m_sockFileOperation);
m_sockFileOperation = NULL;
SendMessage(WM_CLOSE);
return TRUE;
} if(listen(m_sockFileOperation,SOMAXCONN)==SOCKET_ERROR)
{
MessageBox("用于文件操作的套接字监听失败!","错误",MB_ICONERROR|MB_OK);
closesocket(m_sockFileOperation);
m_sockFileOperation = NULL;
SendMessage(WM_CLOSE);
return TRUE;
} AfxBeginThread(FileOperationThread, this);
///---------------------------------------------------------------------------------- Sleep(100);
GetDiskDrivers();
m_cCurrentRecordDriver = m_cHardDriver[1];
CWinThread* pThread = AfxBeginThread(CheckDiskSpaceThread,this);
m_hThread[0] = pThread->m_hThread; Sleep(100);
pThread = AfxBeginThread(GetRecordThread,this);
m_hThread[1] = pThread->m_hThread;
//-------------------------------------------------------------------------------------
SetNewConnectionCallBack(NotifyANewConnection);
StartServer("");
RunServer();
return TRUE; // return TRUE unless you set the focus to a control
}// 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 CServerDlg::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 CServerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}BOOL CServerDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}void CServerDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
m_bStarted = FALSE;
if(m_sockSrv)
{
closesocket(m_sockSrv);
m_sockSrv = NULL;
}
if(m_sockFileOperation)
{
closesocket(m_sockFileOperation);
m_sockFileOperation = NULL;
}
StopServer(); AfxBeginThread(WaitStopThread,this);
m_WaitDlg.DoModal(); TaskBarDelIcon();
CDialog::OnClose();
}
UINT CServerDlg::SrvThread(LPVOID pParam)//接收车务段电脑的连接请求
{
CServerDlg* pDlg = (CServerDlg*)pParam;
sockaddr_in ClientSockAddr;
int nClientSockAddrLen = sizeof(ClientSockAddr);
SOCKET NewServSock;
NewServSock = accept(pDlg->m_sockSrv, (sockaddr*)&ClientSockAddr, &nClientSockAddrLen);
if( NewServSock ==INVALID_SOCKET)
{
return 1;
}
AfxBeginThread(SrvThread, pParam); SocketData data;
memset(&data, 0, sizeof(data));
int nRecv = recv(NewServSock, (char*)&data, sizeof(data), 0);
if(nRecv>0) //成功接收数据
{
AfxOleInit();
HRESULT hr;
_ConnectionPtr pConnection;
try
{
hr = pConnection.CreateInstance("ADODB.Connection"); //创建Connection对象
if(SUCCEEDED(hr))
{
pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data;","","",adModeUnknown); //连接数据库
}
}
catch(_com_error &e) //捕捉异常
{
closesocket(NewServSock);
return 2;
} CString strSql;
strSql.Format("insert into list (AddrCode,CxCode,Path,ip) values (%ld,%ld,'%s','%s')",
data.nAddrCode, data.nCxCode, data.szFirstRecPath, inet_ntoa(ClientSockAddr.sin_addr));
_variant_t vt;
pDlg->m_cs.Lock();
pConnection->Execute((_bstr_t)strSql, &vt, adCmdText); //添加记录
pDlg->m_cs.Unlock();
pConnection->Close();
} closesocket(NewServSock);
return 0;
}
UINT CServerDlg::GetRecordThread(LPVOID pParam)
{
CServerDlg* pDlg = (CServerDlg*)pParam; AfxOleInit();
while(pDlg->m_bStarted)
{
HRESULT hr;
_ConnectionPtr pConnection;
try
{
hr = pConnection.CreateInstance("ADODB.Connection");
if(SUCCEEDED(hr))
{
pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data;","","",adModeUnknown); //连接数据库
}
}
catch(_com_error &e) //捕捉异常
{
Sleep(20000);
continue;
} CString strSql;
strSql.Format("select top 1 * from list where FailNum<3 or (FailNum>=3 and FailTime<%ld) order by id",
CTime::GetCurrentTime().GetTime() - 1800 ); _RecordsetPtr pRecordset;
pRecordset.CreateInstance("ADODB.Recordset"); pDlg->m_cs.Lock();
pRecordset = pConnection->Execute((_bstr_t)strSql, NULL, adCmdText); //读记录
if(pRecordset->adoEOF)
{
pRecordset->Close();
pDlg->m_cs.Unlock();
pConnection->Close();
Sleep(20000);
continue;
} long nid = pRecordset->GetCollect("id").lVal;
long nAddrCode = pRecordset->GetCollect("AddrCode").lVal;
long nCxCode = pRecordset->GetCollect("CxCode").lVal;
CString strPath = (char*)_bstr_t(pRecordset->GetCollect("Path"));
CString strIp = (char*)_bstr_t(pRecordset->GetCollect("ip"));
long nFailNum = pRecordset->GetCollect("FailNum").lVal;
pRecordset->Close(); //关闭记录集
pDlg->m_cs.Unlock();
//////////下载录像文件/////////////////////////////////////////////////////////////////
CFtpConnection *psMyCFtpConnection = NULL;
CInternetSession *psMyCInternetSession = NULL;
psMyCInternetSession = new CInternetSession();
psMyCInternetSession->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,5000);
psMyCInternetSession->SetOption(INTERNET_OPTION_CONNECT_BACKOFF,1000);
psMyCInternetSession->SetOption(INTERNET_OPTION_CONNECT_RETRIES,1); //重试次数
try
{
psMyCFtpConnection = psMyCInternetSession->GetFtpConnection(strIp); //建立FTP连接
}
catch (CInternetException* e)
{
#ifdef _DEBUG
TCHAR szError[1024];
if(e->GetErrorMessage(szError,1024))
::MessageBox(NULL, szError, "错误", MB_OK|MB_ICONERROR);
else
{
CString STR;
STR.Format("未连接上FTP服务器:%s,请确认网络是否连通", strIp);
::MessageBox(NULL, STR, "错误", MB_OK|MB_ICONERROR);
}
#endif e->Delete(); psMyCFtpConnection = NULL;
psMyCInternetSession->Close();
delete psMyCInternetSession;
psMyCInternetSession = NULL;
if(nFailNum >= 3)
{
strSql.Format("delete from list where id = %ld", nid);
}
else
{
strSql.Format("update list set FailNum = %ld, FailTime = %ld where id = %ld",
nFailNum+1, CTime::GetCurrentTime().GetTime(), nid);
}
pConnection->Execute((_bstr_t)strSql, NULL, adCmdText);
pConnection->Close();
Sleep(20000);
continue;
}
CString strRomoteFile00 = strPath.Mid(3);
CString strFileName00 = strPath.Right(28);
CString strRecDate = strFileName00.Mid(10, 8);
CString strRecTime = strFileName00.Mid(18, 6);
char cRecordDriver = pDlg->m_cCurrentRecordDriver;
CString strSaveDir;
strSaveDir.Format("%c:\\Record_%c\\%s\\%s\\%ld_%ld\\", cRecordDriver, cRecordDriver, strRecDate, strRecTime, nAddrCode, nCxCode);
MakeSureDirectoryPathExists(strSaveDir); //创建目录
CString strLocalFile00 = strSaveDir+strFileName00;
strRomoteFile00.MakeLower();//变为小写
strLocalFile00.MakeLower();
if(psMyCFtpConnection->GetFile(strRomoteFile00, strLocalFile00, FALSE)==0)
{
#ifdef _DEBUG
CString STR;
//STR.SetParent(this);
STR.Format("下载FTP服务器(%s)上的文件 %s 失败", strIp, strRomoteFile00);
::MessageBox(NULL, STR, "错误", MB_OK|MB_ICONERROR);
//m_MsgBox.MessageBox("2秒关闭。","错误",2000,MB_OK|MB_ICONINFORMATION);
// HWND shwnd = ::FindWindow(NULL,"错误");
// if(shwnd)
// {
// ::PostMessage(shwnd, WM_COMMAND, IDOK, 0); //点击“确定”
// }
#endif
psMyCFtpConnection->Close();
delete psMyCFtpConnection;
psMyCFtpConnection = NULL;
psMyCInternetSession->Close();
delete psMyCInternetSession;
psMyCInternetSession = NULL;
if(nFailNum >= 3)
{
strSql.Format("delete from list where id = %ld", nid);
}
else
{
strSql.Format("update list set FailNum = %ld, FailTime = %ld where id = %ld",
nFailNum+1, CTime::GetCurrentTime().GetTime(), nid);
}
pConnection->Execute((_bstr_t)strSql, NULL, adCmdText);
pConnection->Close();
Sleep(20000);
continue;
}
CString strRomoteFile01 = strRomoteFile00;
CString strLocalFile01 = strLocalFile00;
strRomoteFile01.Replace("channel00","channel01");
strLocalFile01.Replace("channel00","channel01");
psMyCFtpConnection->GetFile(strRomoteFile01, strLocalFile01, FALSE); CString strRomoteFile02 = strRomoteFile00;
CString strLocalFile02 = strLocalFile00;
strRomoteFile02.Replace("channel00","channel02");
strLocalFile02.Replace("channel00","channel02");
psMyCFtpConnection->GetFile(strRomoteFile02, strLocalFile02, FALSE);
CString strRomoteFile03 = strRomoteFile00;
CString strLocalFile03 = strLocalFile00;
strRomoteFile03.Replace("channel00","channel03");
strLocalFile03.Replace("channel00","channel03");
psMyCFtpConnection->GetFile(strRomoteFile03, strLocalFile03, FALSE);
CString strRomoteFile04 = strRomoteFile00;
CString strLocalFile04 = strLocalFile00;
strRomoteFile04.Replace("channel00","channel04");
strLocalFile04.Replace("channel00","channel04");
psMyCFtpConnection->GetFile(strRomoteFile04, strLocalFile04, FALSE); CString strRomoteFile05 = strRomoteFile00;
CString strLocalFile05 = strLocalFile00;
strRomoteFile05.Replace("channel00","channel05");
strLocalFile05.Replace("channel00","channel05");
psMyCFtpConnection->GetFile(strRomoteFile05, strLocalFile05, FALSE);
int nLength = strRomoteFile00.GetLength();
CString strTempPath = strRomoteFile00.Left(nLength-34);
CString strRomoteCheHao = strTempPath+"TrainCheHao.dat";//客户端的车号
CString strLocalCheHao = strSaveDir+"TrainCheHao.dat"; //本地车号
psMyCFtpConnection->GetFile(strRomoteCheHao, strLocalCheHao, FALSE); psMyCFtpConnection->Close();
delete psMyCFtpConnection;
psMyCFtpConnection = NULL;
psMyCInternetSession->Close();
delete psMyCInternetSession;
psMyCInternetSession = NULL; strSql.Format("delete from list where id = %ld", nid);
pConnection->Execute((_bstr_t)strSql, NULL, adCmdText);
pConnection->Close();
VodCreateIndex(strLocalFile00.GetBuffer(0), strLocalFile00.GetLength());
VodCreateIndex(strLocalFile01.GetBuffer(0), strLocalFile01.GetLength());
VodCreateIndex(strLocalFile02.GetBuffer(0), strLocalFile02.GetLength());
VodCreateIndex(strLocalFile03.GetBuffer(0), strLocalFile03.GetLength());
VodCreateIndex(strLocalFile04.GetBuffer(0), strLocalFile04.GetLength());
VodCreateIndex(strLocalFile05.GetBuffer(0), strLocalFile05.GetLength());
CString strConn;//连接数据源,并且把数据插入到SQL Server 2000数据库
strConn.Format("Provider=sqloledb;Data Source=%s,1433;Network Library=DBMSSOCN;Initial Catalog=RecordDB;User ID=sa;Password=leaddo;", SqlSrv_Ip);
_ConnectionPtr pConnection2;
hr = pConnection2.CreateInstance("ADODB.Connection"); //创建Connection对象
BOOL bOK = FALSE;
try
{
if(SUCCEEDED(hr))
{
pConnection2->Open((_bstr_t)strConn,"","",adModeUnknown);
bOK = TRUE;
}
}
catch(_com_error &e) //捕捉异常
{
} if(bOK)
{
CString strXianLu = "";
switch (nAddrCode)
{
case 1:
if(nCxCode<0)
strXianLu = "京广线上行";
else
strXianLu = "京广线下行";
break;
case 2:
if(nCxCode<0)
strXianLu = "a2线上行";
else
strXianLu = "b2线下行";
break;
case 3:
if(nCxCode<0)
strXianLu = "京九线下行";
else
strXianLu = "京九线上行";
break;
case 4:
if(nCxCode<0)
strXianLu = "京九线上行";
else
strXianLu = "京九线下行";
break;
case 5:
if(nCxCode<0)
strXianLu = "宁西线上行";
else
strXianLu = "宁西线下行";
break;
case 6:
if(nCxCode<0)
strXianLu = "京广线上行";
else
strXianLu = "京广线下行";
break;
case 7:
if(nCxCode<0)
strXianLu = "孟宝线上行";
else
strXianLu = "孟宝线下行";
break;
case 8:
if(nCxCode<0)
strXianLu = "a8线上行";
else
strXianLu = "b8线下行";
break;
case 9:
if(nCxCode<0)
strXianLu = "焦柳线下行";
else
strXianLu = "焦柳线上行";
break;
case 10:
if(nCxCode<0)
strXianLu = "襄渝线上行";
else
strXianLu = "襄渝线下行";
break;
case 11:
if(nCxCode<0)
strXianLu = "枝柳线上行";
else
strXianLu = "枝柳线下行";
break;
} strSql.Format("insert into RecordList (AddrCode,XianLuName,RecordDate,RecordTime,FirstRecordPath,SaveDisk,CxCode) values (%ld,'%s','%s','%s','%s','%c',%ld)",
nAddrCode, strXianLu, strRecDate, strRecTime, strLocalFile00, cRecordDriver, nCxCode); pConnection2->Execute((_bstr_t)strSql, NULL, adCmdText);
pConnection2->Close();
}
///////////////////////////////////////////////////////////////////////////////////////
Sleep(20000); //20秒1次循环
} return 0;
}UINT CServerDlg::CheckDiskSpaceThread(LPVOID pParam)
{
CServerDlg* pDlg = (CServerDlg*)pParam; AfxOleInit();
while(pDlg->m_bStarted)
{
CString strDisk;
strDisk.Format("%c:\\", pDlg->m_cCurrentRecordDriver);
ULARGE_INTEGER FreeSpace,CallerSpace,TotalSpace;
GetDiskFreeSpaceEx(strDisk,&CallerSpace,&TotalSpace,&FreeSpace);
if(CallerSpace.QuadPart < MINSPACE)
{
if(pDlg->JudgeAllDiskFull())
{
CString strConn;
strConn.Format("Provider=sqloledb;Data Source=%s,1433;Network Library=DBMSSOCN;Initial Catalog=RecordDB;User ID=sa;Password=leaddo;", SqlSrv_Ip);
HRESULT hr;
_ConnectionPtr pConnection;
hr = pConnection.CreateInstance("ADODB.Connection"); //创建Connection对象
BOOL bOK = FALSE;
try
{
if(SUCCEEDED(hr))
{
pConnection->Open((_bstr_t)strConn,"","",adModeUnknown);
bOK = TRUE;
}
}
catch(_com_error &e) //捕捉异常
{
Sleep(3000);
}
if(bOK)
{
CString strSql;
strSql.Format("select top 50 * from RecordList where SaveDisk='%c' order by RecordDate,RecordTime", pDlg->m_cCurrentRecordDriver); _RecordsetPtr pRecordset;
pRecordset.CreateInstance("ADODB.Recordset");
pRecordset = pConnection->Execute((_bstr_t)strSql, NULL, adCmdText);
while(!pRecordset->adoEOF)
{
long nid = pRecordset->GetCollect("id").lVal;
CString strRecFile00 = (char*)_bstr_t(pRecordset->GetCollect("FirstRecordPath")); strSql.Format("delete from RecordList where id = %ld", nid);
pConnection->Execute((_bstr_t)strSql, NULL, adCmdText); int nIndex = strRecFile00.ReverseFind('\\');
CString strPath = strRecFile00.Left(nIndex);
pDlg->DeleteFilePath(strPath);
pRecordset->MoveNext();
}
pRecordset->Close();
pConnection->Close();
} }
} Sleep(20000); //20秒1次循环
} return 0;
}void CServerDlg::GetDiskDrivers()
{
DWORD dw = GetLogicalDriveStrings(0, NULL);
LPTSTR pAllDrivers=new char[dw];
GetLogicalDriveStrings(dw, pAllDrivers);
LPTSTR pDriver=pAllDrivers;
char tempDriver[26];
DWORD DriverNum=0;
while(pDriver[0]!=0)
{
tempDriver[DriverNum++]=*pDriver;
pDriver=_tcschr(pDriver,0)+1;
}
//volume information
TCHAR lpVolumeNameBuffer[200];
DWORD dwVolumeSerialNumber,dwMaxComLength;
DWORD dwFileSystemFlags;
TCHAR lpFileSystemNameBuffer[50];
DWORD HardNum=0;
for(DWORD num=0;num<DriverNum;num++)
{
CString csRootPath;
csRootPath.Format("%c:\\",tempDriver[num]);
if(GetDriveType(csRootPath)==DRIVE_FIXED) //硬盘
{
if(GetVolumeInformation(csRootPath,lpVolumeNameBuffer,sizeof(lpVolumeNameBuffer),&dwVolumeSerialNumber,
&dwMaxComLength,&dwFileSystemFlags,lpFileSystemNameBuffer,sizeof(lpFileSystemNameBuffer)))
{
m_cHardDriver[HardNum++]=tempDriver[num];
}
}
}
m_nHardDriverNum = HardNum;
delete[] pAllDrivers;
}BOOL CServerDlg::JudgeAllDiskFull()
{
ULARGE_INTEGER FreeSpace,CallerSpace,TotalSpace;
CString csRootPath;
for(int i = 1; i < m_nHardDriverNum; i++)
{
csRootPath.Format("%c:\\", m_cHardDriver[i]);
GetDiskFreeSpaceEx(csRootPath,&CallerSpace,&TotalSpace,&FreeSpace);
if(CallerSpace.QuadPart > MINSPACE)
{
m_cCurrentRecordDriver = m_cHardDriver[i];
//TRACE("m_cCurrentRecordDriver = %c:\\", m_cCurrentRecordDriver);
return FALSE;
}
}
return TRUE;
}BOOL CServerDlg::DeleteFilePath(CString filepath)
{
CFileFind finder;
CString filepathfind=filepath+"\\*.*";
BOOL bFinded=finder.FindFile(filepathfind);
while (bFinded)
{
bFinded=finder.FindNextFile();
if (finder.IsDots())
continue; if (finder.IsDirectory())
DeleteFilePath(finder.GetFilePath());
else
DeleteFile(finder.GetFilePath());
}
finder.Close();
if(RemoveDirectory(filepath))
return TRUE;
else
return FALSE;
}void CServerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
// TODO: Add your message handler code here and/or call default
if(nID==SC_MINIMIZE)
ShowWindow(SW_HIDE);
else
CDialog::OnSysCommand(nID, lParam);
}void CServerDlg::TaskBarAddIcon()
{
m_nData.cbSize = sizeof(NOTIFYICONDATA);
m_nData.hWnd = GetSafeHwnd();
m_nData.uID = IDR_MAINFRAME;
m_nData.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
m_nData.uCallbackMessage = WM_NOTIFYICON;
m_nData.hIcon = m_hIcon;
lstrcpy(m_nData.szTip, "正在运行 - 集中存储服务器\n武汉利德 版权所有");
Shell_NotifyIcon(NIM_ADD, &m_nData);
}void CServerDlg::TaskBarDelIcon()
{
Shell_NotifyIcon(NIM_DELETE, &m_nData);
}void CServerDlg::OnIconNotify(WPARAM wParam, LPARAM lParam)
{
UINT uMouseMsg = LOWORD(lParam);
if(uMouseMsg == WM_RBUTTONDOWN)
{
CPoint point;
GetCursorPos(&point); CMenu menu;
menu.LoadMenu(IDR_POPMENU);
CMenu *pMenu = menu.GetSubMenu(0);
SetForegroundWindow();
pMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x,point.y, this);
menu.DestroyMenu();
}
}