Click here to Skip to main content
15,860,861 members
Articles / Desktop Programming / MFC

Resource ID Organiser Add-In for Visual C++ 5.0/6.0/.NET

Rate me:
Please Sign up or sign in to vote.
4.98/5 (71 votes)
10 Jan 2005CPOL25 min read 527.5K   12.1K   201  
An application/add-in to organise and renumber resource symbol IDs
// Copyright (c) Iuri Apollonio 1998
// Use & modify as you want & need, and leave those 4 lines.
// Strongly based on article "Inplace edit control" of Mario Contestabile and "Editable subitems" of Zafir
// http://www.codeguru.com
//
// GfxGroupEdit.cpp : implementation file
//
/////////////////////////////////////////////////////////////////////////////
/****************************************************************************
 *
 * $Date: 10/14/99 12:41p $
 * $Revision: 4 $
 * $Archive: /CodeJock/CJLibrary/GfxGroupEdit.cpp $
 *
 * $History: GfxGroupEdit.cpp $
 * 
 * *****************  Version 4  *****************
 * User: Kirk Stowell Date: 10/14/99   Time: 12:41p
 * Updated in $/CodeJock/CJLibrary
 * Added source control history to file header.
 *
 ***************************************************************************/
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "GfxGroupEdit.h"
#include "GfxOutBarCtrl.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGfxGroupEdit

CGfxGroupEdit::CGfxGroupEdit()
{
	bEscapeKey = FALSE;
	iIndex = -1;
	msgSend = NM_OB_ONGROUPENDEDIT;
	bNoDown = false;
}

CGfxGroupEdit::~CGfxGroupEdit()
{
}


BEGIN_MESSAGE_MAP(CGfxGroupEdit, CEdit)
	//{{AFX_MSG_MAP(CGfxGroupEdit)
	ON_WM_KILLFOCUS()
	ON_WM_CREATE()
	ON_WM_CHAR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGfxGroupEdit message handlers

void CGfxGroupEdit::OnKillFocus(CWnd* /*pNewWnd*/) 
{
	PostMessage(WM_CLOSE, 0, 0);
	if (!bEscapeKey)
	{
		GetWindowText(text);
		if (text != "") GetOwner()->SendMessage(WM_OUTBAR_NOTIFY, msgSend, (LPARAM) this);
	}
}

BOOL CGfxGroupEdit::PreTranslateMessage(MSG* pMsg) 
{
	if (pMsg->wParam == VK_RETURN)
	{
		PostMessage(WM_CLOSE, 0, 0);
		return TRUE;
	}
	else if (pMsg->wParam == VK_ESCAPE)
	{
		PostMessage(WM_CLOSE, 0, 0);
		return bEscapeKey = TRUE;
	}
	
	return CEdit::PreTranslateMessage(pMsg);
}

void CGfxGroupEdit::PostNcDestroy() 
{
	CEdit::PostNcDestroy();
	delete this;
}

int CGfxGroupEdit::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CEdit::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	SendMessage(WM_SETFONT,(WPARAM) GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
	return 0;
}

void CGfxGroupEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if (msgSend == NM_OB_ONGROUPENDEDIT)
	{
		CEdit::OnChar(nChar, nRepCnt, nFlags);
		return;
	}

	if (nChar == VK_ESCAPE || nChar == VK_RETURN)
	{
		if (nChar == VK_ESCAPE) bEscapeKey = TRUE;
		GetParent()->SetFocus();
		return;
	}
	CEdit::OnChar(nChar, nRepCnt, nFlags);
	CString str;
	CRect rect, parentrect;
	GetClientRect(&rect);
	GetParent()->GetClientRect(&parentrect);
	ClientToScreen(&rect);
	GetParent()->ScreenToClient(&rect);
	GetWindowText(str);
	CWindowDC dc(this);
	CFont *pFont = GetParent()->GetFont();
	CFont *pFontDC = dc.SelectObject(pFont);
	CRect szrc(rect);
	szrc.bottom = szrc.top;

	if (bNoDown == true)
	{
		dc.DrawText(str, szrc, DT_CALCRECT);
		if (szrc.right >= parentrect.right - 1) rect.right = parentrect.right - 1;
		else rect.right = szrc.right;
		MoveWindow(&rect);
		return;
	}

	dc.DrawText(str, szrc, DT_WORDBREAK|DT_CENTER|DT_CALCRECT);
	dc.SelectObject(pFontDC);
	CSize size = szrc.Size();

	if (size.cx > rect.Width())
	{
		if (size.cx + rect.left < parentrect.right) rect.right = rect.left + size.cx;
		else rect.right = parentrect.right;
		MoveWindow(&rect);
	}
	else if (size.cy > rect.Height())
	{
		if (size.cy + rect.bottom < parentrect.bottom) rect.bottom = rect.top + size.cy;
		else rect.bottom = parentrect.bottom;
		MoveWindow(&rect);
	}
}

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
Founder Riverblade Limited
United Kingdom United Kingdom
I haven't always written software for a living. When I graduated from Surrey University in 1989, it was with an Electronic Engineering degree, but unfortunately that never really gave me the opportunity to do anything particularly interesting (with the possible exception of designing Darth Vader's Codpiece * for the UK Army in 1990).
    * Also known as the Standard Army Bootswitch. But that's another story...
Since the opportunity arose to lead a software team developing C++ software for Avionic Test Systems in 1996, I've not looked back. More recently I've been involved in the development of subsea acoustic navigation systems, digital TV broadcast systems, port security/tracking systems, and most recently software development tools with my own company, Riverblade Ltd.

One of my personal specialities is IDE plug-in development. ResOrg was my first attempt at a plug-in, but my day to day work is with Visual Lint, an interactive code analysis tool environment with works within the Visual Studio and Eclipse IDEs or on build servers.

I love lots of things, but particularly music, photography and anything connected with history or engineering. I despise ignorant, intolerant and obstructive people - and it shows...I can be a bolshy cow if you wind me up the wrong way...Laugh | :laugh:

I'm currently based 15 minutes walk from the beach in Bournemouth on the south coast of England. Since I moved here I've grown to love the place - even if it is full of grockles in Summer!

Comments and Discussions