Question : Cancel AutoPlay in Windows (XP and after) with C++

O.S. : Windows XP and up
Language : C++

Hey guys, I am making an application which will be sent out on a multiple DVD set. All the DVDs will have their own autorun.inf file (cannot change this) and once the program is started, it requires different DVDs to be inserted. This poses the unacceptable annoyance of having the autoplay run for each DVD. I know Windows provides a way to cancel this (http://msdn.microsoft.com/en-us/library/cc144204%28VS.85%29.aspx) but I am unsure how to use this (I am not too familiar with C++).

Just copying the first part about registering the windows messages
     uMessage = RegisterWindowMessage(TEXT("QueryCancelAutoPlay"));
provides a compilation error of missing a type. I am unsure what the type would be, or if I am missing some #include or linked library. Also, the next part of the provided code :

UINT g_uQueryCancelAutoPlay = 0;

BOOL DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    ...
    default:
        if (!g_uQueryCancelAutoPlay)
        {
            g_uQueryCancelAutoPlay = RegisterWindowMessage(TEXT("QueryCancelAutoPlay"));
        }
        if (uMsg == g_uQueryCancelAutoPlay)
        {
            SetWindowLong(hDlg, DWL_MSGRESULT, TRUE);          
            return 1;              
        }
    }
}

does not work with the "..." and undefined "hDlg"

Any suggestions on how to implement this into a project (or other ideas, changing the registry is not exactly my best option, with the ever-present chance of not being able to assure changed the key back)? My apologies for my ineptitude.

Thanks in advance!

Answer : Cancel AutoPlay in Windows (XP and after) with C++

Hi j_willy,

in which kind of application do you need this? With MFC or without? If MFC, a dialog, SDI or MDI?

I.e. if it's for a MFC dialog application it's quite easy. Just add a line like this near the top (but at least below the '#include "stdafx.h"') of the dialog's implementation file:

    UINT g_uQueryCancelAutoPlay = RegisterWindowMessage( TEXT("QueryCancelAutoPlay") );

Then add a message handler for this message by adding a entry to the dialogs message map, i.e. add this somewhere between 'BEGIN_MESSAGE_MAP' and 'END_MESSAGE_MAP':

    ON_REGISTERED_MESSAGE( g_uQueryCancelAutoPlay, OnQueryCancelAutoPlay )

Add a function declararation for this message handler in the dialog class declaration like this:

    afx_msg LONG OnQueryCancelAutoPlay (WPARAM wParam, LPARAM lParam);

and implement it somehow like this in your dialog (here I assume the name of the dialogs class is CTestDlg, replace it with your dialog classes name):

    LONG CTestDlg::OnQueryCancelAutoPlay(WPARAM wParam, LPARAM lParam)
    {
     return 1;
    }


Hope that helps,

ZOPPO
    }




Random Solutions  
 
programming4us programming4us