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

📄 openhtmdlg.cpp

📁 Visual.C++程序设计技巧与实例--配套光盘 第6章 文件和系统操作 本章共11个实例: 1. FolderCopy文件夹的选择和拷贝 2. DeleteCertainFile删除指定路
💻 CPP
字号:
// OpenHtmDlg.cpp : implementation file
//

#include "stdafx.h"
#include "OpenHtm.h"
#include "OpenHtmDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// COpenHtmDlg dialog

COpenHtmDlg::COpenHtmDlg(CWnd* pParent /*=NULL*/)
	: CDialog(COpenHtmDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(COpenHtmDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void COpenHtmDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COpenHtmDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(COpenHtmDlg, CDialog)
	//{{AFX_MSG_MAP(COpenHtmDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_OPENHTML, OnOpenhtml)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COpenHtmDlg message handlers

BOOL COpenHtmDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void COpenHtmDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		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;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR COpenHtmDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void COpenHtmDlg::OnOpenhtml() 
{
/*
通过读取注册表,取得Windows默认浏览器的路径名,然后带参数执行默认浏览器,所带的参
数即所要调用的主页地址。Windows默认浏览器的键值在注册表中的存放目录是
HKEY_CLASSES_ROOT\htmlfile\shell\open\command
	*/
	
	//定义注册表根关键字
	HKEY hkeyRoot; 
	
	//定义注册表子关键字
	HKEY hkeySub;
    char valuename[128];
    unsigned char datavalue[128];
    unsigned long cbvaluename=128;
    unsigned long cbdatavalue=128;
	
	//定义命令行
    char ShellChar[128]; 
    DWORD dwType;
	
    //打开注册表根关键字
    if(RegOpenKey(HKEY_CLASSES_ROOT,NULL,&hkeyRoot)==ERROR_SUCCESS)
    {
		//打开子关键字
        if( ERROR_SUCCESS==RegOpenKeyEx(hkeyRoot,
			"htmlfile\\shell\\open\\command",
			0,
			KEY_ALL_ACCESS,
			&hkeySub) )
        {
            //读取注册表,获取默认浏览器的命令行
            RegEnumValue(hkeySub,
                0,
				valuename,
				&cbvaluename,
				NULL,
				&dwType,
				datavalue,
				&cbdatavalue);
			
            // 调用参数(主页地址)赋值
            strcpy(ShellChar,(char *)datavalue);
            strcat(ShellChar," www.buaa.edu.cn");
			
            // 启动浏览器
            WinExec(ShellChar,SW_SHOW);
        }
        else
            MessageBox("网页浏览器打开错误!","错误",MB_OK);
    }
    else
		
        MessageBox("网页浏览器打开错误!","错误",MB_OK);
	
    //关闭注册表
    RegCloseKey(hkeySub);
    RegCloseKey(hkeyRoot);
	
}

⌨️ 快捷键说明

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