예제 #1
0
static VOID
PlayFile(HWND hwnd, LPTSTR lpFileName)
{
    MCI_PLAY_PARMS mciPlay;
    TCHAR szLocalFileName[MAX_PATH];
    UINT FileType;
    MCIERROR mciError;

    if (lpFileName == NULL)
    {
        if (szPrevFile[0] == _T('\0'))
            return;

        _tcscpy(szLocalFileName, szPrevFile);
    }
    else
    {
        _tcscpy(szLocalFileName, lpFileName);
    }

    if (GetFileAttributes(szLocalFileName) == INVALID_FILE_ATTRIBUTES)
    {
        return;
    }

    FileType = IsSupportedFileExtension(szLocalFileName);

    switch (FileType)
    {
        case UNSUPPORTED_FILE:
            MessageBox(hwnd, _T("Unsupported format!"), NULL, MB_OK);
            return;
        case WAVE_FILE:
            OpenMciDevice(hwnd, _T("waveaudio"), szLocalFileName);
            break;
        case MIDI_FILE:
            OpenMciDevice(hwnd, _T("sequencer"), szLocalFileName);
            break;
        case AUDIOCD_FILE:
            OpenMciDevice(hwnd, _T("cdaudio"), szLocalFileName);
            break;
        case AVI_FILE:
            OpenMciDevice(hwnd, _T("avivideo"), szLocalFileName);
            break;
    }

    SetTimer(hwnd, IDT_PLAYTIMER, 100, (TIMERPROC) PlayTimerProc);

    mciSendCommand(wDeviceId, MCI_SEEK, MCI_WAIT | MCI_SEEK_TO_START, 0);

    mciPlay.dwCallback = (DWORD_PTR)hwnd;
    mciPlay.dwFrom = 0;
    mciPlay.dwTo = MaxFilePos;

    mciError = mciSendCommand(wDeviceId, MCI_PLAY, MCI_NOTIFY | MCI_FROM /*| MCI_TO*/, (DWORD_PTR)&mciPlay);
    if (mciError != 0)
    {
        MessageBox(hwnd, _T("Can't play!"), NULL, MB_OK);
    }
}
예제 #2
0
// Check if a single file name is provided that seems to be an image file.
bool CMyStatic::CanLoadFromFile(COleDataObject *pDataObject) const
{
	// Check if there is a HDROP object with a single file name.
	bool bCanLoadFromFile = (1 == m_DropTarget.GetFileNameCount(pDataObject));
	if (bCanLoadFromFile)
	{
		bCanLoadFromFile = false;
		CString str = m_DropTarget.GetSingleFileName(pDataObject);
		// Check if file exists
		if (!str.IsEmpty() &&
			INVALID_FILE_ATTRIBUTES != ::GetFileAttributes(str.GetString()))
		{
			// Check file extension.
			// This is a rather simple check.
			// A full check may get the file type by reading the first bytes from the file.
			bCanLoadFromFile = IsSupportedFileExtension(str.GetString());
		}
	}
	return bCanLoadFromFile;
}