How to start with Win32 DirectShow in WinCE

I was assigned a work to use direct show on our toradex-evaluation board running Wince7.
Here is my small article explaining how I approached this problem statement.

I was a total novice in field of windows programming so,first of all I dediced to learn a few basic concepts

So I searched for books on Win32(C++ mod of microsoft with lots of microsoft api`s)
Finally decided to go with
Charles Petzold 5th edition (I got a pdf ,I am sure u can get it too 😉 )

Installed Visual Studio 2008 (We had a licenced version)
Installed a SDK given by Toradex.(Cross compiler in terms of Linux)
Thats it !No more setup

=>From Petzold book I compiled first program (a hello world program)
hellowin.c

=>Make a new project-> Visual C++ -> Win32Project
OK
Make empty projet and its done.
Add a new source file name is as hellowin.c
In project properties -> C/C++ -> Advanced -> Compile As ->Compile as C code
then add the following code in that file(sorry I do not have a written permission to publish it…)


/*------------------------------------------------------------
HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
(c) Charles Petzold, 1998
------------------------------------------------------------*/
#include <windows.h>
//#include <tchar.h>
//#pragma comment(lib, "Winmm.lib")
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT (“HelloWin”) ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT (“This program requires Windows NT!”),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
TEXT (“The Hello Program”), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_CREATE:
PlaySound (TEXT (“hellowin.wav”), NULL, SND_FILENAME | SND_ASYNC) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, TEXT (“Hello, Windows 98!”),-1, &rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}

 

Compile and run.

=>You will see a window with text “Hello,Windows98”
also load some .wav file and name it as hellowin.wav,place the sound file with .exe
When you run the program this time ,the sound will play as well

Congrats,you started with the Win32(far more difficult than the classic linux – qt programming)

Some explanation:(you can refer book for this but if you dont have time to learn in detail like me then this will help)

wndclass->An object which will hold some properties of window class(common code in all progs)
RegisterClass()->Registers this window class
ShowWindow()
UpdateWindow (hwnd) ->Repaints this window (hwnd is a handle of window =>imp stuff)
while ()-> Message loop (required for dispatching the messages )
Now messages is very important phenomenon here
Win32 is event based system and not procedural (similar to device drivers in linux)
So whenever a user clicks mouse or a window is diaplayed or user clicks some key ,everything has a message associated to it.
Now this message ,when event happen reach to while loop,and while loop throws to the winproc() func.
In winproc func using switch case we get to know which event has happened and we take action (call some routines)according to it.

When window is displayed,events
WM_CREATE:
WM_PAINT:

is by default generated.
When we close window
WM_DESTROY:
event is generated.

Ok now I know a bit about Win32 lets look at this DirectShow stuff.
So I compiled some direct show samples for desktop on my laptop(windows 7 )
click here to check it out.

 


Like what you read?
Do you think you have knowledge to fetch Overseas Jobs and Projects?
Register here and start posting...
The following two tabs change content below.

Embedded Design Engineer by profession .Extremly intrested in Emedded Systems,Linux and Electronics.I truely believe in open source , join me in this mission by registering .

How to Integrate Google “No CAPTCHA reCAPTCHA” on Your Website


Leave a Reply