Share via


Aggiunta di funzioni di callback a un'applicazione

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

  • Lo stato cambia
  • Si verificano errori
  • I buffer video e audio diventano disponibili
  • L'applicazione deve restituire durante l'acquisizione di streaming

L'esempio seguente crea una finestra di acquisizione e registra lo stato, l'errore, il flusso video e le funzioni di callback frame 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 funzioni di callback di stato, errore e frame semplici.

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 di Acquisizione video