المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : problems about how to cancel auto play from an application



C# Programming
09-11-2009, 01:59 PM
I am developing an application to play DVD. however When i insert a disk, Windows will automatically try to open that disk either in an explorer window or ask the user what to do with the disk. Then I search in the internet and find two approaches.
The first and simplest is to register the special Windows message "QueryCancelAutoPlay" and simply return 1 when the message is handled. This only works for the current window, and not a background application.

The second approach requires inserting an object that implements the COM interface IQueryCancelAutoPlay COM interface into the Running Object Table.

I used the first one. But sometimes two messages of "QueryCancelAutoPlay" are received and the autoplay window appears again. Here is my code of cancel auto play. Sometimes one message of "QueryCancelAutoPlay" is received and the autoplay window doesn't appear. Sometimes no message of "QueryCancelAutoPlay" is received and the autoplay window appear again.

here is my code of cancel the autoplay ********

IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (g_uQueryCancelAutoPlay == 0)
{
g_uQueryCancelAutoPlay = RegisterWindowMessage("QueryCancelAutoPlay");
}
if (g_uQueryCancelAutoPlay != 0 && (uint)msg == g_uQueryCancelAutoPlay)
{
System.Windows.MessageBox.Show("QueryCancelAutoPlay1"); //Sometime it appears twice, sometimes it doesn't appear
return (IntPtr)1;
}
return IntPtr.Zero;
}