⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mavusb.cpp

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    ofn.lpstrFilter = "Music Files (.mp3;.wma;.wav)\0"
                      "*.mp3;*.wma;*.wav\0"
                      "All Files (*.*)\0"
                      "*.*\0";
    ofn.lpstrCustomFilter = NULL;
    ofn.nFilterIndex = 1;
    ofn.lpstrFile = pcBuffer;
    ofn.nMaxFile = 4096;
    ofn.lpstrFileTitle = NULL;
    ofn.lpstrInitialDir = NULL;
    ofn.lpstrTitle = NULL;
    ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER;
    ofn.lpTemplateName = NULL;

    //
    // The initial file name is empty.
    //
    pcBuffer[0] = 0;

    //
    // Display the open file dialog box.
    //
    if(GetOpenFileName(&ofn) != 0)
    {
        //
        // Display the Audible information dialog box.
        //
        if(DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_AUDIBLE), hWnd,
                     AudibleDlgProc) == IDOK)
        {
            //
            // Find the last '\' character in the name of the host file.  The
            // remainder of the host file name will become the device file
            // name.
            //
            pcDeviceName = strrchr(pcBuffer, '\\');
            if(pcDeviceName)
            {
                pcDeviceName++;
            }
            else
            {
                pcDeviceName = pcBuffer;
            }

            //
            // Clear the Audible meta-data for this file.
            //
            memset(cAudibleData, 0, 512);

            //
            // Convert the title from ASCII to Unicode and place it in the
            // meta-data structure.
            //
            MultiByteToWideChar(CP_ACP, 0, g_pcAudibleTitle,
                                strlen(g_pcAudibleTitle) + 1,
                                pAudibleData->pusTitle, 128);

            //
            // Set the start of the Audible program in the meta-data.
            //
            pAudibleData->ulProgramStart = g_ulAudibleStart;

            //
            // Set the number of sections in the Audible program in the
            // meta-data.
            //
            pAudibleData->ulSections = g_ulAudibleSections;

            //
            // Save the offset of the sections in the meta-data.
            //
            pAudibleData->pulSectionStart[0] = g_pulAudibleSection[0];
            pAudibleData->pulSectionStart[1] = g_pulAudibleSection[1];
            pAudibleData->pulSectionStart[2] = g_pulAudibleSection[2];
            pAudibleData->pulSectionStart[3] = g_pulAudibleSection[3];
            pAudibleData->pulSectionStart[4] = g_pulAudibleSection[4];

            //
            // Convert the device file name from ASCII to Unicode.
            //
            MultiByteToWideChar(CP_ACP, 0, pcDeviceName,
                                strlen(pcDeviceName) + 1, pusDeviceName, 128);

            //
            // Add the Audible meta-data for this file to the device.
            //
            SetAudibleMetaData(g_ulDriveNum, pusDeviceName, cAudibleData, 508);

            //
            // A single file was selected, so download it now.
            //
            Download(hWnd, pcBuffer);
        }
    }

    //
    // Re-load the list of files on the device.
    //
    LoadFileList();
}

//****************************************************************************
//
// Displays a save file dialog and uploads the selected files from the device.
//
//****************************************************************************
void
SaveFiles(HWND hWnd)
{
    OPENFILENAME ofn;
    char pcPath[MAX_PATH], pcFile[256];
    LVITEM item;
    int iNumItems, iIdx;

    //
    // Get the number of items which are selected.
    //
    iNumItems = ListView_GetSelectedCount(g_hListView);

    //
    // Find the first selected item in the list view control.
    //
    iIdx = 0;
    while(1)
    {
        //
        // Fill in the LVITEM structure for this item.
        //
        item.mask = LVIF_STATE | LVIF_TEXT;
        item.iItem = iIdx++;
        item.iSubItem = 0;
        item.stateMask = LVIS_SELECTED;
        item.pszText = pcPath;
        item.cchTextMax = MAX_PATH;

        //
        // Get the item information.
        //
        ListView_GetItem(g_hListView, &item);

        //
        // Is this item selected?
        //
        if(item.state & LVIS_SELECTED)
        {
            break;
        }
    }

    //
    // Fill in the save file dialog box structure.
    //
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = hWnd;
    ofn.hInstance = g_hInstance;
    ofn.lpstrFilter = "All files (*.*)\0*.*\0\0\0";
    ofn.lpstrCustomFilter = NULL;
    ofn.nFilterIndex = 1;
    ofn.lpstrFile = pcPath;
    ofn.nMaxFile = MAX_PATH;
    ofn.lpstrFileTitle = NULL;
    ofn.lpstrInitialDir = NULL;
    ofn.lpstrTitle = NULL;
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOTESTFILECREATE;
    ofn.lpTemplateName = NULL;

    //
    // Display the save as dialog box.
    //
    if(GetSaveFileName(&ofn) != 0)
    {
        //
        // Remove the file name from the end of the path name.
        //
        pcPath[ofn.nFileOffset] = '\0';

        //
        // Loop through all the items to find the ones which are selected.
        //
        iIdx = 0;
        while(iNumItems)
        {
            //
            // Fill in the LVITEM structure for this item.
            //
            item.mask = LVIF_STATE | LVIF_TEXT;
            item.iItem = iIdx++;
            item.iSubItem = 0;
            item.stateMask = LVIS_SELECTED;
            item.pszText = pcFile;
            item.cchTextMax = 256;

            //
            // Get the item information.
            //
            ListView_GetItem(g_hListView, &item);

            //
            // Is this item selected?
            //
            if(item.state & LVIS_SELECTED)
            {
                //
                // Append the file name to the directory name.
                //
                strcpy(pcPath + ofn.nFileOffset, pcFile);

                //
                // Upload this file.
                //
                Upload(hWnd, pcPath, pcFile);

                //
                // Decrement the count of selected items.
                //
                iNumItems--;
            }
        }
    }
}

//****************************************************************************
//
// Pastes files from the clipboard to the device.
//
//****************************************************************************
void
Paste(HWND hWnd)
{
    HDROP hDrop;
    int iFiles, iIdx;
    char pcBuffer[256];

    //
    // Open the clipboard.
    //
    if(OpenClipboard(NULL) == 0)
    {
        return;
    }

    //
    // Try to get the file name list from the clipboard.
    //
    hDrop = (HDROP)GetClipboardData(CF_HDROP);
    if(hDrop == NULL)
    {
        CloseClipboard();
        return;
    }

    //
    // Get the number of files in the clipboard.
    //
    iFiles = DragQueryFile(hDrop, -1, NULL, 0);

    //
    // Loop through all the files in the clipboard.
    //
    for(iIdx = 0; iIdx < iFiles; iIdx++)
    {
        //
        // Get the name of this file.
        //
        DragQueryFile(hDrop, iIdx, pcBuffer, 256);

        //
        // Download this file to the player.
        //
        DoDownload(hWnd, pcBuffer);
    }

    //
    // Close the clipboard.
    //
    CloseClipboard();

    //
    // Re-load the list of files on the device.
    //
    LoadFileList();
}

//****************************************************************************
//
// Deletes the currently selected file(s).
//
//****************************************************************************
void
DeleteFiles(HWND hWnd)
{
    LVITEM item;
    int iNumItems, iIdx;
    char pcMsg[256];
    unsigned short pusFileName[128];

    //
    // Get the number of items which are selected.
    //
    iNumItems = ListView_GetSelectedCount(g_hListView);
    if(!iNumItems)
    {
        return;
    }

    //
    // Generate the confirmation message.
    //
    if(iNumItems == 1)
    {
        strcpy(pcMsg, "Are you sure you want to delete this file?");
    }
    else
    {
        wsprintf(pcMsg, "Are you sure you want to delete these %d files?",
                 iNumItems);
    }

    //
    // Display a message box and make sure that the user really wants to delete
    // these files.
    //
    if(MessageBox(hWnd, pcMsg, "Confirm File Delete",
                  MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) != IDYES)
    {
        return;
    }

    //
    // Loop through all the items to find the ones which are selected.
    //
    iIdx = 0;
    while(iNumItems)
    {
        //
        // Fill in the LVITEM structure for this item.
        //
        item.mask = LVIF_STATE | LVIF_TEXT;
        item.iItem = iIdx++;
        item.iSubItem = 0;
        item.stateMask = LVIS_SELECTED;
        item.pszText = pcMsg;
        item.cchTextMax = 256;

        //
        // Get the item information.
        //
        ListView_GetItem(g_hListView, &item);

        //
        // Is this item selected?
        //
        if(item.state & LVIS_SELECTED)
        {
            //
            // Convert the file name from ASCII to Unicode.
            //
            MultiByteToWideChar(CP_ACP, 0, pcMsg, strlen(pcMsg) + 1,
                                pusFileName, 128);

            //
            // This item is selected, so delete it from the device.
            //
            Maverick_Delete(g_ulDriveNum, pusFileName);

            //
            // Remove any Audible meta-data associated with this file.
            //
            RemoveAudibleMetaData(g_ulDriveNum, pusFileName);

            //
            // Decrement the count of selected items.
            //
            iNumItems--;
        }
    }

    //
    // Re-load the list of files on the device.
    //
    LoadFileList();
}

//****************************************************************************
//
// Changes the view in the list view control.
//
//****************************************************************************
void
SetView(HWND hWnd, DWORD dwStyle, UINT uiMenuId)
{
    DWORD dwCurStyle;
    HMENU hMenu;

    //
    // Get the current window style.
    //
    dwCurStyle = GetWindowLong(g_hListView, GWL_STYLE);

    //
    // If the current window style is not the large icon style, then
    // we need to change the window style.
    //
    if((dwCurStyle & LVS_TYPEMASK) != dwStyle)
    {
        //
        // Change the window style to the large icon style.
        //
        SetWindowLong(g_hListView, GWL_STYLE,
                      (dwCurStyle & ~LVS_TYPEMASK) | dwStyle);

        //
        // Get the handle of the "view" menu.
        //
        hMenu = GetSubMenu(GetMenu(hWnd), 2);

        //
        // Set the check mark for the new view item and clear the check marks
        // for the other items.
        //
        CheckMenuRadioItem(hMenu, ID_VIEW_LARGEICONS, ID_VIEW_DETAILS,
                           uiMenuId, MF_BYCOMMAND);
    }
}

//****************************************************************************
//
// Changes the current drive.
//
//****************************************************************************
void
SetDrive(HWND hWnd, unsigned long ulDrive, UINT uiMenuId)
{
    HMENU hMenu;

    //
    // If we are already on the selected drive then there is nothing to do.
    //
    if(g_ulDriveNum == ulDrive)
    {
        return;
    }

    //
    // Change the drive number to the given drive.
    //
    g_ulDriveNum = ulDrive;

    //
    // Get the handle of the "drive" menu.
    //
    hMenu = GetSubMenu(GetMenu(hWnd), 3);

    //
    // Set the check mark for the "internal" item and clear the check
    // marks for the other items.
    //
    CheckMenuRadioItem(hMenu, ID_DRIVE_INTERNAL, ID_DRIVE_EXTERNAL,
                       uiMenuId, MF_BYCOMMAND);

    //
    // Re-load the file list.
    //
    LoadFileList();
}

//****************************************************************************
//
// Formats the file system on the device.
//
//****************************************************************************
void
Format(HWND hWnd)
{
    //
    // Make sure that the user really wants to format the device.
    //
    if(MessageBox(hWnd,
                  "Formatting the device will lose all the files stored on "
     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -