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

📄 dhtmldemodlg.cpp

📁 VC.net 的一些有用的技巧
💻 CPP
字号:
// DHtmlDemoDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "DHtmlDemo.h"
#include "DHtmlDemoDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// 对话框数据
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CDHtmlDemoDlg 对话框

BEGIN_DHTML_EVENT_MAP(CDHtmlDemoDlg)
	DHTML_EVENT_ONCLICK(_T("ButtonOK"), OnButtonOK)
	DHTML_EVENT_ONCLICK(_T("ButtonCancel"), OnButtonCancel)
	DHTML_EVENT_ONCLICK(_T("Button1"),OnButton1)
	DHTML_EVENT_ONMOUSEOVER(_T("LabelText"),OnMouseOverLabelText)
	DHTML_EVENT_ONMOUSEOUT(_T("LabelText"),OnMouseOutLabelText)
END_DHTML_EVENT_MAP()


CDHtmlDemoDlg::CDHtmlDemoDlg(CWnd* pParent /*=NULL*/)
	: CDHtmlDialog(CDHtmlDemoDlg::IDD, CDHtmlDemoDlg::IDH, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDHtmlDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDHtmlDialog::DoDataExchange(pDX);
	DDX_DHtml_ElementText(pDX,_T("Text1"),DISPID_A_VALUE ,m_strEdit);
}

BEGIN_MESSAGE_MAP(CDHtmlDemoDlg, CDHtmlDialog)
	ON_WM_SYSCOMMAND()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


// CDHtmlDemoDlg 消息处理程序

BOOL CDHtmlDemoDlg::OnInitDialog()
{
	CDHtmlDialog::OnInitDialog();

	// 将\“关于...\”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO:在此添加额外的初始化代码
	m_strEdit="请输入消息内容";
	UpdateData(FALSE);
	return TRUE;  // 除非设置了控件的焦点,否则返回 TRUE
}

void CDHtmlDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDHtmlDialog::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。

void CDHtmlDemoDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作矩形中居中
		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;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDHtmlDialog::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标显示。
HCURSOR CDHtmlDemoDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}
HRESULT CDHtmlDemoDlg::OnButtonOK(IHTMLElement* /*pElement*/)
{
	OnOK();
	return S_OK;
}

HRESULT CDHtmlDemoDlg::OnButtonCancel(IHTMLElement* /*pElement*/)
{
	OnCancel();
	return S_OK;
}

//HTML元素的事件映射
//HRESULT CDHtmlDemoDlg::OnButton1(IHTMLElement* /*pElement*/)
//{
//	MessageBox("单击按钮的事件映射");
//	return S_OK; 
//}

//DDX/DDV机制
HRESULT CDHtmlDemoDlg::OnButton1(IHTMLElement* /*pElement*/)
{
	UpdateData(TRUE);
	MessageBox(m_strEdit);
	return S_OK; 
}

//
HRESULT CDHtmlDemoDlg::OnMouseOverLabelText(IHTMLElement *pElement)
{
	IHTMLStyle *phtmlStyle; 
	pElement->get_style(&phtmlStyle); 
	if (phtmlStyle) 
	{ 
		VARIANT varColor; 
		varColor.vt = VT_I4; 
		varColor.lVal = 0x0000ff; 
		phtmlStyle->get_color(&m_varColor); 
		phtmlStyle->put_color(varColor);
		phtmlStyle->Release(); 
	}

	return S_OK;
}

HRESULT CDHtmlDemoDlg::OnMouseOutLabelText(IHTMLElement *pElement)
{
	IHTMLStyle *phtmlStyle; 
	pElement->get_style(&phtmlStyle); 
	if (phtmlStyle) 
	{ 
		phtmlStyle->put_color(m_varColor); 
		phtmlStyle->Release(); 
	}

	return S_OK;
}

⌨️ 快捷键说明

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