?? spiderwnd.cpp
字號:
// SpiderWnd.cpp : implementation file
//
#include "stdafx.h"
#include "SpiderWnd.h"
#include "DSP.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// SpiderWnd
#define IDC_BTNABORT 0xFFF0 //放棄按鈕的ID
#define MSG_ASSIGNNEWSECT 12345
#define MSG_CREATERECVTHREAD 12346
enum
{
//窗體的字模的高度、窗體的高度和按鈕的寬度高度
WND_FONT_HEIGHT =11,
WND_BTN_WIDTH =12,
WND_HEIGHT =WND_FONT_HEIGHT*4+2,
};
SpiderWnd::SpiderWnd()
{
this->m_spider.m_pstaPrompt =&this->m_staPrompt;
}
SpiderWnd::~SpiderWnd()
{
if(this->m_btnAbort.m_hWnd!=NULL)
{
this->m_btnAbort.DestroyWindow();
this->m_staCurrLen.DestroyWindow();
this->m_staFilename.DestroyWindow();
this->m_staPrompt.DestroyWindow();
this->m_progress.DestroyWindow();
}
}
BEGIN_MESSAGE_MAP(SpiderWnd, CWnd)
//{{AFX_MSG_MAP(SpiderWnd)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_MESSAGE(DSPSpider::MSG_SENDSECT,OnUpdateSect)
ON_MESSAGE(DSPSpider::MSG_RECVSECT,OnUpdateSect)
ON_MESSAGE(DSPSpider::MSG_SENDCOMPLETE,OnSendComplete)
ON_MESSAGE(DSPSpider::MSG_SETFILENAMESIZE,OnSetFilenameSize)
ON_MESSAGE(DSPSpider::MSG_SHOWPROMPT,OnShowPrompt)
ON_MESSAGE(DSPSpider::MSG_GETFILENAME,OnGetFilename)
ON_MESSAGE(MSG_ASSIGNNEWSECT,OnAssignNewSect)
ON_MESSAGE(MSG_CREATERECVTHREAD,OnCreateRecvThread)
ON_COMMAND(IDC_BTNABORT,OnAbort)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// SpiderWnd message handlers
BOOL SpiderWnd::Create(int offx,int offy,int width, CWnd *pParentWnd)
{
//創建窗體本身
CRect rect(offx,offy,offx+width,offy+WND_HEIGHT);
if(!CWnd::CreateEx(WS_EX_TOPMOST|WS_EX_STATICEDGE|WS_EX_TOOLWINDOW,
AfxRegisterWndClass(CS_SAVEBITS,NULL,NULL,NULL),
NULL,WS_POPUP|WS_DLGFRAME,rect,pParentWnd,NULL,NULL))
return FALSE;
CRect rectWnd;
this->m_font.CreateFont(10, // nHeight
4, // nWidth
0, // nEscapement
0, // nOrientation
FW_MEDIUM, // nWeight
0, // bItalic
0, // bUnderline
0, // bStrikeOut
0, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
PROOF_QUALITY, // nQuality
0, // nPitchAndFamily
"Terminal"); // lpszFacename
this->SetFont(&this->m_font);
this->GetClientRect(rectWnd);
this->ReviseContent(rectWnd);
return TRUE;
}
void SpiderWnd::ReviseContent(CRect &rect)
{
CRect rectProg,rectName,rectSize,rectCurr,rectPrompt,rectCancel;
//名字、進度條與窗體的寬度相同
rectName =rectProg =rect;
//計算名字的位置
rectName.bottom =WND_FONT_HEIGHT;
//計算進度條的位置
rectProg.top =rectName.bottom;
rectProg.bottom =rectProg.top+8;
//計算下載字節數提示的位置
rectCurr.left =rect.left;
rectCurr.top =rectProg.bottom;
rectCurr.bottom =rectCurr.top+WND_FONT_HEIGHT;
rectCurr.right =rect.Width()/2;
rectSize.left =rectCurr.right;
rectSize.right =rect.right;
rectSize.top =rectCurr.top;
rectSize.bottom =rectCurr.bottom;
//計算提示信息框的位置,放棄按鈕在提示信息框的右邊
rectPrompt.top =rectSize.bottom;
rectPrompt.bottom =rectPrompt.top+WND_BTN_WIDTH;
rectPrompt.left =rect.left;
rectCancel.right =rect.right;
rectCancel.left =rect.right-WND_BTN_WIDTH;
rectCancel.top =rectPrompt.top;
rectCancel.bottom =rectPrompt.bottom;
rectPrompt.right =rectCancel.left;
if(this->m_progress.m_hWnd==NULL)
{
//如果按鈕沒有被創建
this->m_staFilename.Create(NULL,WS_CHILD|WS_VISIBLE,rectName,this);
this->m_progress.Create(WS_CHILD|WS_VISIBLE|PBS_SMOOTH,rectProg,this,0xFFFF);
this->m_staPrompt.Create("start recv......",WS_CHILD|WS_VISIBLE,rectPrompt,this);
this->m_btnAbort.Create("X",WS_CHILD|WS_VISIBLE,rectCancel,this,IDC_BTNABORT);
this->m_staCurrLen.Create("(0K) 0",WS_CHILD|WS_VISIBLE|SS_RIGHT,rectCurr,this);
this->m_staFilesize.Create("/0 (0K)",WS_CHILD|WS_VISIBLE,rectSize,this);
this->m_staFilename.SetFont(&this->m_font,FALSE);
this->m_staPrompt.SetFont(&this->m_font,FALSE);
this->m_staCurrLen.SetFont(&this->m_font,FALSE);
this->m_staFilesize.SetFont(&this->m_font,FALSE);
this->m_btnAbort.SetFont(&this->m_font);
}
}
LRESULT SpiderWnd::OnUpdateSect(WPARAM wParam, LPARAM lParam)
{
CString str;
DWORD dwSize =this->m_spider.OnUpdateSect(wParam,lParam);
this->m_progress.StepIt();
str.Format("(%dK) %d",dwSize/1024,dwSize);
this->m_staCurrLen.SetWindowText(str);
return 0;
};
LRESULT SpiderWnd::OnSetFilenameSize(WPARAM wParam, LPARAM lParam)
{
//設置文件的名字和大小
DSPSpider::_FILEDETAIL* lphfd =(DSPSpider::_FILEDETAIL*)wParam;
//顯示文件名
this->m_staFilename.SetWindowText(lphfd->strPathname);
//顯示總的長度
CString str;
str.Format("/ %d (%dK)",lphfd->dwFilesize,lphfd->dwFilesize/1024);
this->m_staFilesize.SetWindowText(str);
//初始化當前接收的長度
this->m_staCurrLen.SetWindowText("0K");
//初始化進度顯示
this->m_progress.SetRange32(0,lphfd->dwFilesize);
this->m_progress.SetStep(this->m_spider.GetProgressStep());
this->m_progress.SetPos(this->m_spider.GetCurrSize());
return 0;
}
LRESULT SpiderWnd::OnSendComplete(WPARAM wParam, LPARAM lParam)
{
LRESULT l =this->m_spider.OnSendComplete(wParam,lParam);
switch(l)
{
case 1:
{
//已全部下載完
::AfxMessageBox("文件接收完成!");
}
case 2:
//所有的線程都已經終止
this->m_btnAbort.EnableWindow(true);
break;
}
return 0;
}
LRESULT SpiderWnd::OnAbort(WPARAM wParam, LPARAM lParam)
{
if(this->m_spider.OnAbort(wParam,lParam))
{
//如果已經沒有線程在運行啦,則關閉窗體
this->DestroyWindow();
delete this;
}
else
{
//如果有線程在運行,則終止運行的線程
this->m_btnAbort.EnableWindow(FALSE);
}
return 0;
};
LRESULT SpiderWnd::OnAssignNewSect(WPARAM wParam, LPARAM lParam)
{
return this->m_spider.OnAssignNewSect(wParam,lParam);
};
LRESULT SpiderWnd::OnCreateRecvThread(WPARAM wParam, LPARAM lParam)
{
return this->m_spider.OnCreateRecvThread(wParam,lParam);
};
LRESULT SpiderWnd::OnGetFilename(WPARAM wParam, LPARAM lParam)
{
DSPSpider::_FILEDETAIL& fd =*(DSPSpider::_FILEDETAIL*)wParam;
fd.strPathname ="允許被下載的文件名,包含路徑";
fd.dwFilesize =DSP::GetFileSize(fd.strPathname);
return 0;
};
LRESULT SpiderWnd::OnShowPrompt(WPARAM wParam,LPARAM lParam)
{
CString str;
switch((WORD)wParam)
{
case DSPSpider::PROMPT_RECVSLEEP:
str.Format("Recv:%d ,Sleep:%d.",(BYTE)(wParam>>16),(BYTE)(wParam>>24));
break;
case DSPSpider::PROMPT_MORETHAN:
str.Format("Recv:%d ,Sleep:%d, cann't create more than.",(BYTE)(wParam>>16),(BYTE)(wParam>>24));
break;
case DSPSpider::PROMPT_NOIP:
str.Format("Recv:%d ,Sleep:%d, No IP",(BYTE)(wParam>>16),(BYTE)(wParam>>24));
break;
case DSPSpider::PROMPT_CANNOTCONNECT:
str.Format("connect to IP %s Failed!",(char*)lParam);
break;
case DSPSpider::PROMPT_RECVABORT:
str ="Recv abort.All Thread have been stoped.";
break;
case DSPSpider::PROMPT_RECVEND:
str ="File recv successful.Clear up file.";
}
this->m_staPrompt.SetWindowText(str);
return 0;
};
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -