Compartilhar via


SHCameraCapture

Windows Mobile SupportedWindows Embedded CE Not Supported

9/9/2008

O SHCameraCapture função inicia a caixa diálogo Camera Capture, que permite que o usuário para captura ainda imagens e vídeo clipes.

Syntax

HRESULT SHCameraCapture (
  PSHCAMERACAPTURE pshcc
);

Parameters

  • pshcc
    [In/Out] Referência a um SHCAMERACAPTURE estrutura, que contém informações que inicializa a SHCameraCapture function, and also contains a reference to the fully-qualified path-name of the captured picture file or video file.

Return Value

  • S_OK
    O método foi concluído com êxito.
  • S_FALSE
    O usuário cancelou a caixa diálogo Camera Capture.
  • E_OUTOFMEMORY
    Não há memória suficiente para salvar a imagem ou vídeo.
  • E_INVALIDARG
    Um inválido argumento foi especificado.
  • " HRESULT_FROM_WIN32 (ERROR_RESOURCE_DISABLED) "
    Esse erro indica que a câmera está desabilitada devido a um valor específico condição.

    Observação

    O valor de retorno específico é 0x800710D5, as opposed to o valor de retorno ERROR_RESOURCE_DISABLED de 0x000010D5.

Remarks

Quando o SHCameraCapture função retorna com êxito, a reserva apontada pelo **SHCAMERACAPTURE::**szFile contains the fully-qualified path-name of the picture file or video file.

Os criadores de aplicativo devem estar cientes que SHCameraCapture função pode causar o aplicativo chamado para parar de responder em casos onde o aplicativo chamado é minimizado e depois reativado enquanto a chamar para SHCameraCapture função ainda é bloqueio.

Uma seqüência de eventos possível pode ser da seguinte maneira:

  • Usuário inicia um aplicativo
  • Chamadas de aplicativo SHCameraCapture
  • Usuário minimiza o aplicativo enquanto a exibição da câmera está ativo
  • Usuário reativa o aplicativo

Em vez de ir voltar a exibição da câmera, o usuário verá o aplicativo chamado e ele irá parar responder.

Você deve assumir ambas as seguinte etapas para evitar esses tipos de problemas quando chamado este API:

  1. Não use o estilo janela WS_POPUP na janela que chama SHCameraCapture.
  2. Quando seu aplicativo está sendo reativado, determinar se ele é ainda bloqueio em um chamar para SHCameraCapture e se for, trazer a janela da câmera para o primeiro plano. Você pode localizar a janela da câmera pelo chamado FindWindow (texto ("View da câmera"), NULL).

O seguinte exemplo de código mostra como superar esse problema.

// The class name of the Camera window.
#define CAMERAWND_CLASSNAME TEXT("Camera View")
// The message to activate the Camera window.
#define WM_ACTIVATE_CAMERAVIEW WM_USER + 1
// The flag to determine if the Camera window is running.
BOOL g_bCameraRunning = FALSE;
// The sample function of calling SHCameraCapture()
HRESULT CameraCaptureExample(HWND hwndOwner, LPTSTR pszFilename)
{
   HRESULT hResult;
   SHCAMERACAPTURE shcc;
   // Set the SHCAMERACAPTURE structure.
   // Set g_bCameraRunning flag as TRUE before we call SHCameraCapture() function.
   g_bCameraRunning = TRUE;
   // Display the Camera Capture dialog.
   hResult = SHCameraCapture(&shcc);
   // Set g_bCameraRunning flag as FALSE after we called SHCameraCapture() function.
   g_bCameraRunning = FALSE;
   return hResult;
}
// The window procedure of app's window
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   switch (uMsg)
   {
      case WM_ACTIVATE:
         if (WA_ACTIVE == LOWORD(wParam) && g_bCameraRunning)
         {
            PostMessage(hwnd, WM_ACTIVATE_CAMERAVIEW, 0, 0);
         }
         break;
      case WM_ACTIVATE_CAMERAVIEW:
         if (g_bCameraRunning)
         {
            // Reactivate the camera window if camera window is running
            HWND hwndCamera = FindWindow(CAMERAWND_CLASSNAME, NULL);
            if (NULL != hwndCamera)
            {
               // Bring the last active window owned by camera window to the foreground
               SetForegroundWindow(GetLastActiveWindow(hwndCamera));
            }
         }
         break;
// Determine if hwnd is owned by hwndOwner.
BOOL IsOwned(HWND hwndOwner, HWND hwnd)
{
   BOOL bOwned = FALSE;
   while (NULL != (hwnd = GetWindow(hwnd, GW_OWNER)))
   {
      if (hwnd == hwndOwner)
      {
         bOwned = TRUE;
         break;
      }
   }
return bOwned;
}
// Get the topmost, visible, enabled window who is owned by the window
// which specified by the application-defined value given in EnumWindows.
BOOL CALLBACK EnumLastActiveWindowProc(HWND hwnd, LPARAM lParam)
{
   BOOL bContinue = TRUE;
   HWND hOwner = *((HWND *)lParam);
   // Ignore windows which are invisible, disabled or cannot be activated.
   if (!IsWindowVisible(hwnd) || !IsWindowEnabled(hwnd) || (WS_EX_NOACTIVATE & GetWindowExStyle(hwnd)))
   {
   // Continue enumeration.
   goto Exit;
   }
   // If this is the owner window, there are no owned windows because
   // all owned windows are always above its owner in the z-order.
   if (hwnd == hOwner)
   {
   // Not found the owned window. Stop enumeration.
      bContinue = FALSE;
      goto Exit;
   }
   // Is this window owned by hwndOwner?
   if (IsOwned(hOwner, hwnd))
   {
      // Found the last owned window. Stop enumeration.
      bContinue = FALSE;
      *((HWND *)lParam) = hwnd;
      goto Exit;
   }
   Exit:
      return bContinue;
}
// Retrieves the last active window owned by hwndOwner.
HWND GetLastActiveWindow(HWND hwndOwner)
{
   HWND hwndLastActive = hwndOwner;
   EnumWindows(EnumLastActiveWindowProc, (LPARAM)&hwndLastActive);
   return hwndLastActive;
}

Exemplo de código

O seguinte exemplo de código demonstra como usar SHCameraCapture.

Observação

Para fazer o seguinte exemplo de código mais fácil de ler, verificação de segurança e manipulação de erro não estão incluídos.Esta exemplo de código não deve ser usado em uma configuração versão a menos que ele foi modificado para incluí-las.

HRESULT CameraCaptureExample(HWND hwndOwner, LPTSTR pszFilename)
{
    HRESULT         hResult;

    // Set the SHCAMERACAPTURE structure.
    ZeroMemory(&shcc, sizeof(shcc));
    shcc.cbSize             = sizeof(shcc);
    shcc.hwndOwner          = hwndOwner;
    shcc.pszInitialDir      = TEXT("\\My Documents");
    shcc.pszDefaultFileName = TEXT("test.3gp");
    shcc.pszTitle           = TEXT("Camera Demo");
    shcc.<MSHelp:link keywords="wce51lrfCAMERACAPTURE_VIDEOTYPES" TABINDEX="0">VideoTypes</MSHelp:link>         = CAMERACAPTURE_VIDEOTYPE_MESSAGING;
    shcc.nResolutionWidth   = 176;
    shcc.nResolutionHeight  = 144;
    shcc.nVideoTimeLimit    = 15;
    shcc.<MSHelp:link keywords="wce51lrfCAMERACAPTURE_MODE" TABINDEX="0">Mode</MSHelp:link>               = CAMERACAPTURE_MODE_VIDEOWITHAUDIO;
    // Display the Camera Capture dialog.

    // The next statements will execute only after the user takes
    // a picture or video, or closes the Camera Capture dialog.
    if (S_OK == hResult)
    {
        StringCchCopy(pszFilename, MAX_PATH, shcc.szFile);
    }
    return hResult;
}

Requirements

Header aygshell.h
Windows Mobile Pocket PC for Windows Mobile Version 5.0 and later, Smartphone for Windows Mobile Version 5.0 and later

See Also

Reference

Shell Functions
SHCAMERACAPTURE (structure)
CAMERACAPTURE_MODE
CAMERACAPTURE_STILLQUALITY
CAMERACAPTURE_VIDEOTYPES

Other Resources

Camera Capture
Camera Capture Graph