Click here to Skip to main content
11,478,873 members (56,013 online)
Click here to Skip to main content
Add your own
alternative version

XHTMLTipOfTheDay - HTML Tip of the Day Dialog

, 14 Jun 2004 CPOL 51.3K 1.1K 43
XHTMLTipOfTheDay is a Tip of the Day dialog that displays HTML and has forward and back buttons.
// XHTMLTipOfTheDayTestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "XHTMLTipOfTheDayTest.h"
#include "XHTMLTipOfTheDayTestDlg.h"
#include "about.h"
#include "XHTMLTipOfTheDayDlg.h"
#include "CreateFileFromResource.h"

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

#define WM_APP_COMMAND (WM_APP+100)


/////////////////////////////////////////////////////////////////////////////
// CXHTMLTipOfTheDayTestDlg dialog

BEGIN_MESSAGE_MAP(CXHTMLTipOfTheDayTestDlg, CDialog)
	//{{AFX_MSG_MAP(CXHTMLTipOfTheDayTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_APP_COMMAND, OnAppCommand)
END_MESSAGE_MAP()

CXHTMLTipOfTheDayTestDlg::CXHTMLTipOfTheDayTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CXHTMLTipOfTheDayTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CXHTMLTipOfTheDayTestDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CXHTMLTipOfTheDayTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CXHTMLTipOfTheDayTestDlg)
	//}}AFX_DATA_MAP
}

/////////////////////////////////////////////////////////////////////////////
// CXHTMLTipOfTheDayTestDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	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);
		}
	}

	// 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
	
	// create tips file from resource
	TCHAR szPath[_MAX_PATH*3] = { 0 };
	HINSTANCE hinst = AfxGetInstanceHandle();
	::GetModuleFileName(hinst, szPath, sizeof(szPath)/sizeof(TCHAR)-2);
	TCHAR * cp = _tcsrchr(szPath, _T('\\'));
	if (cp)
		*cp = _T('\0');

	DWORD dwSize = CreateFileFromResource(IDR_TIPFILE, 
										  _T("TIPS"),
										  _T("Tips.tip"),
										  szPath,
										  TRUE);
	TRACE(_T("dwSize=%u\n"), dwSize);

	XHTMLSTATIC_APP_COMMAND AppCommands[] = 
	{
		{ m_hWnd, WM_APP_COMMAND, 0, _T("WM_APP_COMMAND") },
	};

	CXHTMLTipOfTheDayDlg dlg(_T("Tips.tip"));
	dlg.SetAppCommands(AppCommands, sizeof(AppCommands)/sizeof(AppCommands[0]));
	dlg.DoModal();
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

// 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 CXHTMLTipOfTheDayTestDlg::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 CXHTMLTipOfTheDayTestDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

// OnAppCommand will be called when user clicks on hyperlink
LRESULT CXHTMLTipOfTheDayTestDlg::OnAppCommand(WPARAM, LPARAM)
{
	TRACE(_T("in CXHTMLStaticTestDlg::OnAppCommand\n"));
	CAboutDlg dlgAbout;
	dlgAbout.DoModal();
	return 0;
}

void CXHTMLTipOfTheDayTestDlg::OnButton1() 
{
	XHTMLSTATIC_APP_COMMAND AppCommands[] = 
	{
		{ m_hWnd, WM_APP_COMMAND, 1, _T("WM_APP_COMMAND") },
	};
	CXHTMLTipOfTheDayDlg dlg(_T("Tips.tip"));
	dlg.SetAppCommands(AppCommands, sizeof(AppCommands)/sizeof(AppCommands[0]));
	dlg.DoModal();
}

// force display even if startup option is off
void CXHTMLTipOfTheDayTestDlg::OnButton2() 
{
	XHTMLSTATIC_APP_COMMAND AppCommands[] = 
	{
		{ m_hWnd, WM_APP_COMMAND, 2, _T("WM_APP_COMMAND") },
	};
	CXHTMLTipOfTheDayDlg dlg(_T("Tips.tip"));
	dlg.SetStartup(TRUE);		// force it to display
	dlg.SetAppCommands(AppCommands, sizeof(AppCommands)/sizeof(AppCommands[0]));
	dlg.DoModal();
}

static const TCHAR szSection[]   = _T("TipOfTheDay");
static const TCHAR szTimeStamp[] = _T("TimeStamp");

// open at welcome tip
void CXHTMLTipOfTheDayTestDlg::OnButton3() 
{
	XHTMLSTATIC_APP_COMMAND AppCommands[] = 
	{
		{ m_hWnd, WM_APP_COMMAND, 3, _T("WM_APP_COMMAND") },
	};
	CXHTMLTipOfTheDayDlg dlg(_T("Tips.tip"));

	// clear the registry entry
	AfxGetApp()->WriteProfileString(szSection, szTimeStamp, NULL);

	dlg.SetAppCommands(AppCommands, sizeof(AppCommands)/sizeof(AppCommands[0]));
	dlg.DoModal();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Hans Dietrich
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see www.hdsoft.org.






| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 14 Jun 2004
Article Copyright 2004 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid