Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2006

Tip: Looking for answers? Try searching our database.

Delegates and unmanaged CPP

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Egbert Nierop (MVP for IIS) - 15 Mar 2006 11:26 GMT
Hi,

I have a class, see below, that needs to be subclassed in a dialog.
Inside the dialog (OnInitDialog), I need something like this.

m_MyControl.SubclassWindow(GetDlgItem(IDC_MyControl).m_hWnd);

m_MyControl.SetMouseHover(reinterpret_cast
<CMouseHover::ONMOUSEHOVER>(&mainWin::OnMouseHover)); //

Line above, will produce a casting error. I've seen some articles on this
theme http://www.progdoc.de/papers/chameleon/value/value.html but I simply
don't get it.

What can I do to fix this?

Thanks!

// for Subclassing controls so we have support for OnMouseHover and
OnMouseLeave
class CMouseHover: public CWindowImpl<CMouseHover>
{
public:
CMouseHover():  m_bIsMouseOver(false) , OnMouseHover(NULL),
OnMouseLeave(NULL)
{
}

//declare event signature
typedef void (CALLBACK* ONMOUSEHOVER)(int nFlags, int ID, POINT pt);
typedef void (CALLBACK* ONMOUSELEAVE)(int ID);
void SetMouseHover(ONMOUSEHOVER ptr) throw()
{
 OnMouseHover =  ptr;
}
ONMOUSEHOVER OnMouseHover;
ONMOUSELEAVE OnMouseLeave;
private:

bool m_bIsMouseOver;
BEGIN_MSG_MAP(CMouseHover)
 MESSAGE_HANDLER(WM_MOUSEHOVER, OnMouseHover_System)
 MESSAGE_HANDLER(WM_MOUSELEAVE, OnMouseLeave_System)
 MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove_System)
END_MSG_MAP()

LRESULT OnMouseHover_System(UINT, WPARAM wParam, LPARAM lParam, BOOL&)
throw()
{
 if (OnMouseHover != NULL)
 {
  POINT pt ={GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
  UINT nFlags = (UINT)wParam;
  OnMouseHover(nFlags, GetDlgCtrlID(), pt);
 }
 return FALSE;
}
LRESULT OnMouseLeave_System(UINT, WPARAM, LPARAM, BOOL&) throw()
{
 if (OnMouseLeave != NULL)
 {
  TRACKMOUSEEVENT evntTrack;
  evntTrack.cbSize = sizeof(TRACKMOUSEEVENT);
  evntTrack.hwndTrack = m_hWnd;
  evntTrack.dwHoverTime = HOVER_DEFAULT;
  evntTrack.dwFlags = TME_CANCEL | TME_LEAVE | TME_HOVER;
  TrackMouseEvent(&evntTrack);
  m_bIsMouseOver = false;
  OnMouseLeave(GetDlgCtrlID());
 }
 return 0;
}
LRESULT OnMouseMove_System(UINT, WPARAM, LPARAM, BOOL&) throw()
{
 ATLASSERT(::IsWindow(m_hWnd));
 if (!m_bIsMouseOver)
 {
  TRACKMOUSEEVENT evntTrack;
  evntTrack.cbSize = sizeof(TRACKMOUSEEVENT);
  evntTrack.hwndTrack = m_hWnd;
  evntTrack.dwHoverTime = HOVER_DEFAULT;
  evntTrack.dwFlags = TME_LEAVE | TME_HOVER;
  if (TrackMouseEvent(&evntTrack) == TRUE)
   m_bIsMouseOver = true;
 }
 //must return zero
 return FALSE;
}
};
Egbert Nierop (MVP for IIS) - 15 Mar 2006 16:18 GMT
Should read as...

I have a class, see below, that needs to subclass controls.
Egbert Nierop (MVP for IIS) - 17 Mar 2006 00:09 GMT
Hi,

I have a CWindowImpl derived class , see below, that needs to subclass .

Inside the dialog (OnInitDialog), I need something like this.

m_MyControl.SubclassWindow(GetDlgItem(IDC_MyControl).m_hWnd);

==> problem here

m_MyControl.SetMouseHover(
   reinterpret_cast<CMouseHover::ONMOUSEHOVER>(&mainWin::myMemberFunction)
   );

Compiler will return a casting error.

What can I do to fix this?

Thanks!

// for Subclassing controls so we have support for OnMouseHover and
OnMouseLeave
class CMouseHover: public CWindowImpl<CMouseHover>
{
public:
CMouseHover():  m_bIsMouseOver(false) , OnMouseHover(NULL),
OnMouseLeave(NULL)
{
}

//declare event signature
typedef void (CALLBACK* ONMOUSEHOVER)(int nFlags, int ID, POINT pt);
typedef void (CALLBACK* ONMOUSELEAVE)(int ID);

void SetMouseHover(ONMOUSEHOVER ptr) throw()
{
 OnMouseHover =  ptr;
}
ONMOUSEHOVER OnMouseHover;
ONMOUSELEAVE OnMouseLeave;
private:

bool m_bIsMouseOver;
BEGIN_MSG_MAP(CMouseHover)
 MESSAGE_HANDLER(WM_MOUSEHOVER, OnMouseHover_System)
 MESSAGE_HANDLER(WM_MOUSELEAVE, OnMouseLeave_System)
 MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove_System)
END_MSG_MAP()

LRESULT OnMouseHover_System(UINT, WPARAM wParam, LPARAM lParam, BOOL&)
throw()
{
 if (OnMouseHover != NULL)
 {
  POINT pt ={GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
  UINT nFlags = (UINT)wParam;
   //signal our delegate
  OnMouseHover(nFlags, GetDlgCtrlID(), pt);
 }
 return FALSE;
}

LRESULT OnMouseLeave_System(UINT, WPARAM, LPARAM, BOOL&)
{
 if (OnMouseLeave != NULL)
 {
  TRACKMOUSEEVENT evntTrack;
  evntTrack.cbSize = sizeof(TRACKMOUSEEVENT);
  evntTrack.hwndTrack = m_hWnd;
  evntTrack.dwHoverTime = HOVER_DEFAULT;
  evntTrack.dwFlags = TME_CANCEL | TME_LEAVE | TME_HOVER;
  TrackMouseEvent(&evntTrack);
  m_bIsMouseOver = false;
   //signal delegate
  OnMouseLeave(GetDlgCtrlID());
 }
 return 0;
}
LRESULT OnMouseMove_System(UINT, WPARAM, LPARAM, BOOL&)
{
 ATLASSERT(::IsWindow(m_hWnd));
 if (!m_bIsMouseOver)
 {
  TRACKMOUSEEVENT evntTrack;
  evntTrack.cbSize = sizeof(TRACKMOUSEEVENT);
  evntTrack.hwndTrack = m_hWnd;
  evntTrack.dwHoverTime = HOVER_DEFAULT;
  evntTrack.dwFlags = TME_LEAVE | TME_HOVER;
  if (TrackMouseEvent(&evntTrack) == TRUE)
   m_bIsMouseOver = true;
 }
 return FALSE;
}
};

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.