C++ Macro to D mixin template, delegates Please help

BLS nanali at nospam-wanadoo.fr
Thu Sep 20 07:29:59 PDT 2007


Please have a look on my translation.
Problems are
1) porting C++ macros
2) use of delegates within template mixins

/*  THE C++ Stuff , a fragment
class CMsg
{
public:

	virtual BOOL NewMsgProc(HWND hWnd, UINT uID, WPARAM wParam, LPARAM 
lParam,LRESULT lResult)
	{
		return FALSE;
	}
};


#define BEGIN_MSG_MAP() \
public: \
	virtual BOOL NewMsgProc(HWND hWnd, UINT uID, WPARAM wParam, LPARAM 
lParam,LRESULT& lResult) \
	{ \
		

#define ON_WM_CLOSE(vfunc)\
	if (uID == WM_CLOSE) \
	{ \
		lResult =vfunc(); \
		return lResult; \
	}

// and so on ............



class CWin : public CMsg
{

public:	

	virtual BOOL OnClose()
	{
		return TRUE;
	}


     BEGIN_MSG_MAP()
         ON_WM_CLOSE(OnClose)
         ON_WM_DESTROY(OnDestroy)
         ON_WM_NCDESTROY(OnNcDestroy)
     END_MSG_MAP_DEFAULT()
	

}

EOF C++ stuff */

THE D port
module dgt.win;

  // All Window's messages will be mapped in this function
class CMsg
{
public:

     bool NewMsgProc(HWND hWnd, UINT uID, WPARAM wParam, LPARAM 
lParam,LRESULT lResult)
     {
         return false;
     }

}

template ON_WM_CLOSE(D) (D delegate() dg)
{
     if (uID == WM_CLOSE)
     {
         lResult = dg();
         return lResult;
     }
}

template ON_MESSAGE_RANGE(M1, M2, D) (M1 MsgF, M2 MsgL, D delegate(...) dg )
{
     if(uID >= MsgF && uID <= MsgL)
      {
         lResult = dg(uID, wParam, lParam);
          return true;
      }
}



// Window
  class CWin : CMsg
{

public:	
     bool onClose()
     {
         return true;
     }

     override bool NewMsgProc(HWND hWnd, UINT uID, WPARAM wParam, LPARAM 
lParam, ref LRESULT lResult)
     {
         mixin ON_WM_CLOSE!(&CWin.OnClose);
     }
}

--------------------
Okay, I've ported it as good as I can... the available tutorials are not 
very helpfull in this case. So please help
Bjoern


More information about the Digitalmars-d-learn mailing list