DeveloperSide.NET Forums
August 03, 2020, 03:21:36 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
   Home   Help Search Login Register  
Pages: [1]
Author Topic: cam ActiveX control?  (Read 6892 times)
0 Members and 1 Guest are viewing this topic.
Captain Xarzu
« on: August 22, 2007, 09:09:47 PM »

Is there an ActiveX control for a display from a cam? There must be one that I can drop into an MFC application.

In the resource editor there is a button for a "Custom Control" in the 2005 IDE but I also remember there used to be a special way to select from a list of Active X controls in the older versions of Visual Studio. I think it was "Add Control".

Has anyone tried something like this? If you have not, where would you look to find out something like this?

OK, so maybe MFC is a dead issue now days. But still, there must be ActiveX or COM components that people still use.

Andrew Kirillov wrote a motion detection program and posted it on:
that seems to use some sort of plug-in.  But it is written in C#. I tried poking around in this code but there is no resource view familiar to me.

Laurent Kempé wrote what seems to be a way to do it using C++ and ATL:
ATL is a form of COM.  It looks good but the ATL component seems to be one that he wrote from scratch.  Is this the only way to do this?

Other web sites seem to suggest that the activeX control comes with the camera manufacturers firmware.

There must be a standard way that it is done.  Can anyone tell me?

I noticed in the Toolbox there is an Animation Control.  I wonder if there is a way to make use of this.

Using CAnimateCtrl 

An animation control, represented by the class CAnimateCtrl, is a window that displays a clip in Audio Video Interleaved (AVI) format — the standard Windows video/audio format. An AVI clip is a series of bitmap frames, like a movie.

Since your thread continues executing while the AVI clip is displayed, one common use for an animation control is to indicate system activity during a lengthy operation. For example, the Windows Find dialog box displays a moving magnifying glass as the system searches for a file.

Animation controls can only play simple AVI clips, and they do not support sound. (For a complete list of limitations, see CAnimateCtrl.) Since the capabilities of an animation control are severely limited and subject to change, you should use an alternative such as the MCIWnd control if you need a control to provide multimedia playback and/or recording capabilities. For more information about the MCIWnd control, see the multimedia documentation.

So this seems to be the right control to use.  But this brings up more questions.  How do I get information from a cam to the CAnimateCtrl?

I got an answer from on how to do this with WIN32 API:

Here's a simple guide i wrote a while back with Win32 api calls,  using API calls are a hell of a lot faster than using an ActiveX control so you should use this method unless you have a very good reason not to.

The capCreateCaptureWindow() function you'll need to create the control is in avicap32.dll (in system32 folder of all windows pc's), See a guide about importing functions from DLL's if your unsure how to do this (system32 is in PATH of every pc so don't use the full address of the dll just import it by the filename).

I've attached an example but it's in assembly however (contains executable too), I've ported the main bits you'll need in C below though. If you've got some experience using the Win32 api you should be able to recognize the structure anyway.

How to Create a basic Webcam viewer program (like the example):

Use the capCreateCaptureWindow() function in your startup routine to create the control (WM_INITDIALOG or WM_CREATE are reccomended but i guess you could create it at runtime if you wanted):

HWND  hWebcam = capCreateCaptureWindow(_camtitle, WS_VISIBLE + WS_CHILD, 10, 10,266, 252, MainWindowHwnd, 0)     

_camtitle is just a string with the name of your window in it (wasn't NULL terminated in example) and MainWindowHwnd is just the HWND variable containing the handle of the parent window. This function is very similar to CreateWindowEx() and your just creating a control just how you would use CreateWindowEx() to create a button or editbox.

Setting up the control to accept input from Webcam:

To start input from the webcam once you've created the control you can use the following code in a "Start" button routine or just after the previous code in WM_CREATE/WM_INITDIALOG if you want to program to automatically get input from the webcam at startup:
SendMessage(hWebcam, 1034, nDevice, 0); //connect to device
SendMessage(hWebcam, 1077, TRUE, 0); //Set scale
SendMessage(hWebcam, 1076, nFPS, 0); //Preview Rate
SendMessage(hWebcam, 1074, TRUE, 0);   //start preview
nDevice should be 0 for a webcam (try different numbers if 0 does not work) and nfps is a integer that can be set to about 100 or whatever you want. the second parameter of the SendMessage function used here are ID's of commands, I only know a few though, must be some documentation somewhere. SendMessage() is an api call that should get declared by including windows.h otherwise import it from user32.dll (also in system32 folder).

Stopping/Pausing the Video

to stop the video you can do this:
SendMessage(hWebcam, 1035, _camtitle, 0); //Driver Disconnect
have this as the routine for a stop button. Also i think you have to put this in your WM_CLOSE routine also.

Taking Screenshot:

And to take a screenshot of the current frame you can do this:
SendMessage(hWebcam, 1049, 0, _filename) //save bitmap
_filename is just a string containing the destination bmp file for the screenshot to be written to in the same directory (surprisingly simple :p). add this code to a screenshot button or something.

I haven't written C in a while so there might be some minor syntax errors. I think your supposed to put &MainWindowHwnd instead of just MainWindowHwnd and you might have to store the variables as integer variables and put the variable name instead of just stating the number,just silly things like that which you could probably figure out in seconds. Also if your looking for a repository of libraries just use the windows API, they'res the whole library of functions in the Win32 and COM development section on the MSDN website, most have information at the bottom which .DLL you import them from.

Pages: [1]
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!