📄 httpview.cpp
字号:
// HttpView.cpp : implementation of the CHttpSvrView class
//
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1997-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
#include "stdafx.h"
#include "HttpSvr.h"
#include "Http.h"
#include "HttpDoc.h"
#include "HttpView.h"
#include "RootDlg.h"
#include "NoRoot.h"
#include "Request.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHttpSvrView
IMPLEMENT_DYNCREATE(CHttpSvrView, CListView)
BEGIN_MESSAGE_MAP(CHttpSvrView, CListView)
//{{AFX_MSG_MAP(CHttpSvrView)
ON_COMMAND(IDM_VIEW_LARGE, OnViewLarge)
ON_UPDATE_COMMAND_UI(IDM_VIEW_LARGE, OnUpdateViewLarge)
ON_COMMAND(IDM_VIEW_LIST, OnViewList)
ON_UPDATE_COMMAND_UI(IDM_VIEW_LIST, OnUpdateViewList)
ON_COMMAND(IDM_VIEW_REPORT, OnViewReport)
ON_UPDATE_COMMAND_UI(IDM_VIEW_REPORT, OnUpdateViewReport)
ON_COMMAND(IDM_VIEW_SMALL, OnViewSmall)
ON_UPDATE_COMMAND_UI(IDM_VIEW_SMALL, OnUpdateViewSmall)
ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnclick)
ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetDispInfo)
ON_NOTIFY_REFLECT(LVN_DELETEITEM, OnDeleteItem)
ON_COMMAND(IDM_VIEW_CLEAR, OnViewClear)
//}}AFX_MSG_MAP
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
ON_COMMAND(IDM_POPUP_CLEAR, OnPopupClear)
ON_COMMAND(IDM_POPUP_EDIT, OnPopupEdit)
ON_COMMAND(IDM_POPUP_OPEN, OnPopupOpen)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHttpSvrView construction/destruction
CHttpSvrView::CHttpSvrView()
{
m_phdPopup = NULL;
}
CHttpSvrView::~CHttpSvrView()
{
}
BOOL CHttpSvrView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style = (cs.style & ~LVS_TYPEMASK) | LVS_REPORT;
cs.style |= LVS_AUTOARRANGE;
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CHttpSvrView drawing
void CHttpSvrView::OnDraw(CDC* pDC)
{
CHttpSvrDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
}
void CHttpSvrView::OnInitialUpdate()
{
CHttpSvrDoc* pDoc = GetDocument();
CListView::OnInitialUpdate();
// get the root directory....
CString strRoot = pDoc->m_strRoot;
// make sure it exists and it's a folder....
BOOL bLoop = TRUE;
while ( bLoop )
{
DWORD dwAttr = GetFileAttributes( strRoot );
if ( dwAttr == -1 )
{
CNoRootDlg dlg;
dlg.m_strRoot = strRoot;
UINT uButton = dlg.DoModal();
if ( uButton == IDOK )
{
strRoot = dlg.m_strRoot;
dwAttr = GetFileAttributes( strRoot );
if ( dwAttr == -1 )
{
if ( !CreateDirectory( strRoot, NULL ) )
{
MessageBox( "Create Directory failed",
strRoot, MB_ICONEXCLAMATION|MB_OK );
}
}
}
else // no....
bLoop = FALSE; // use it anyway
}
else if ( (dwAttr & FILE_ATTRIBUTE_DIRECTORY) == 0 )
{
CBadRootDlg dlg;
dlg.m_strRoot = strRoot;
if ( dlg.DoModal() == IDCANCEL )
bLoop = FALSE; // use it anyway
}
else
{
// root is okay, save it....
if ( strRoot.CompareNoCase(pDoc->m_strRoot) != 0 )
{
pDoc->m_strRoot = strRoot;
pDoc->SetModifiedFlag( TRUE );
}
bLoop = FALSE; // okay!
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CHttpSvrView diagnostics
#ifdef _DEBUG
void CHttpSvrView::AssertValid() const
{
CListView::AssertValid();
}
void CHttpSvrView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CHttpSvrDoc* CHttpSvrView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHttpSvrDoc)));
return (CHttpSvrDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHttpSvrView message handlers
BOOL CHttpSvrView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
BOOL bCreated = CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
if ( bCreated )
{
CListCtrl& listView = GetListCtrl();
int aWidths[] = { 150, 200, 50, 140, 225, 200 };
CString strHeading;
for ( int iCol = 0; iCol < C_COLUMNS; iCol++) {
strHeading.LoadString( IDS_COLUMN1 + iCol );
listView.InsertColumn( iCol, strHeading, LVCFMT_LEFT,
aWidths[iCol], iCol );
}
// Create the full-sized and small icon image lists.
if ( m_ilLarge.Create( IDB_IMAGES, 32, 1, RGB(0,255,0) ) )
{
listView.SetImageList( &m_ilLarge, LVSIL_NORMAL );
}
if ( m_ilSmall.Create( IDB_SMALLIMAGES, 16, 1, RGB(0,255,0) ) )
{
listView.SetImageList( &m_ilSmall, LVSIL_SMALL);
}
}
return bCreated;
}
void CHttpSvrView::SetListView( DWORD dwView )
{
CListCtrl& list = GetListCtrl();
DWORD dwStyle = GetWindowLong( list.m_hWnd, GWL_STYLE );
if ( (dwStyle & LVS_TYPEMASK) != dwView )
SetWindowLong( list.m_hWnd, GWL_STYLE,
(dwStyle & ~LVS_TYPEMASK) | dwView );
}
void CHttpSvrView::OnViewLarge()
{
SetListView( LVS_ICON );
}
void CHttpSvrView::OnUpdateViewLarge(CCmdUI* pCmdUI)
{
CListCtrl& list = GetListCtrl();
DWORD dwStyle = GetWindowLong( list.m_hWnd, GWL_STYLE ) & LVS_TYPEMASK;
pCmdUI->SetCheck( dwStyle == LVS_ICON );
}
void CHttpSvrView::OnViewList()
{
SetListView( LVS_LIST );
}
void CHttpSvrView::OnUpdateViewList(CCmdUI* pCmdUI)
{
CListCtrl& list = GetListCtrl();
DWORD dwStyle = GetWindowLong( list.m_hWnd, GWL_STYLE ) & LVS_TYPEMASK;
pCmdUI->SetCheck( dwStyle == LVS_LIST );
}
void CHttpSvrView::OnViewReport()
{
SetListView( LVS_REPORT );
}
void CHttpSvrView::OnUpdateViewReport(CCmdUI* pCmdUI)
{
CListCtrl& list = GetListCtrl();
DWORD dwStyle = GetWindowLong( list.m_hWnd, GWL_STYLE ) & LVS_TYPEMASK;
pCmdUI->SetCheck( dwStyle == LVS_REPORT );
}
void CHttpSvrView::OnViewSmall()
{
SetListView( LVS_SMALLICON );
}
void CHttpSvrView::OnUpdateViewSmall(CCmdUI* pCmdUI)
{
CListCtrl& list = GetListCtrl();
DWORD dwStyle = GetWindowLong( list.m_hWnd, GWL_STYLE ) & LVS_TYPEMASK;
pCmdUI->SetCheck( dwStyle == LVS_SMALLICON );
}
int CALLBACK
CompareHitDocs( CHitDoc* doc1, CHitDoc* doc2, LPARAM lCol )
{
int nCmp = 0;
switch( lCol )
{
case COLUMN_PATH:
nCmp = doc1->m_strFolder.CompareNoCase( doc2->m_strFolder );
break;
case COLUMN_HITS:
if ( doc1->m_nHits > doc2->m_nHits )
nCmp = -1;
else if ( doc1->m_nHits < doc2->m_nHits )
nCmp = 1;
break;
case COLUMN_LAST:
if ( doc1->m_timeLastHit > doc2->m_timeLastHit )
nCmp = -1;
else if ( doc1->m_timeLastHit < doc2->m_timeLastHit )
nCmp = 1;
break;
case COLUMN_CMD:
nCmp = doc1->m_strCommand.CompareNoCase( doc2->m_strCommand );
break;
case COLUMN_URL:
nCmp = doc1->m_strURL.CompareNoCase( doc2->m_strURL );
break;
default:
// put folders ahead of everything....
if ( doc1->m_bFolder && !doc2->m_bFolder )
nCmp = -1;
else if ( !doc1->m_bFolder && doc2->m_bFolder )
nCmp = 1;
// sort successfully hit docs....
else if ( doc1->m_nStatus == 200 && doc2->m_nStatus == 200 )
{
nCmp = doc1->m_strFile.CompareNoCase( doc2->m_strFile );
if ( nCmp == 0 )
nCmp = doc1->m_strFolder.CompareNoCase( doc2->m_strFolder );
}
// put hit docs ahead of status items....
else if ( doc1->m_nStatus == 200 )
nCmp = -1;
else if ( doc2->m_nStatus == 200 )
nCmp = 1;
// sort status items by status value....
else if ( doc1->m_nStatus < doc2->m_nStatus )
nCmp = -1;
else if ( doc1->m_nStatus > doc2->m_nStatus )
nCmp = 1;
break;
}
return nCmp;
}
void CHttpSvrView::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -