Mouse up event can’t be handled

Posted on Updated on

I want to get the event mouse up within a window.
I set event to event handler like:

static const EventTypeSpec kWindowEvents[] =
{
{ kEventClassCommand, kEventCommandProcess },
{ kEventClassMouse , kEventMouseMoved },
{ kEventClassMouse , kEventMouseUp },
{ kEventClassMouse , kEventMouseDown },
};

err = CreateWindowFromNib( sNibRef, CFSTR(“MainWindow"), &window );
require_noerr( err, CantCreateWindow );

InstallWindowEventHandler( window, GetWindowEventHandlerUPP(),
GetEventTypeCount( kWindowEvents ), kWindowEvents,
window, NULL );

RepositionWindow( window, NULL, kWindowCascadeOnMainScreen );
// The window was created hidden, so show it
ShowWindow( window );

CantCreateWindow:
return err;

but in my handler function, it just get MouseDown, MouseMove events. No MouseUp passed into handle function.

to solve this problem, add an event kEventClassControl/kEventControlTrack to your window.
mouse up then coulde be handled as the mouse pointer is in tracking area

OSStatus err;

static const EventTypeSpec kWindowEvents[] =
{
{ kEventClassCommand, kEventCommandProcess },
{ kEventClassMouse , kEventMouseMoved },
{ kEventClassMouse , kEventMouseUp },
{ kEventClassMouse , kEventMouseDown },
};

static const EventTypeSpec kControlEvents[] =
{
{ kEventClassControl , kEventControlTrack },
};

// Create a window. “MainWindow" is the name of the window object. This name is set in
// InterfaceBuilder when the nib is created.
err = CreateWindowFromNib( sNibRef, CFSTR(“MainWindow"), &window );
require_noerr( err, CantCreateWindow );

// Install a command handler on the window. We don’t use this handler yet, but nearly all
// Carbon apps will need to handle commands, so this saves everyone a little typing.
InstallWindowEventHandler( window, GetWindowEventHandlerUPP(),
GetEventTypeCount( kWindowEvents ), kWindowEvents,
window, NULL );

// Position new windows in a staggered arrangement on the main screen
RepositionWindow( window, NULL, kWindowCascadeOnMainScreen );

HIViewRef imgView ;
HIViewTrackingAreaRef outTrackingRef ;
HIViewTrackingAreaID trackID= { ‘tMid’ , 2010 };

err = HIViewFindByID(HIViewGetRoot(window), kCtrlIDCtrlHIImage, &imgView);

HIViewNewTrackingArea ( imgView, NULL, trackID, &outTrackingRef );
InstallControlEventHandler( imgView, GetCtrlEventHandlerUPP(),
GetEventTypeCount( kWindowEvents), kWindowEvents,
imgView,NULL);

// The window was created hidden, so show it
ShowWindow( window );

CantCreateWindow:
return err;

reference:
Carbon Event Handling Theory (ADC refereces)

廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s