Click here to Skip to main content
15,891,136 members
Articles / Desktop Programming / MFC

Function to load a bitmap on a dialog

Rate me:
Please Sign up or sign in to vote.
1.31/5 (21 votes)
6 Apr 2006CPOL 62K   1.8K   13  
Here is a function to load a bitmap on any dialog.
// SDlg.cpp: implementation of the SDlg class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SBitDialog.h"
#include "SDlg.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SDlg::SDlg()
{

}

SDlg::~SDlg()
{

}
BEGIN_MESSAGE_MAP(SDlg, CButton)
	
	ON_WM_MOUSEMOVE()
	
	ON_WM_KEYDOWN()
	//}}AFX_MSG_MAP
    
END_MESSAGE_MAP()
void SDlg::SetToolTipText(CString s)
{
	
	if(m_tooltip.m_hWnd==NULL)
	{
		if(m_tooltip.Create(this))	//first assignment
			if(m_tooltip.AddTool(this, (LPCTSTR)s))
				m_tooltip.Activate(1);
	}
	else {
		m_tooltip.UpdateTipText((LPCTSTR)s,this);
	}

}

void SDlg::RelayEvent(UINT message, WPARAM wParam, LPARAM lParam)
{
	
// This function will create a MSG structure, fill it in a pass it to
// the ToolTip control, m_ttip.  Note that we ensure the point is in window
// coordinates (relative to the control's window).
	if(NULL != m_tooltip.m_hWnd){
		MSG msg;
 		msg.hwnd = m_hWnd;
		msg.message = message;
		msg.wParam = wParam;
		msg.lParam = lParam;
		msg.time = 0;
		msg.pt.x = LOWORD(lParam);
		msg.pt.y = HIWORD(lParam);
		m_tooltip.RelayEvent(&msg);
	}

}

void SDlg::OnMouseMove(UINT nFlags, CPoint point)
{
	RelayEvent(WM_MOUSEMOVE,(WPARAM)nFlags,MAKELPARAM(LOWORD(point.x),LOWORD(point.y)));
	CButton::OnMouseMove(nFlags, point);
}

bool SDlg::MakeButton(CString st,UINT Resource, UINT ResourceSel, UINT ResourceFocus, UINT ResourceDisabled)
{
	LoadBitmaps(Resource,ResourceSel,ResourceFocus,ResourceDisabled);
    SetToolTipText(st);
	SizeToContent();
	return true;
}

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)


Written By
Web Developer
India India
This is Saday Chand Sarkar , New in MFC world.
Working in Trek Technology Pte.Ltd.

Comments and Discussions