tanvon++

September 27, 2006

Ticker ( Displaying Text Over Running Video )

Filed under: DirectShow — tanvon malik @ 1:18 am

The code for this article 

Download Demo

Displaying text is a bit same as displaying an image over video which I stated previously in my blog also.

The Actual Work

Displaying text over video means, that first we need to create a bitmap then we will write our text over that bitmap, and that bitmap will be blended with the running video with the help of VMR9.

Need Some Control Over Mixing

The thing that is vital, Is some preferences which we need to set. Actually if you display an image over video, You don’t need much control over actual blending, Because if an image is a bit is scaled or changed it is difficult to catch it, But in the case of text you can’t accept such situation. Because if text is a bit scaled or changed it would be much harder to read it. So first of all we need to tell the mixer to not scale our text. The interface which will come to save us is IVMRMixerControl9. Here we request point filtering instead of bilinear filtering (which is default) to improve the text quality. If you are not scaling the app Image, you should use point filtering.

pVmr->QueryInterface( IID_IVMRMixerControl9, (void**) &pMix);
DWORD dwPrefs=0;
pMix->GetMixingPrefs( &dwPrefs);
dwPrefs |= MixerPref_PointFiltering;
dwPrefs &= ~( MixerPref_BiLinearFiltering );
pMix->SetMixingPrefs( dwPrefs );

Text To Image

Now we will create the bitmap having our text. (more…)

September 24, 2006

CFileDialogX What Is The Vital Change

Filed under: Windows — tanvon malik @ 4:28 pm

Introduction

In my this article on codeproject.com you can easily judge the difference. I here adds my control side by side the CFileDialog controls, not at bottom which is normal, when we add a template to the  file open dialog.

Why ??

Meeting  the needs of  his or his clients is not easy, But this is the thing which differentiate us (programmers) from others. The above project also has a such story. But doing what our client wants is the only way, if you want to live in the industry.

HOW ??

With the help of MFC, it has become much easier to customize the dialogs whom MFC wraps. Otherwise we our self have to hook them. Because MFC itself hooks those dialogs, So it is much easier to customize a dialog , By just overriding some methods. In the above project the same I did. I just handled OnInitDialog()  and OnFileNameChange(), The first is more important, all work is done inside it.

CRect rect;
CWnd * parent = GetParent();
parent->GetWindowRect(&rect);
parent->SetWindowPos(0,rect.left,rect.top,rect.Width()+200,rect.Height(),0);
ScreenToClient(rect);
CRect staticWinRect( rect.Width(), rect.top+65, rect.Width()+200-20, rect.Height()-100 );
CFont * pfont = parent->GetFont();
mStaticPreview.Create( "VC++ shows its mystries", WS_CHILD|WS_VISIBLE|WS_BORDER, staticWinRect,parent);
mStaticPreview.SetFont(pfont,false);
return TRUE;

You can see above, First I get the window rect of the normal dialog, Remember it when we handle OnInitDialog() of any dialog, It is confirmed that the dialog box is complete in the memory all its control now exists, So it is the best time to customize the normal dialog. So I do the same I get the window rect of the normal dialog, Then I change that rect from screen to client coordinates. Then I make the normal dialog a bit fat to make room for my control. Here I create a static control and places it on the dialog, Then I set the font of my control the font which dialog box uses, It is the best practice to live in somebody’s house wearing the same style clothe the other people there are wearing, So you donot look strange or stranger there.

This is all Ok now, you can place any control at the above place, And update it appropriately as I do in OnFileNameChange(). Here I just see the currently selected file or folder, and show its some properties.

Some Bad Practice

In the above segment of code you see some fixed numbers at

CRect staticWinRect(rect.Width(), rect.top+65, rect.Width()+200-20, rect.Height()-100);

It is not a good practice to do, Why because sometimes you or some other guy wants to make the dialog sizeable or want to add some more control, it will be difficult for them to do there job. But why I do it here the problem is that, I wanted to place my control next the listview of file open dialog, But when I checked the existence list view in the OnInitDialog() , I came to know that list view is not currently there, So I can’t get its dimentions. Therefore I used the fixed numbers, But I will try to get a workaround this problem.

September 19, 2006

How To Make 256 Color Toolbar

Filed under: Windows — tanvon malik @ 3:22 pm

For the last whole week I have seen this question two times, First at microsoft.public.vc.mfc newsgroup  and the other at codeproject site. Actually the problem is that in MFC whenever we will create a toolbar it will automatically create a toolbar with 16 colors.

We want a workaround to this problem. A toolbar stores all its bitmaps as an image list. So we have to make that image list to have 256 color bitmaps. At first you must have a bitmap you want to show as toolbar, or create a bitmap (a bitmap which shows all buttons ) with 256 color in paint brush or any painting application you like. Now load that bitmap with LoadImage().
HBITMAP hbm = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_BITMAP,
0,0, LR_CREATEDIBSECTION | LR_LOADMAP3DCOLORS );
CBitmap bm;
bm.Attach(hbm);

All we have done is that now we have a CBitmap loaded with the 256 color bitmap. Now create an image list but tell it to have 256 color.
CImageList m_ilToolBar.Create(20,20,ILC_COLOR8,4,4);
Here ILC_COLOR8 is the flag which tells create image list of 256 colors. Now add your loaded image in the image list. This way your 256 color image list now have a 256 color bitmap.

m_ilToolBar.Add(&bm,(CBitmap*)NULL);

Now the last step is to serve your 256 color image list to your application’s toolbar
m_wndToolBar.GetToolBarCtrl().SetImageList(&m_ilToolBar);

September 18, 2006

How Hooks Work

Filed under: Windows — tanvon malik @ 5:25 pm

I updated my article about hooks, and why to implement them

look here http://www.codeproject.com/useritems/PickIconDlg2.asp

September 15, 2006

Showing an Animated Image Over Running Video

Filed under: DirectShow — tanvon malik @ 4:24 pm

Peeking Inside DirectShow

Background

You can download Source files and a demo of the given project from my this article on codeproject

Displaying a picture over video requires some insight of DirectShow, and how to build a filter graph (another my article on codeproject). And adding custom filters in the graph like VMR9 (video mixing renderer). This VMR9 is the key, it is the renderer which allows us to display picture over video.

 Introduction

  The basic force behind displaying an image over video is the interface IVMRMixerBitmap9. Basically this interface only has three member functions.

  • GetAlphaBitmapParameters()
  • SetAlphaBitmap()
  • UpdateAlphaBitmapParameters()

The other basic thing is a structure VMR9AlphaBitmap , This basically used to convey data among functions.

Some of the members of VMR9AlphaBitmap which arediscussed here are given below
DWORD dwFlags;
HDC hdc;
RECT rSrc;
VMR9NormalizedRect rDest;
FLOAT fAlpha;
COLORREF clrSrcKey;

How to work

 Now comes the point how to work with them. Let us know how to initialize the thing for the first time. First of all we need to know (more…)

September 13, 2006

Taskbar and Start Menu Properties Dialog

Filed under: Windows — tanvon malik @ 4:54 pm

In a newsgroup a message asked  “How to display Taskbar and Start Menu Properties” programmatically in VC++. At first I guessed that it is an easy question. Just search ” cpl ” files in your system and it will give us the actual file names of all control panel applets. Now we can double click any file to show which applet it is, Or we can run any applet from run box with ” Control desk.cpl “.

Running programmatically, to run these applets from VC++ it is also easy just

ShellExecute( this->m_hWnd, NULL, "desk.cpl", NULL, NULL, 0);

Showing Required, But my friend’s requirement was to show  ” Taskbar and Start Menu Properties” dialog from VC++ , alas. When I searched my system for ” cpl ” files it showed many applets but not my required.

I searched MSDN, it tells me that scripting languages can show this dialog box, but what about VC++.

I can’t find any clue. So I called it the IDispatch way

 CString ss = ("TrayProperties");
BSTR szMember = ss.AllocSysString();
DISPID dispid;
COleDispatchDriver disp;
disp.CreateDispatch("Shell.Application");
disp.m_lpDispatch->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid);
disp.InvokeHelper(dispid, DISPATCH_METHOD, NULL,NULL,NULL);
SysFreeString( szMember);

    Now with this code we can show the desired dialog. Never forget to initialize and uninitialize the COM.

September 12, 2006

Pick Icon Dialog

Filed under: Windows — tanvon malik @ 8:46 am

My this article and its source code is here.

    You can see my previous article on showing Pick Icon Dialog at codeproject. It is a very simple way to show this dialog. After that I started trying to customize it to make it more useful. The first change I made is I made a new class which wraps the API and conversions of string in unicode and then back. Now you only need to call just one method of class to show the dialog and other two methods to get path and index of the selected icon.

    The second change I made is I customized it to show index of currently selected icon in the icon listbox. I dynamically created a static control on the dialog and updated that static control to show current selection of  listbox.

    How things works, I hooked the dialog box with SetWindowsHookEx and hook type is WH_CALLWNDPROC. In my hook procedure first thing I wanted to do was to make room for my static control.

    ListBox has a Fixed Height ,  The first thing came to my mind was to shrink the listbox. So I tried, But in vain, It is a “FIXED height” listbox you can’t change its height, I tried to set the height with SetWindowPos() it did not work. Lest I set the height to zero, but the list box remained at its place. The same is not with width, it can be changed.

    Make Dialog Bigger , So now only way I had was to make the dialog more taller. So I made it, But making the dialog taller was not the only story I also had to move the buttons down too. There you can see only two buttons, but actually there are three buttons ( Oh SPY++  I love you very much ). I moved the three buttons down, because I did not want to have any problem in the future, If I have to show that third button and moving at that time would not be a good thing, so I solved it here.

    Creation of Static Control , then I created static control dynamically, and placed it below the listbox.

    Messages Handled , In my hook procedure I handled WM_INITDIALOG , and WM_COMMAND messages. the WM_INITDIALOG message is sent every time when the dialog box is about to be shown, so I did all my control changing there. the second WM_COMMAND message is actually handled only for a notification, which is sent to the parent of a listbox when the listbox selection changes. I handled it to update my static control.

    Mysteries, Another thing I noticed in this dialog’s list box is, It selects the first entry by default, But whenever inquired with GetCurSel() it returns -1, which means no selection. So I made my class to handle this problem also.

    If Finds a Bug or Problem , if you find any problem or any malfunction, Please inform me.

Blog at WordPress.com.