Click here to Skip to main content
15,891,765 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 532.7K   12.1K   201  
An application/add-in to organise and renumber resource symbol IDs
////////////////////////////////////////////////////////////////
// TRACEWIN Copyright 1995-1996 Microsoft Systems Journal. 
// If this program works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// TRACEWIN is a development tool that displays MFC TRACE output in
// a window, even if you don't run under the debugger. To use tracewin,
// simply #include this file in your main .cpp file, the one that contains
// your CWinApp-derived app, and call 
//
//		MfxTraceInit();
//
// from your app's InitInstance function. You also need the TRACEWIN applet
// itself, which you can download from any MSJ bulletin board. NOTE: since 
// TraceWin.h contains code, you should only #include it in once place in
// your app. (Don't #include it in stdafx.h.)
//
// NOTE: I would have defined a static instance to initialize MfxTrace, so
// calling MfxTraceInit would be unecessary, but there's a problem with the
// order of intializations. CFileTrace requires that afxDump be initialized
// first, which can fail to happen if CFileTrace is initialized as a static
// object.
//
// Modification history
// 4-1-95:   Created
// 10-12-95: Use WM_COPYDATA instead of atoms. Also note the name of this 
//           file is changed to TRACEWIN.H.
// 11-10-95: Added "Keep WIndow on Top" feature and fixed a bug 
//           relating to saved window pos.
// 11-15-95: Save/Restore position with CWindowPlacement.
// 12-05-95: Implemented tracer object with "new" instead of static, so
//           it remains around for reporting memory leaks, if any.

#ifdef _WIN32	// TraceWin only used for WIN32

#define TRACEWND_CLASSNAME "MfxTraceWindow"

// This ID is sent as COPYDATASRUCT::dwData to identify the WM_COPYDATA
// message as coming from an app using TRACEWIN. 
//
#define ID_COPYDATA_TRACEMSG MAKELONG(MAKEWORD('t','w'),MAKEWORD('i','n'))

#ifdef _DEBUG

//////////////////
// CFileTrace looks like a CFile, but "writes" to the trace window
//
class CFileTrace : public CFile {
	CFileTrace()  { }			// private constructor
public:
	virtual void Write(const void* lpBuf, UINT nCount);
	static void Init();
};

/////////////////
// Initialize tracing. Replace global afxDump.m_pFile with me.
//
void CFileTrace::Init()
{
	// This initialization function creates the only instance ever
	// of a CFileTrace object, and it's never deleted. This gurantees
	// that when MFC gets around to reporting memory leaks, they will
	// show up in the TRACEWIN window. If I were to instantiate CFileTrace 
	// as a static object, it would be destructed before the CRT gets
	// around to reporting memory leaks, and the information would be lost.

	static CFileTrace* pTracer;
	if (afxDump.m_pFile == NULL) {
		// Since I don't want this allocation to be reported as a leak,
		// turn off memory tracking
		BOOL bEnable = AfxEnableMemoryTracking(FALSE);
		afxDump.m_pFile = pTracer = new CFileTrace; //&theTracer;
		AfxEnableMemoryTracking(bEnable);

	} else if (afxDump.m_pFile != pTracer)
		TRACE("afxDump is already using a file; TRACEWIN not installed.\n");
}

//////////////////
// Override to Write to TRACEWIN applet instead of file.
//
void CFileTrace::Write(const void* lpBuf, UINT nCount)
{
	if (!afxTraceEnabled)
		return;

	CWnd *pTraceWnd = CWnd::FindWindow(TRACEWND_CLASSNAME, NULL);
	if (pTraceWnd) {
		// Found Trace window: send string with WM_COPYDATA
		//
		COPYDATASTRUCT cds;
		cds.dwData = ID_COPYDATA_TRACEMSG;
		cds.cbData = nCount;
		cds.lpData = (void*)lpBuf;
		CWinApp* pApp = AfxGetApp();
		pTraceWnd->SendMessage(WM_COPYDATA, 
			pApp ? (WPARAM)pApp->m_pMainWnd->GetSafeHwnd() : 0,
			(LPARAM)&cds);

	} else {
		// No trace window: do normal debug thing
		::OutputDebugString((LPCSTR)lpBuf);	
	}
}

#define MfxTraceInit CFileTrace::Init

#else  // Not _DEBUG

#define MfxTraceInit()

#endif // _DEBUG

#else  // Not _WIN32

#define MfxTraceInit()

#endif // _WIN32

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