Condividi tramite


Aggiunta di funzioni di callback a un'applicazione

Un'applicazione può registrare le funzioni di callback con la finestra di acquisizione in modo da notificare all'applicazione nelle circostanze seguenti:

  • Lo stato cambia
  • Si verificano errori
  • I frame video e i buffer audio diventano disponibili
  • L'applicazione dovrebbe cedere durante la cattura in streaming

L'esempio seguente crea una finestra di acquisizione e registra lo stato, l'errore, il flusso video e le funzioni di callback dei fotogrammi nel ciclo di elaborazione dei messaggi di un'applicazione. Include anche un'istruzione di esempio per disabilitare una funzione di callback. Gli esempi successivi mostrano semplici funzioni di callback per lo stato, gli errori e i frame.

case WM_CREATE: 
{ 
    char    achDeviceName[80] ; 
    char    achDeviceVersion[100] ; 
    char    achBuffer[100] ; 
    WORD    wDriverCount = 0 ; 
    WORD    wIndex ; 
    WORD    wError ; 
    HMENU   hMenu ; 
 
    // Create a capture window using the capCreateCaptureWindow macro.
    ghWndCap = capCreateCaptureWindow((LPSTR)"Capture Window", 
        WS_CHILD | WS_VISIBLE, 0, 0, 160, 120, (HWND) hWnd, (int) 0); 
 
    // Register the error callback function using the 
    // capSetCallbackOnError macro. 
    capSetCallbackOnError(ghWndCap, fpErrorCallback); 
 
    // Register the status callback function using the 
    // capSetCallbackOnStatus macro. 
    capSetCallbackOnStatus(ghWndCap, fpStatusCallback); 
 
    // Register the video-stream callback function using the
    // capSetCallbackOnVideoStream macro. 
    capSetCallbackOnVideoStream(ghWndCap, fpVideoCallback); 
 
    // Register the frame callback function using the
    // capSetCallbackOnFrame macro. 
    capSetCallbackOnFrame(ghWndCap, fpFrameCallback); 
 
    // Connect to a capture driver 

    break; 
} 
case WM_CLOSE: 
{ 
// Use the capSetCallbackOnFrame macro to 
// disable the frame callback. Similar calls exist for the other 
// callback functions.

    capSetCallbackOnFrame(ghWndCap, NULL); 

    break; 
} 
 

Uso dell'acquisizione video