2010-01-29 12 views
1

En ce moment je fais une application pour capturer la vidéo d'une webcam, et en même temps clique sur divers boutons qui écrivent dans un fichier texte pour faire notes sur la vidéo. Je suis à peu près tout maintenant, sauf que WM_CAP_SEQUENCE enlève le contrôle de l'application par défaut pendant la capture ... donc pas de bouton. Je dois passer dans une structure de paramètres de capture pour dire que le clic est autorisé, fait à travers le bool yField étant mis à vrai. C'est là que j'ai un peu de mal, je ne suis pas habitué aux structures et je ne sais pas comment utiliser WM_CAP_SET_SEQUENCE_SETUP, il publie le code approprié ci-dessous et j'espère que quelqu'un pourrait m'offrir un aperçu ou des indications.C# Essayer d'utiliser WM_CAP_SET_SEQUENCE_SETUP pour me permettre de garder le contrôle de l'application pendant la capture vidéo

[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SendMessageA", SetLastError = true)] 
    public static extern int SendMessage2(IntPtr webcam1, int Msg, IntPtr wParam, ref CAPTUREPARMS lParam); 


CAPTUREPARMS CaptureParams = new CAPTUREPARMS(); 
     CaptureParams.fYield = 1; 
     CaptureParams.fAbortLeftMouse = 0; 
     CaptureParams.fAbortRightMouse = 0; 
     CaptureParams.dwRequestMicroSecPerFrame = 66667; 
     CaptureParams.fMakeUserHitOKToCapture = 0; 
     CaptureParams.wPercentDropForError = 10; 
     CaptureParams.wChunkGranularity = 0; 
     CaptureParams.dwIndexSize = 0; 
     CaptureParams.wNumVideoRequested = 10; 
     CaptureParams.fCaptureAudio = 0; 
     CaptureParams.fLimitEnabled = 0; 
     CaptureParams.fMCIControl = 0; 
     CaptureParams.fStepMCIDevice = 0; 
     CaptureParams.dwMCIStartTime = 0; 
     CaptureParams.dwMCIStopTime = 0; 
     CaptureParams.fStepCaptureAt2x = 0; 
     CaptureParams.wStepCaptureAverageFrames = 5; 
     CaptureParams.dwAudioBufferSize = 0; 


SendMessage2(webcam1, WM_CAP_SET_SEQUENCE_SETUP, new IntPtr(Marshal.SizeOf(CaptureParams)), ref CaptureParams); 

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] 
    public struct CAPTUREPARMS 
    { 
     public System.UInt32 dwRequestMicroSecPerFrame; 
     public System.Int32 fMakeUserHitOKToCapture; 
     public System.UInt32 wPercentDropForError; 
     public System.Int32 fYield; 
     public System.UInt32 dwIndexSize; 
     public System.UInt32 wChunkGranularity; 
     public System.Int32 fCaptureAudio; 
     public System.UInt32 wNumVideoRequested; 
     public System.UInt32 wNumAudioRequested; 
     public System.Int32 fAbortLeftMouse; 
     public System.Int32 fAbortRightMouse; 
     public System.Int32 fMCIControl; 
     public System.Int32 fStepMCIDevice; 
     public System.UInt32 dwMCIStartTime; 
     public System.UInt32 dwMCIStopTime; 
     public System.Int32 fStepCaptureAt2x; 
     public System.UInt32 wStepCaptureAverageFrames; 
     public System.UInt32 dwAudioBufferSize; 



     public void SetParams(System.Int32 fYield, System.Int32 fAbortLeftMouse, System.Int32 fAbortRightMouse, System.UInt32 dwRequestMicroSecPerFrame, System.Int32 fMakeUserHitOKToCapture, 
      System.UInt32 wPercentDropForError, System.UInt32 dwIndexSize, System.UInt32 wChunkGranularity, System.UInt32 wNumVideoRequested, System.Int32 fCaptureAudio, System.Int32 fMCIControl, 
      System.Int32 fStepMCIDevice, System.UInt32 dwMCIStartTime, System.UInt32 dwMCIStopTime, System.Int32 fStepCaptureAt2x, System.UInt32 wStepCaptureAverageFrames, System.UInt32 dwAudioBufferSize) 
     { 


      this.dwRequestMicroSecPerFrame = dwRequestMicroSecPerFrame; 
      this.fMakeUserHitOKToCapture = fMakeUserHitOKToCapture; 
      this.fYield = fYield; 
      this.wPercentDropForError = wPercentDropForError; 
      this.dwIndexSize = dwIndexSize; 
      this.wChunkGranularity = wChunkGranularity; 
      this.wNumVideoRequested = wNumVideoRequested; 
      this.fCaptureAudio = fCaptureAudio; 
      this.fAbortLeftMouse = fAbortLeftMouse; 
      this.fAbortRightMouse = fAbortRightMouse; 
      this.fMCIControl = fMCIControl; 
      this.fStepMCIDevice = fStepMCIDevice; 
      this.dwMCIStartTime = dwMCIStartTime; 
      this.dwMCIStopTime = dwMCIStopTime; 
      this.fStepCaptureAt2x = fStepCaptureAt2x; 
      this.wStepCaptureAverageFrames = wStepCaptureAverageFrames; 
      this.dwAudioBufferSize = dwAudioBufferSize; 

Répondre

0

wParam doit être égale à la taille de la structure et wParam est avant lParam, alors vous devriez l'appeler comme ceci:

SendMessage2(webcam1, WM_CAP_SET_SEQUENCE_SETUP, new IntPtr(Marshal.SizeOf(typeof(CAPTUREPARMS))), ref CaptureParams); 

Et la signature de la méthode devrait ressembler à ceci:

[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SendMessageA")] 
public static extern IntPtr SendMessage2(IntPtr webcam1, int Msg, IntPtr wParam, ref CAPTUREPARMS lParam); 

Votre structure a également la mauvaise mise en page, utilisez la définition CAPTUREPARMS de pinvoke.net (le Pack=1 la partie semble suspecte là, donc vous pourriez vouloir essayer avec et sans).

+0

[code] new IntPtr (Marshal.SizeOf (CAPTUREPARMS)), [/ code] a donné une erreur donc j'ai mis dans CaptureParams où vous avez suggéré CAPTUREPARMS. Après ça ça s'est bien passé, mais ça ne semble toujours pas me permettre de cliquer sur les choses, comme avant ... c'est comme si la structure elle-même ne disait rien d'utile. (j'ai fait tout le reste, lparams, etc.) – Verian

+0

La disposition de votre structure 'CAPTUREPARMS' est également incorrecte, essayez celle de pinvoke.net. –

+0

Merci pour votre aide jusqu'à présent. Je déteste avoir l'air idiot maintenant, mais je suis allé chercher la structure de pinvoke, et j'ai changé mes fausses/vraies entrées en 0/1 pour les int32s à prendre, et je n'ai toujours pas de chance – Verian