Breaking change - OnNcHitTest

Breaking change - OnNcHitTest
September 16th, 2005 · 12 Comments

Alright, this is a really bad one. This line of code :-

ON_WM_NCHITTEST()

- which was compiling quite okay in VC++ 6 (and VC++ 7.1) suddenly throws this strange error message.

error C2440: 'static_cast' : cannot convert from 'UINT (__thiscall CPocket::* )(CPoint)' to 'LRESULT (__thiscall CWnd::* )(CPoint)'

And it also has a suggestion to fix the error that is even more confusing :-

Cast from base to derived requires dynamic_cast or static_cast

We are already using static_cast, aren't we?

Guess what? The return type for OnNcHitTest has been changed from UINT to LRESULT (only in the MFC source, the MSDN documentation still says UINT as of Beta 2) to accommodate for negative return values. Crappy part is that this was wizard generated code - we didn't even write it, damnit! The fix is to change UINT to LRESULT - though if you want to compile the same code for VC++ 6 and 7.1, you'd want to do what I did :-

//In header file

#if _MSC_VER >= 1400
afx_msg LRESULT OnNcHitTest(CPoint point);
#else
afx_msg UINT OnNcHitTest(CPoint point);
#endif
//In cpp file

#if _MSC_VER >= 1400
LRESULT CPocket::OnNcHitTest(CPoint point)
#else
UINT CPocket::OnNcHitTest(CPoint point)
#endif
{
#if _MSC_VER >= 1400
LRESULT nRet=CButton::OnNcHitTest(point);
#else
UINT nRet=CButton::OnNcHitTest(point);
#endif
//...

Took me a while to figure that one out! It's not even listed in the Breaking Changes page! :grrr:

Tags: C++ · VC++ 2005

12 responses so far ↓

  • 1 Alok // Sep 21, 2005 at 5:25 am

    Same condition apply for widly use ON_MESSAGE macro too..

  • 2 Indranil Datta // Sep 30, 2005 at 1:41 pm

    Hi,
    I am quite sure that you are right in this matter and the blog is excellent. I should not
    be ashemed that I don't know why if _MSC_VER >= 1400 ?? :->
    If you can elaborate on this, I will be happy.

  • 3 Scherbina Vladimir // Nov 5, 2005 at 9:39 pm

    Indranil, _MSC_VER defines the compiler version, so Nish just decided to change function prototype (CButton::OnNcHitTest) for a Beta2 compiler by using #if #else #endif statements.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值