Forum Navigation
Signal/Slot instead of MFC/wxWidgets MSG-MAP
Posted: 09/20/07 12:50:53 Modified: 09/20/07 12:59:53Hi, I've tried to translate some C++ stuff into D. The D port has Bugs, However the intention should be clear. As you can see I have tried to translate the MSG_MAP macros into D templates. However, the question is, it possible to replace the MSG_MAP code using Tango's Signal/Slot... implementation ?
/* THE C++ Stuff. (Just a fragment. D port a few lines later)
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?)
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 the templates have bugs... may be I should use :
template ON_WM_CLOSE(D) {
alias D delegate() dg; if (uID == WM_CLOSE) {
lResult = dg(); return lResult;
}
}
However, the BIG question is, can I use Signal/Slot instead. If yes : How :-) I really need some advice. Thanks
Bjoern












