Friday, September 30, 2011

Windows mobile application closing and navigation tutorial

Mobile devices always have one application in the foreground. So navigation to another application or another section of the same application is very important when you are developing for a mobile device.

  • Mobile devices doesn't care about closing applications. It only cares about switching between applications and application components in a quick and easy manner.

  • Minimizing the application will give faster response time between application switches. Operating system must take care of the termination of application when the system is running out of memory. Minimize option can be implemented by setting the following properties of the Form we are displaying.
Form.ControlBox = True;
Form.MinimizeBox = True;

  • Closing the application will allow the user to control the application life-cycle on his own. Operating system has less work to do comparing to the minimize option. This option can be implemented by setting the following properties.
 Form.ControlBox = True;
 Form.MinimizeBox = False;

We can remove both these options and eventually remove the entire control box by setting the following property.

Form.ControlBox = False;

If we set this option, then there should be a way to navigate away from this form. For that we can use a button to navigate to another form by implementing one of the two methods mentioned below for the button click event. 


Form.ShowDialog - This method will show the second Form and waits until that form is closed (Blocking Call) before executing the first Form's code.

Form.Show - This method will show the second form and continue the first Form's code without caring about the second Form's activities (Non - Blocking call) 









Monday, September 26, 2011

Controlling the Windows Form in Windows Mobile

With the introduction of Windows Forms 2.0, classes which inherited form windows forms class are separated into two separate files using the "partial" keyword. This has separated the User interface components and the control logic into two separate files named

  • form.designer.cs
  • form.cs 

respectively.Basic components of a windows form user interface are shown below.


Mobile device applications are normally run in full screen mode and programmer might need to customize the entire display area with his colors and themes. For doing this, he needs to tweak with the basic components of the UI Form.

Hiding the Title Bar
This can be done with setting the following property

Form.WindowState = Maximized

Hiding the Bottom Menu bar
This can be done by deleting the MainMenu control in the Form class.

Removing the Control Box in the top right hand corner
This control box is used control the form's minimzing and closing behavior. To remove this control from the Form, with the following setting

Form.ControlBox = false




Setting close and minimize buttons in the application


Small control box displayed in the top right corner of the window is used to minimize or close the application . If the control box contains the OK button, then application will be terminated after clicking that button. If it contains the cross sign (X), application will be minimized. setting the desired control can be done through the following property setting.

Form.MinimizeBox = False - This will enable the OK button and make the application exit when the button is clicked

Form.MinimizeBox = True - This will enable the X button and make the application minimize when the button is clicked























Friday, September 16, 2011

How to play a media file with DirectShow

 Hello World in DirectShow Programming

Every directshow application must perform the following basic tasks.
  1. Creates an instance of the FGM
  2. Build a fliter graph using the FGM
  3. controls the filter graph and responds to events
Following example code will give an insight into a simple directshow application, which uses the above mentioned tasks.

  • Creating an instance of the FGM
IGraphBuilder Interface is used to create an instance of the FGM.

IGraphBuilder *pGraph;
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
                    IID_IGraphBuilder, (void **)&pGraph);

  • Building a filter graph with the FGM
IMediaControl Interface is used to handle the media stream in the filter graph

IMediaControl *pMediaControl;

  • Run the filter graph using the FGM
RenderFile method is used to read the video stream into the filter.
Run method is used to run the media stream through the filter graph

pGraph->RenderFile(L"\\Hello_World.avi", NULL);
pMediaControl->Run();

The Full Source code sample is found on http://msdn.microsoft.com/en-us/library/aa916490.aspx




Microsoft DirectShow Programming Tutorial - Part I


As per the Microsft's definition Microsoft® DirectShow® is an architecture for streaming media on the Microsoft Windows® platform
DirectShow provides for high-quality capture and playback of multimedia streams. It supports a wide variety of formats, including Advanced Systems Format (ASF), Motion Picture Experts Group (MPEG), Audio-Video Interleaved (AVI), MPEG Audio Layer-3 (MP3), and WAV sound files. It supports capture from digital and analog devices based on the Windows Driver Model (WDM) or Video for Windows. It automatically detects and uses video and audio acceleration hardware when available, but also supports systems without acceleration hardware.
The basic building block of the DirectShow API architecture is a filter. 
"Filter is a unit which performs a single operation on a multimedia stream."
Examples for the filter are 
  1. Filter for read files
  2. Filter for decoding a particular media stream format, such as MPEG-1 video
  3. Filter for passing data to the graphics or sound card
Filters are used to manage and manipulate data. These are used to perform actions such as parsing, decoding, formatting or rendering on a multimedia stream.
To perform a given task, we need to connect several filters such that output of one filter is an input for another filter.
"Set of connected filters is called a filter graph"

Filter Graph Manager (FGM)

As you have seen in the first part of this tutorial  the atomic module of the direct show is a filter. Set of connected filters are used for processing a multimedia stream. This is called a filter graph. Most important feature of the DirectShow API is the Filter Graph Manager (FGM) which handles all the required operations for handling a filter graph.

If you are processing a multimedia stream with DirectShow, you don't need to look after each and every filter. FGM controls the flow of data through the filter graph. You only need to call high level API calls such as

  • Run - to move the data through the filter graph
  • Stop - to stop the data flow
FGM will take care about all the required operations with the filters. 
If the user wants to handle the filters on his own, then user can use the "COM" interface to interact with filters. 
Another thing that FGM does is that passing the event notifications to the application, so that user application can respond to events such as
  • end of the stream
  • pause
  • stop
This process is done with the help of the Operating systems Message Queue. If end of the stream event is happened, OS will pass that message to the FGM. Then it will pass the relevant message to the application.

to be contd ...