⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wininettestview.cpp

📁 VC++高级编程技巧与示例
💻 CPP
字号:
// WinInetTestView.cpp : implementation of the CWinInetTestView class
//

#include "stdafx.h"
#include "WinInetTest.h"

#include "WinInetTestDoc.h"
#include "WinInetTestView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWinInetTestView

//●: 
#include "mainfrm.h"

IMPLEMENT_DYNCREATE(CWinInetTestView, CScrollView)

BEGIN_MESSAGE_MAP(CWinInetTestView, CScrollView)
	//{{AFX_MSG_MAP(CWinInetTestView)
	ON_BN_CLICKED(IDC_LINK, OnLink)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWinInetTestView construction/destruction

CWinInetTestView::CWinInetTestView()
{
	// TODO: add construction code here
}

CWinInetTestView::~CWinInetTestView()
{
}

BOOL CWinInetTestView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CWinInetTestView drawing

void CWinInetTestView::OnDraw(CDC* pDC)
{
	CWinInetTestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//●: 
	UINT nl;
	UINT i;
	CRect rc;
	CSize sz,szt;

	nl=m_Info.GetSize();

	sz.cx=0;
	sz.cy=0;

	for(i=0;i<nl;i++)
	{
		szt=pDC->GetTextExtent(m_Info[i]);
		if(szt.cx>sz.cx)
		{
			sz.cx=szt.cx+100;
		}
		sz.cy+=szt.cy+10;
	}

	SetScrollSizes(MM_TEXT,sz);

	for (i=0;i<nl;i++)
	{
        pDC->TextOut(20, szt.cy*i+10, m_Info[i]);
	}
}

void CWinInetTestView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
//●: 
	sizeTotal.cx =1000;
	sizeTotal.cy =500;
	SetScrollSizes(MM_TEXT, sizeTotal);

	CString InitEdit;
	CMainFrame * m_Frame;
	m_Frame=(CMainFrame *)GetParentFrame();
	m_DlgBar=&m_Frame->m_wndMyDialogBar;
	m_Edit=(CEdit *)m_DlgBar->GetDlgItem (IDC_URL);
	m_DlgBar->SetWindowText("输入URL");
	m_Edit->SetWindowText("http://localhost");
}

/////////////////////////////////////////////////////////////////////////////
// CWinInetTestView printing

BOOL CWinInetTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CWinInetTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CWinInetTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CWinInetTestView diagnostics

#ifdef _DEBUG
void CWinInetTestView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CWinInetTestView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CWinInetTestDoc* CWinInetTestView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWinInetTestDoc)));
	return (CWinInetTestDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CWinInetTestView message handlers
//●: 
void CWinInetTestView::OnLink() 
{
	// TODO: Add your control notification handler code here
	UINT i;
	CString url;
	CString str;
	m_DlgBar->GetDlgItemText(IDC_URL,url);
    CInternetSession Is;
    try
    {
        CHttpFile* Hf =
           (CHttpFile*)Is.OpenURL(url);

        while(Hf->ReadString(str))
		{
			m_Info.Add(str);
		}

        Hf->Close();        
	}
    catch (CInternetException* e)
    {
		if(m_Info.GetSize()!=0)
		{
			m_Info[0] = "CInternetException received!";
			for(i=1;i<m_Info.GetSize();i++)
			{
				m_Info[i]="";
			}
		}
		else
		{
			m_Info.Add("CInternetException received!");
		}
        e->ReportError();
	}        
	Is.Close();
    Invalidate();    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -