Click here to Skip to main content
15,881,669 members
Articles / Desktop Programming / MFC

Static Control with ToolTip

Rate me:
Please Sign up or sign in to vote.
2.95/5 (10 votes)
13 Sep 2007CPOL 41.3K   2.1K   13  
The Tool Tip shows the Text of Static Control when the Text is clipped in Static Control.
// ToolTipCtrlDlg.cpp : �C���v�������e�[�V���� �t�@�C��
//

#include "stdafx.h"
#include "ToolTipCtrl.h"
#include "ToolTipCtrlDlg.h"

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

#define XXX	//Used for testing (By Sandesh)

/////////////////////////////////////////////////////////////////////////////
// �A�v���P�[�V�����̃o�[�W�������Ŏg���Ă��� CAboutDlg �_�C�A���O

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

// �_�C�A���O �f�[�^
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard �͉��z�֐��̃I�[�o�[���C�h�𐶐����܂�
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV �̃T�|�[�g
	//}}AFX_VIRTUAL

// �C���v�������e�[�V����
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

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

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

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// ���b�Z�[�W �n���h��������܂���B
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CToolTipCtrlDlg �_�C�A���O

CToolTipCtrlDlg::CToolTipCtrlDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CToolTipCtrlDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CToolTipCtrlDlg)
		// ����: ���̈ʒu�� ClassWizard �ɂ���ă����o�̏��������lj�����܂��B
	//}}AFX_DATA_INIT
	// ����: LoadIcon �� Win32 �� DestroyIcon �̃T�u�V�[�P���X��v�����܂���B
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CToolTipCtrlDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CToolTipCtrlDlg)
	DDX_Control(pDX, IDC_STC4, m_TlTipStc4);
	DDX_Control(pDX, IDC_STC3, m_TlTipStc3);
	DDX_Control(pDX, IDC_STC2, m_TlTipStc2);
	DDX_Control(pDX, IDC_EDIT_INPUT, m_EditIP);
	DDX_Control(pDX, IDC_STC_TEST, m_TlTipStc);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CToolTipCtrlDlg, CDialog)
	//{{AFX_MSG_MAP(CToolTipCtrlDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_EN_CHANGE(IDC_EDIT_INPUT, OnChangeEditInput)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CToolTipCtrlDlg ���b�Z�[�W �n���h��

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

	// "�o�[�W�������..." ���j���[���ڂ�V�X�e�� ���j���[�֒lj����܂��B

	// IDM_ABOUTBOX �̓R�}���h ���j���[�͈̔͂łȂ���΂Ȃ�܂���B
	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);
		}
	}

	// ���̃_�C�A���O�p�̃A�C�R����ݒ肵�܂��B�t���[�����[�N�̓A�v���P�[�V�����̃��C��
	// �E�B���h�E���_�C�A���O�łȂ����͎����I�ɐݒ肵�܂���B
	SetIcon(m_hIcon, TRUE);			// �傫���A�C�R����ݒ�
	SetIcon(m_hIcon, FALSE);		// �������A�C�R����ݒ�
	
	// TODO: ���ʂȏ�������s�����͂��̏ꏊ�ɒlj����Ă��������B
	
	return TRUE;  // TRUE ��Ԃ��ƃR���g���[���ɐݒ肵���t�H�[�J�X�͎����܂���B
}

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

// ����_�C�A���O�{�b�N�X�ɍŏ����{�^����lj�����Ȃ�΁A�A�C�R����`�悷��
// �R�[�h��ȉ��ɋL�q����K�v������܂��BMFC �A�v���P�[�V������ document/view
// ���f����g���Ă���̂ŁA���̏����̓t���[�����[�N�ɂ�莩���I�ɏ�������܂��B

void CToolTipCtrlDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // �`��p�̃f�o�C�X �R���e�L�X�g

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

		// �N���C�A���g�̋�`�̈��̒���
		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;

		// �A�C�R����`�悵�܂��B
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// �V�X�e���́A���[�U�[���ŏ����E�B���h�E��h���b�O���Ă���ԁA
// �J�[�\����\�����邽�߂ɂ�����Ăяo���܂��B
HCURSOR CToolTipCtrlDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CToolTipCtrlDlg::OnChangeEditInput() 
{
	// TODO: ���ꂪ RICHEDIT �R���g���[���̏ꍇ�A�R���g���[���́A lParam �}�X�N
	// ��ł̘_���a�� ENM_CHANGE �t���O�t���� CRichEditCrtl().SetEventMask()
	// ���b�Z�[�W��R���g���[���֑��邽�߂� CDialog::OnInitDialog() �֐���I�[�o�[
	// ���C�h���Ȃ����肱�̒ʒm�𑗂�܂���B
	
	// TODO: ���̈ʒu�ɃR���g���[���ʒm�n���h���p�̃R�[�h��lj����Ă�������
	char szTempBuff[MAX_BUFF_SIZE] = {0};
	m_EditIP.GetLine(0, szTempBuff, MAX_BUFF_SIZE - 1);

	int nStrLen = m_EditIP.LineLength(0);
	if(nStrLen < MAX_BUFF_SIZE){
		szTempBuff[nStrLen] = '\0';
	}else{
		AfxMessageBox("The text size has exceeded. Only 1023 Characters will be considered.");
		szTempBuff[MAX_BUFF_SIZE-1] = '\0';
	}
	m_TlTipStc.SetText(szTempBuff);

#ifdef XXX 
	static UINT uCount = 0;
	static BOOL bFlag = FALSE;
	
	if(bFlag == FALSE){
		uCount++;
		//TRACE("WAIT......%d........\n",uCount);
	}

	if(uCount == 25){
		AfxMessageBox(" ForeGround Color will be Set");
		m_TlTipStc.SetFGColor(15,10,200);
	}

	if(uCount == 30){
		AfxMessageBox("Background Color will be Set");
		m_TlTipStc.SetBGColor(255,20,20);
	}
	
	if(uCount == 33){
		AfxMessageBox("ForeGround Color of ToolTip will be Set");
		m_TlTipStc.SetToolTipFGColor(50,250,120);
	}
	if(uCount == 35){
		AfxMessageBox(" Background Color of ToolTip will be Set");;
		m_TlTipStc.SetToolTipBGColor(200,150,175);
		bFlag = TRUE;
		uCount++;
	}
#endif //XXX	
}

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
me a VC++ programmer

Comments and Discussions