PDFViewCtrl::SetCustomEventHandlers example

Hi,

I have just started using the PDFNet C++ SDK. I am using the PDFViewCtrl control to display PDFs and now wish to customise mouse event handling in the display window. To do this I assume that I need to set a custom MouseEventHandler using the PDFViewCtrl method SetCustomEventHandlers(), however everything I have tried has resulted in a compilation error of one type or another.

The basic structure of what I have attempted is:

  UInt8 mouseDown(struct MouseEvent* evt, void* custom_data)
  {
    // ... Code to handle mouse down events ...
    return 1;
  }

With, in the constructor of a class that inherits from PDFViewCtrl:

  EventHandlers* customTools = new EventHandlers();
  customTools->mouse_left_down = &mouseDown;
  SetCustomEventHandlers(customTools);

I have tried numerous variations on this basic theme, but without success.

I would be very grateful if someone could point me in the direction of a simple example or code snippet showing the correct way to customise mouse event handling.

Many thanks in advance for your help.

Terry.

The approach you’re following is the correct one. For an example, see the C++ PDFViewSimple test’s “MyMouseDoubleClickEvent” in https://www.pdftron.com/pdfnet/samplecode/PDFViewSimple.cpp.html

Hi Aaron,

Many thanks for your helpful reply. I’m surprised I missed the code in your link because before posting my question I Googled for just about every relevant keyword I could think of! Anyhow, your link was very helpful in confirming that my general approach was correct which led me to realise the real cause of my problem, which was that my event handler ‘mouseDown’ was actually a member function of my class that inherits from PDFViewCtrl (I should have made this clear in my code snippet, sorry my mistake). And, of course, it is incorrect to try to get a pointer to a class member function in this manner. As soon as I changed ‘mouseDown’ to a non-member function my code worked.

Thank you for helping to solve my problem.

Terry.