Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

MFC extension library - A plugin to handle owner drawn menus

, 11 May 2004
Continuation of the Plugin Architecture series
// ODMenu.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "resource.h"
#include <afxdllx.h>
#include <winuser.h>
#include "ODMenu.h"

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

static AFX_EXTENSION_MODULE ODMenuDLL = { NULL, NULL };

HINSTANCE	hDLLInstance = NULL ;

extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
	// Remove this if you use lpReserved
	UNREFERENCED_PARAMETER(lpReserved);

	if (dwReason == DLL_PROCESS_ATTACH)
	{
		TRACE0("ODMenu.DLL Initializing!\n");
		
		// Extension DLL one-time initialization
		if (!AfxInitExtensionModule(ODMenuDLL, hInstance))
			return 0;

		// Insert this DLL into the resource chain
		// NOTE: If this Extension DLL is being implicitly linked to by
		//  an MFC Regular DLL (such as an ActiveX Control)
		//  instead of an MFC application, then you will want to
		//  remove this line from DllMain and put it in a separate
		//  function exported from this Extension DLL.  The Regular DLL
		//  that uses this Extension DLL should then explicitly call that
		//  function to initialize this Extension DLL.  Otherwise,
		//  the CDynLinkLibrary object will not be attached to the
		//  Regular DLL's resource chain, and serious problems will
		//  result.

		new CDynLinkLibrary(ODMenuDLL);
		hDLLInstance = hInstance ;
	}
	else if (dwReason == DLL_PROCESS_DETACH)
	{
		TRACE0("ODMenu.DLL Terminating!\n");
		// Terminate the library before destructors are called
		AfxTermExtensionModule(ODMenuDLL);
	}
	return 1;   // ok
}

extern "C" void MergeMenu(CMyMultiDocTemplate *pTemplate)
{
#ifdef _DEBUG
    // only merge menu option in debug mode
	ASSERT(pTemplate != NULL) ;
	// Note that the default menu for the mainframe will have a GetDocClass of ""
	if (_tcscmp("CAppPlugInCoreDoc", pTemplate->GetDocClass()) == 0)
	{
		CMenu	docMenu ;
		CMenu	append ;

		docMenu.Attach(pTemplate->m_hMenuShared) ;
		append.LoadMenu(IDR_MENU) ;
		VERIFY(PIMergeMenu(&docMenu, &append, true)) ;
		docMenu.Detach() ;
	}
#else
    UNREFERENCED_PARAMETER(pTemplate);
#endif
}

extern "C" void InitialiseDLL()
{
	CODMenu::EnumerateAndLoadToolbars();
}

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)

Share

About the Author

Roger Allen
Software Developer (Senior) Sirius Analytical Instruments
United Kingdom United Kingdom
A research and development programmer working for a pharmaceutical instrument company for the past 17 years.
 
I am one of those lucky people who enjoys his work and spends more time than he should either doing work or reseaching new stuff. I can also be found on playing DDO on the Cannith server (Send a tell to "Maetrim" who is my current main)
 
I am also a keep fit fanatic, doing cross country running and am seriously into [url]http://www.ryushinkan.co.uk/[/url] Karate at this time of my life, training from 4-6 times a week and recently achieved my 1st Dan after 6 years.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 12 May 2004
Article Copyright 2004 by Roger Allen
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid