Click here to Skip to main content
15,881,744 members
Articles / Multimedia / GDI

Custom Captions (Including Multi-line Captions)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (9 votes)
15 Jul 2000CPOL 240.1K   6.8K   63  
Simple customised Window captions, including multi-line captions
////////////////////////////
// An extended multi-line caption class with fixes for the Windows 95/NT caption
// overwrite 'feature' that causes a normal window caption to be drawn
// when non-client area mouse activity occurs after the system menu has been 
// displayed.
//
//	Author: Dave Lorde	(dlorde@cix.compulink.co.uk)
//
//          Copyright January 2000
//

#include "StdAfx.h"
#include "MultiLineCaptionEx.h"
#include "SuppressStyle.h"

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

IMPLEMENT_DYNAMIC(CMultiLineCaptionEx, CMultiLineCaption); 

namespace {
	const int CaptionMouseClick = 0xF012;
}

CMultiLineCaptionEx::CMultiLineCaptionEx(int maxLines)
	:CMultiLineCaption(maxLines)
{}

LRESULT CMultiLineCaptionEx::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
{
	switch (msg) 
	{
	case WM_SETCURSOR:
		return OnSetCursor( (HWND)wp, LOWORD(lp), HIWORD(lp) );

	case WM_SYSCOMMAND:
		OnSysCommand(wp, lp );
		return 0;

	case WM_SIZE:
		OnSize((UINT)wp, LOWORD(lp), HIWORD(lp));
		return 0;

	case WM_INITMENUPOPUP:
		OnInitMenuPopup( CMenu::FromHandle((HMENU)wp), LOWORD(lp), HIWORD(lp));
		return 0;
	}
	// I don't handle it: pass along
	return CMultiLineCaption::WindowProc(msg, wp, lp);
}


void CMultiLineCaptionEx::OnSysCommand(UINT nID, LPARAM lp)
{
	// I don't know why, but clicking on the caption triggers a SysCommand
	// with ID 0xf12. Unless the caption is painted before handling it,
	// the nasty caption line shows

	if (nID == CaptionMouseClick)
		PaintCaption();

	Default();
}

BOOL CMultiLineCaptionEx::OnSetCursor( HWND hWnd, UINT nHitTest, UINT message )
{
	LRESULT res = 0;
	{
		SuppressStyle ss(hWnd, WS_VISIBLE);

		res = Default();

		if (nHitTest != HTHSCROLL && nHitTest != HTVSCROLL && nHitTest != HTSYSMENU &&
	 		nHitTest != HTTRANSPARENT  && nHitTest != HTNOWHERE && nHitTest != HTCLIENT)
		{
			PaintCaption();
		}
	}
	return res;
}

void CMultiLineCaptionEx::OnSize(UINT nType, int cx, int cy)
{
//	SuppressStyle ss(m_pWndHooked->m_hWnd, WS_VISIBLE);

//	Default();
	CMultiLineCaption::OnSize(nType, cx, cy);
	
//	PaintCaption();
}

void CMultiLineCaptionEx::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu)
{
	SuppressStyle ss(m_pWndHooked->m_hWnd, WS_VISIBLE);

	Default();
		
	PaintCaption();
}

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
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions