OptimizedHotkey Example for C++ 5.0 and later

   //Create the RasterScr object
   CoCreateInstance(CLSID_LEADRasterScr, NULL, CLSCTX_ALL, IID_ILEADRasterScr, (void**)&m_pLEADRasterScr);

void CMFCDlg::OnButton1() 
{
   //Instantiate the sink class and hold a pointer to it.
   m_pRasterScrSink = new CRasterScrSink;
   m_pRasterScrSink->m_pDlg = this;
   //Establish a connection between source and sink.
   LPUNKNOWN pUnkSink = m_pRasterScrSink->GetIDispatch(FALSE);
   AfxConnectionAdvise(m_pLEADRasterScr, DIID__LTSCREvents, pUnkSink, FALSE, &m_dwCookie);

   //set cancel key to ESC
   m_pLEADRasterScr->CaptureCancelKey = VK_ESCAPE;
   
   //set hotkey
   m_pLEADRasterScr->CaptureHotKey = 123;/*F12*/
   
   //enable optimized hotkey
   m_pLEADRasterScr->OptimizedHotkey = TRUE;
   
   //start the captures
   m_pLEADRasterScr->CaptureActiveWindow();
}

void CMFCDlg::OnDestroy() 
{
   //Terminate connection between source and sink
   LPUNKNOWN pUnkSink = m_pRasterScrSink->GetIDispatch(FALSE);
   AfxConnectionUnadvise(m_pLEADRasterScr, DIID__LTSCREvents, pUnkSink, FALSE, m_dwCookie);
   delete m_pRasterScrSink;

   m_pLEADRasterScr->StopCapture ();
   m_pLEADRasterScr->Release();
 CDialog::OnDestroy();
}

void CRasterScrSink::OnCaptureImage(long CaptureNumber)
{
   // get the captured image here
   m_pDlg->m_LEADRasterView1.GetRaster().SetBitmap(m_pDlg->m_pLEADRasterScr->GetBitmap());
}