Click here to Skip to main content
15,891,864 members
Articles / Programming Languages / C++

How to add dynamic menus to your application using DLLs

Rate me:
Please Sign up or sign in to vote.
4.08/5 (16 votes)
25 Nov 20054 min read 45.6K   1.3K   44  
How to add dynamic menus to your application using DLLs, if you want to support add-ons to your base application.
// MainFrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_MAINFRM_H__6476E732_4B35_42AA_AD80_89D4A3680827__INCLUDED_)
#define AFX_MAINFRM_H__6476E732_4B35_42AA_AD80_89D4A3680827__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

typedef int (__cdecl  *NUMMENUPTR)(void);
typedef bool (__cdecl  *MENUTEXTPTR)(int ,CString&);
typedef bool (__cdecl *MENUTITLEPTR)(CString&);
typedef bool (__cdecl *MENUFUNCTIONPTR)(int);

struct DllStructure
{
	HINSTANCE m_hInst;
	UINT m_uStartID;
	int m_nMenu;
	MENUFUNCTIONPTR m_pFn;
};

class CMainFrame : public CFrameWnd
{

	CArray <DllStructure,DllStructure&> m_Dlls;
protected: // create from serialization only
	CMainFrame();
	DECLARE_DYNCREATE(CMainFrame)

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMainFrame)
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CMainFrame();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif
	void AddonMenus();
	BOOL AddPopUp(CString str,CMenu*pMenu);
protected:  // control bar embedded members
	CStatusBar  m_wndStatusBar;
	CToolBar    m_wndToolBar;

// Generated message map functions
protected:
	//{{AFX_MSG(CMainFrame)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
		// NOTE - the ClassWizard will add and remove member functions here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	afx_msg void DllFunctions(UINT nID);
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MAINFRM_H__6476E732_4B35_42AA_AD80_89D4A3680827__INCLUDED_)

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Kingdom United Kingdom
I am a visual C++ programmer, currently working in Industrial Control Systems in Sheffield, United Kingdom as a Senior Programmer and Researcher. You can contact me by sending email to farhat_aisha2000@yahoo.com

Comments and Discussions