BeforeClick event cancel not working with VC++

mayfly
05-02-2007, 04:25 AM
When using a MapPoint 2006 control in a VC++ MFC dialog application, setting the Cancel output argument seems to have no effect for me.

The relevant code is:

.h ...

afx_msg void OnBeforeClickMap(long Button, long Shift, long X, long Y, BOOL FAR* Cancel);
DECLARE_EVENTSINK_MAP()
//}}AFX_MSG

.cpp ...

BEGIN_EVENTSINK_MAP(MainDialog, CDialog)
//{{AFX_EVENTSINK_MAP(MainDialog)
ON_EVENT(MainDialog, IDC_MAP_CONTROL, 209 /* BeforeClick */, OnBeforeClickMap, VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_PBOOL)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void TestDialog::OnBeforeClickMap(long Button, long Shift, long X, long Y, BOOL FAR* Cancel)
{
*Cancel = TRUE;
}

The callback is entered OK, with Button, Shift, X and Y as expected and *Cancel FALSE, but the control is still responding to the click events.

Judging from other posts, this obviously works with VB and C# etc. Does anyone know why it should be a problem with VC++ (6)?

Thanks.

Wilfried
05-03-2007, 05:00 AM
It is first time that I see this question. But eventually try to set it to 1 or to -1 (or 0xffffffff). I have seen already bugs like that among programming languages.

mayfly
05-05-2007, 07:27 AM
Thankyou Wilfried,

In hindsight, there was an earlier post on the web answering the question.

MP2K Magazine :: View topic - Canceling mouse clicks in C++ (http://mappointmag.com/mappoint/discussion/viewtopic.asp?p=6498)

It is a pity that Microsoft provides very liitle information about accessing this control from C++.

Wilfried
05-05-2007, 11:13 AM
Hi,

Glad to hear it works. So it is a WORD value. Theoretially null is False and everything else should evaluate to True but that is not the point in various programming languages. Even in same language you can have versions that behave different.

The -1 should normally work also because if it is a WORD value then it convert to 0xFFFF and if it is a DWORD then it would evaluate to 0xFFFFFFFF.

 
Web mp2kmag.com
mapforums.com