?? onlinelist.cpp
字號:
// OnlineList.cpp : implementation file
//
//*************************************************************
//作者:趙明
//EMAIL:zmpapaya@hotmail.com;papaya_zm@sina.com
//主頁:http://h2osky.126.com
/********************************************************/
#include "stdafx.h"
#include "client1.h"
#include "OnlineList.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COnlineList
COnlineList::COnlineList()
{
}
COnlineList::~COnlineList()
{
BEGIN_MESSAGE_MAP(COnlineList, CListCtrl)
//{{AFX_MSG_MAP(COnlineList)
ON_WM_CREATE()
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
// ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COnlineList message handlers
int COnlineList::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
void COnlineList::AddItem(filesendinfo * seinfo)
{
LVITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_IMAGE;
lvi.iItem = GetItemCount();
// lvi.iImage = i;
lvi.iSubItem = 0;
// lvi.s=0;
lvi.pszText = "";
lvi.cchTextMax = 64;
InsertItem(&lvi);
SetItemText(lvi.iItem,0,seinfo->name);
CString aaa;
aaa.Format("%d k",seinfo->length/1000);
SetItemText(lvi.iItem,1,aaa.GetBuffer(0));
//SetItemText(lvi.iItem,2,seinfo->date);
aaa.ReleaseBuffer();
// SetItemText(lvi.iItem,2,name);
// SetItemText(lvi.iItem,3,(char *)m_csPath);
// SetItemText(lvi.iItem,4,(char *)m_csAttrib);
SetHotItem(lvi.iItem); //標注當前項目
EnsureVisible(lvi.iItem,true); //滾動影響的卷軸
Update(lvi.iItem);
//strcpy(name1[lvi.iItem],name2);
//strcpy(name1[lvi.iItem+1],"none");
//strcpy(nameph[lvi.iItem],namepath);
//AfxMessageBox(name1[lvi.iItem]);
}
//
void COnlineList::AddItemtwo(int fileno,int now,int byes,int type,int speed,int threadno)
{
LVITEM lvi;
lvi.mask = LVIF_TEXT ;
lvi.iItem = GetItemCount();
itemtoitem[lvi.iItem]=threadno;
filedono[fileno]=lvi.iItem;
// lvi.iImage = threadno;
lvi.iSubItem = 0;
// lvi.s=0;
lvi.pszText = "";
lvi.cchTextMax = 64;
InsertItem(&lvi);
SetItemText(lvi.iItem,0,zmfile[fileno].name);
CString aaa;
while(now>0)
{
aaa=aaa+'|';
now-=2;
}
SetItemText(lvi.iItem,1,aaa.GetBuffer(0));
aaa.Format("%d k",byes/1000);
SetItemText(lvi.iItem,3,aaa.GetBuffer(0));
aaa.Format("%d k/s",speed);
SetItemText(lvi.iItem,2,aaa.GetBuffer(0));
switch(type)
{
case 0:
aaa="下載中";
break;
case 1:
aaa="下載中";
break;
case 2:
aaa="已完成";
break;
}
SetItemText(lvi.iItem,4,aaa.GetBuffer(0));
//SetItemText(lvi.iItem,2,seinfo->date);
aaa.ReleaseBuffer();
// SetItemText(lvi.iItem,2,name);
// SetItemText(lvi.iItem,3,(char *)m_csPath);
// SetItemText(lvi.iItem,4,(char *)m_csAttrib);
SetHotItem(lvi.iItem); //標注當前項目
EnsureVisible(lvi.iItem,true); //滾動影響的卷軸
Update(lvi.iItem);
//strcpy(name1[lvi.iItem],name2);
//strcpy(name1[lvi.iItem+1],"none");
//strcpy(nameph[lvi.iItem],namepath);
//AfxMessageBox(name1[lvi.iItem]);
}
void COnlineList::Remove(char *name)
{
CString str;
for(int i = 0; i < GetItemCount(); i++)
{
str = GetItemText(i,0);
if(strcmp(str, name) == 0)
{
DeleteItem(i);
break;
}
}
}
//雙擊List控件中的某一項,就可以導致“下載文件”的代碼被執行。
void COnlineList::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
{
//NMLISTVIEW Contains information about a list-view notification message. This structure is the same as the NM_LISTVIEW structure but has been renamed to fit standard naming conventions.
//NMHDR Contains information about a notification message.
//NMLISTVIEW結構的第一個數據成員是NMHDR hdr;所以,下面的這個強制數據類型轉換還是有
//一點點的道理的。不過,只能訪問NMHDR部分,才算是安全的!但是,作者的用法超出了安全的
//范圍,而是訪問了iItem成員??磥?,pNMHDR指針原來就應該是指向NMLISTVIEW類型的變量的?。?!
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
//List控件的父窗口就是“在線文件列表”對話框窗口。
CWnd* pParentWnd = GetParent();
//此變量用來保存獲得的對話框窗口的ID。
int aa;
if(pParentWnd != NULL)
{
//CWnd::GetDlgCtrlID Returns the window or control ID value for any child window, not only that of a control in a dialog box.
//獲得對話框窗口的ID
aa=pParentWnd->GetDlgCtrlID();
}
//之所以要加上這個判斷條件,是因為COnlineList不僅僅用于“在線文件列表”對話框窗口,還用于
//“文件下載進度”對話框窗口。很顯然了,作者的設計是:希望下面的代碼只在對“在線文件列表”
//對話框窗口進行操作的時候被執行,所以,就有了下面的這一句判斷代碼。
//如果對話框窗口的ID是IDD_DIALOG1,則
if(aa==IDD_DIALOG1)
{
CString str;
//獲得List控件的當前被選中的項。
int iSel = pNMListView->iItem;
//如果List控件的當前被選中的項,是有效的,則
if(iSel>=0)
{
//The SendMessage function sends the specified message to a window or windows.
//It calls the window procedure for the specified window and does not return
//until the window procedure has processed the message.
//這里用的是SendMessage,所以,消息發出之后不會立即返回,而是非得要等消息
//被處理完了才能返回。
//向主框架窗口發送CLT_ONSE消息,按照MFC的消息傳遞機制,首先處理此消息的窗口應該
//是主框架中的當前活動的視。不過,在視類中并沒有添加處理此消息的代碼,所以,
//實際上是CMainFrame::OnClient函數處理了此消息。
::AfxGetMainWnd()->SendMessage(CLT_ONSE,0, (LPARAM)&iSel);
}
}
*pResult = 0;
}
void COnlineList::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
{
// ::MessageBox(NULL,"COnlineList::OnRclick的代碼被暫時注釋掉了,等以后再補上。","",0);
/* //不知為什么,這里的代碼一執行就出錯,只好先注釋掉了。
// TODO: Add your control notification handler code here
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
CWnd* pParentWnd = GetParent();
int aa;
if (pParentWnd != NULL)
{
aa =pParentWnd->GetDlgCtrlID();
}
int iSel = pNMListView->iItem;
if(iSel>=0)
{
::AfxGetMainWnd()->SendMessage(AA,0, (LPARAM)&itemtoitem[iSel]);
}
*pResult = 0;
*/
}
void COnlineList::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
// TODO: Add your control notification handler code here
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
CWnd* pParentWnd = GetParent();
int aa;
if (pParentWnd != NULL){
aa =pParentWnd->GetDlgCtrlID();
}
//CString aaa;
//aaa.Format("%d",aa);
//AfxMessageBox(aaa);
if(aa==IDD_DIALOG3){
// CString str;
int iSel = pNMListView->iItem;
// str.Format("the no is %d",iSel);
// AfxMessageBox(str);
if(iSel>=0){
::AfxGetMainWnd()->SendMessage(BB,0, (LPARAM)&itemtoitem[iSel]);
}
}
*pResult = 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -