Practical Learning Logo

Changing the Icon of a Dialog Box

 

Introduction

Because a dialog box in an MFC application is less tied to a document/view scenario than the other types of applications, you can easily do some things such as changing the icon of a dialog box in response to a user's action.

The following two examples change the icon when the user clicks or right-clicks a dialog box

void CDialog2Dlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	HICON hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_HOUSE));
	this->SetIcon(hIcon, FALSE);

	CDialog::OnLButtonDown(nFlags, point);
}

void CDialog2Dlg::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	HICON hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_STAPLE));
	this->SetIcon(hIcon, FALSE);

	CDialog::OnRButtonDown(nFlags, point);
}
 
 

Home Copyright © 2002-2005 FunctionX, Inc.