Visual Studio 2008 Survey

My friend Fabien Lavocat from Microsoft France recently sent me an email regarding a Visual Studio 2008 survey they have just started.
The survey is of course available in English.
If you have a couple of minutes to kill, please answer the survey as this will help Microsoft improve their future editions of Visual Studio!

Click here to access the survey

Thanks for your time!



For french developers willing to obtain Microsoft Developer certifications, a colleague of mine (Julien Dollon) has just published a very useful website that will help you prepare for the certification exams:


I wish Julien good luck with his website and trust it will be a great help a lot of developers.



for this second blog article I've decided to explain this neat little feature of MySQL: SQL_CALC_FOUND_ROWS and FOUND_ROWS().
This article is about MySQL only, it is likely that these keywords/functions exist in other SQL-based languages but I've only ever used them with MySQL.

What's the point, you ask?
When working with (my)SQL databases, you often find yourself using the LIMIT keyword, in order for example to limit the results of a large search. Let's study a particular case.
- You're working on the "employees" table, which contains, say 1000 data rows.
- You wish to display the list of employees in a particular department, 10 by 10.
- You wish to display the amount of employees in this department.

What would you normally do?
Here's a rough example:
$result = mysql_query("SELECT * FROM employees WHERE department='sales' LIMIT 0,10 ");
$total = mysql_num_rows($result);
-> This is incorrect because $total will never exceed 10 due to the LIMIT clause.

You could also do this:
$result = mysql_query("SELECT COUNT(*) cnt FROM employees WHERE department='sales'");
$count = mysql_result($result, 0, "cnt");
$result = mysql_query("SELECT * FROM employees WHERE department='sales' LIMIT 0,10 ");
-> But this means you have to process two SQL queries.

So how do you fix this?
Using the SQL_CALC_FOUND_ROWS keyword in your SQL query will allow you to fetch the total amount of results without being limited by the LIMIT clause.
Here's how you use it:

$data_result = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM employees WHERE department='sales' LIMIT 0,10");
$count_result = mysql_query("SELECT FOUND_ROWS() cnt");
$employees_count = mysql_result($count_result, 0, "cnt");
echo "$employees_count employees found in the sales dept. Showing first 10: ";

As you can see, using the SQL_CALC_FOUND_ROWS keyword allows you to save the amount of results before applying the LIMIT clause; and this amount can be retrieved with a simple "SELECT FOUND_ROWS()" after the query is executed.

I've found this to be pretty useful when designing search pages, directories, and so on...
If you want more information about the FOUND_ROWS() function, and other useful functions aswell, check this page on the official MySQL documentation.

Okay, that's all folks!


WPF: drawing a video using MediaPlayer, VideoDrawing and DrawingBrush

I've decided to start this blog for a simple reason: I was recently doing some research on various subjects, and was unable to find any clear documentation. And here I was thinking the World Wide Web had all the answers. Perhaps my contributions will help some of my fellow developers!

This first article is about how to draw a video using the MediaPlayer class in WPF (C# only - my apologies to VB.NET users: I'm allergic to VB). I was in the middle of preparing a training session at Avanquest Software when I read something in the WPF MOC: using the MediaElement control isn't the only way you can draw a video on a surface. Doh! I investigated a little further on the subject but couldn't find anything on the subject.

What does this do?
This article will explain how to use the MediaPlayer class to play a video on a surface. To demonstrate the wide range of possibilities offered by this mechanism, I will explain how to draw the same video clip on 9 different controls simultaneously.

First, you need to instantiate the MediaPlayer class. This class lets you manage the playback of a media file by exposing methods such as Play, Pause, Stop, etc. The constructor doesn't accept any parameter. Then use the Open() method to specify the media you wish to play. In our example we'll be playing a video.

MediaPlayer mp = new MediaPlayer();
mp.Open(new Uri("c:/video.avi"));

Then initialize a new instance of the VideoDrawing class. This class is used to do the actual drawing on a surface. Instantiate a new object and affect its "Player" member to the MediaPlayer instance you've declared above. Finally, affect the "Rect" member to specifiy the zone where the video will be drawn. Since we're going to be using the video source as a background for our controls, the video will be stretched to fit the control space so the value you specify here don't matter -- just make sure to specify a value greater than 0 as Width and Height.

VideoDrawing vd = new VideoDrawing();
vd.Player = mp;
vd.Rect = new Rect(0, 0, 100, 100);

At this point, nothing is drawn on the window. You need to instantiate a DrawingBrush based on your VideoDrawing instance:

DrawingBrush db = new DrawingBrush(vd);

Your "db" variable is now an instance of DrawingBrush, meaning you can affect any property that is of type Brush, such as Control.Background, etc. In my example, I've got a grid with 9 cells, each of these cells contains a button.

foreach (Button b in videoGrid.Children)
b.Background = db;

Once this is done, all you have to do is to call the Play() method of the MediaPlayer instance.


I've provided a quick demo source code with this article. It plays the file located at c:\video.avi so make sure to either have a file with the same name or, of course, change the location of the file you wish to play.

Download demo project

Search This Blog