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

📄 adddeletedlg.cpp

📁 media player 控件源码 用EVC编译可以进行对WINCE下media player控制
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                break;
            }

            LoadString(g_hInst, IDS_APP_TITLE, szCaption, MAX_PATH);
            LoadString(g_hInst, IDS_DELETE_CONFIRM, szText, MAX_PATH);

            cmd = MessageBox(m_hwndDlg, szText, szCaption, MB_YESNO | MB_ICONEXCLAMATION);
            if (IDYES != cmd)
            {
                break;
            }

            iItem       = ListView_GetNextItem(m_hwndList, -1, LVNI_SELECTED);
            iItemBefore = iItem - 1;

            while (iItem >= 0)
            {
                // Let the player know to stop playing if the current playlist
                // is being deleted
                g_pPlayerWindow->PlaylistDelete(pManager->GetPlaylist(iItem));

                if (false == pManager->DeletePlaylist(iItem))
                {
                    ListView_SetItemState(m_hwndList, iItem, 0, LVIS_SELECTED);
                    break;
                }

                if (-1 == pManager->GetCurrentPlaylistID())
                {
                    m_iCurrentPlaylist = -1;
                }

                SendMessage(m_hwndParent, WM_COMMAND, ID_DELETED_PLAYLIST, (LPARAM)NULL);

                if (iItem < m_iCurrentPlaylist)
                {
                    m_iCurrentPlaylist--;
                }

                iItem = ListView_GetNextItem(m_hwndList, iItem, LVNI_SELECTED);
            }

            SetFocus(m_hwndList);

            LoadAllPlaylists();

            cItem = ListView_GetItemCount(m_hwndList);

            if (cItem > 0)
            {
                int iNewItem = min(iItemBefore+1, cItem-1);

                if (0 == iItemBefore)
                {
                    iNewItem = 0;
                }

                ListView_SetItemState(m_hwndList, iNewItem, LVIS_SELECTED, LVIS_SELECTED);
                ListView_EnsureVisible(m_hwndList, iNewItem, FALSE);
            }

            fHandled = TRUE;
        break;

        case IDC_RENAME_PLAYLIST:
            if (1 != ListView_GetSelectedCount(m_hwndList))
            {
                break;
            }

            iPlaylist = ListView_GetNextItem(m_hwndList, -1, LVNI_SELECTED);

            if (iPlaylist < 0)
            {
                break;
            }

            SetFocus(m_hwndList);
            hwndEdit = ListView_EditLabel(m_hwndList, iPlaylist);
            SendMessage(hwndEdit, EM_SETLIMITTEXT, MAX_PLAYLIST_NAME, 0);

            fHandled = TRUE;
        break;

        case IDOK:
        case IDCANCEL:
            // Treat the OK button as a request to open the currently selected item
            SendMessage(m_hwndDlg, WM_COMMAND, ID_OPEN_PLAYLIST, 0);

            EndDialog(m_hwndDlg, iControl);

            fHandled = TRUE;
        break;
    }

    return fHandled;
}

void CAddDeleteDialog::OnInitDialog()
{
    RECT rc;

    // save our child window handles for later use
    m_hwndStatic = GetDlgItem(m_hwndDlg, IDC_ADD_DELETE_TITLE);
    m_hwndAdd    = GetDlgItem(m_hwndDlg, IDC_NEW_PLAYLIST);
    m_hwndRename = GetDlgItem(m_hwndDlg, IDC_RENAME_PLAYLIST);
    m_hwndDelete = GetDlgItem(m_hwndDlg, IDC_DELETE_PLAYLIST);
    m_hwndList   = GetDlgItem(m_hwndDlg, IDC_PLAYLISTS);

    //
    // Check to see if the screen is small
    //
    if (g_bSmallScreen)
    {
        RECT rcWorkArea;
        RECT rcWnd, rcList;

        GetWindowRect(m_hwndDlg,  &rcWnd);
        GetWindowRect(m_hwndList, &rcList);

        if (!SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0))
        {
            HDC hdc = ::GetDC(NULL);

            rcWorkArea.left = 0;
            rcWorkArea.top  = 0;

            rcWorkArea.right  = GetDeviceCaps(hdc, HORZRES);
            rcWorkArea.bottom = GetDeviceCaps(hdc, VERTRES) - GetSystemMetrics(SM_CYMENU);

            ::ReleaseDC(NULL, hdc);
        }

        MoveWindow(m_hwndDlg,
                   rcWorkArea.left,
                   rcWorkArea.top,
                   rcWorkArea.right,
                   rcWorkArea.bottom,
                   TRUE);

        rcWorkArea.left   += rcList.left - rcWnd.left;
        rcWorkArea.right  -= rcList.left - rcWnd.left;
        rcWorkArea.right  += rcList.right - rcWnd.right - 2*GetSystemMetrics(SM_CXDLGFRAME);

        rcWorkArea.top    += rcList.top  - rcWnd.top - GetSystemMetrics(SM_CYCAPTION);
        rcWorkArea.bottom -= rcList.top  - rcWnd.top;
        rcWorkArea.bottom += rcList.bottom - rcWnd.bottom;

        MoveWindow(m_hwndList,
                   rcWorkArea.left,
                   rcWorkArea.top,
                   rcWorkArea.right,
                   rcWorkArea.bottom,
                   TRUE);
    }

    ListView_SetExtendedListViewStyle(m_hwndList, LVS_EX_FULLROWSELECT);

    GetClientRect(m_hwndList, &rc);

    // add a column to the list of playlists
    LVCOLUMN lvc;
    memset(&lvc, 0, sizeof (lvc));
    lvc.mask = LVCF_FMT | LVCF_WIDTH;
    lvc.fmt  = LVCFMT_LEFT;
    lvc.cx   = (rc.right - rc.left);

    ListView_InsertColumn(m_hwndList, 0, &lvc);

    // Load a snapshot of all the playlist files on the device
    LoadAllPlaylists();

    SetFocus(m_hwndList);

    // Scroll so that the current playlist (the selected item) is visible
    if (1 == ListView_GetSelectedCount(m_hwndList))
    {
        int iPlaylist = ListView_GetNextItem(m_hwndList, -1, LVNI_SELECTED);
        if (iPlaylist >= 0)
        {
            ListView_EnsureVisible(m_hwndList, iPlaylist, FALSE);
        }
    }
}

BOOL CAddDeleteDialog::OnNotify(NMHDR * pNotify)
{
    NMLISTVIEW *pnlv = (NMLISTVIEW *)pNotify;
    BOOL        fHandled = FALSE;
    TCHAR       szCaption[MAX_PATH];
    TCHAR       szText[MAX_PATH];

    if (LVN_ITEMCHANGED == pNotify->code)
    {
        int cSelectedFiles = ListView_GetSelectedCount(m_hwndList);

        EnableWindow(m_hwndRename, 1 == cSelectedFiles);
        EnableWindow(m_hwndDelete, cSelectedFiles >= 1);

        SetWindowLong(m_hwndDlg, DWL_MSGRESULT, 0);
        fHandled = TRUE;
    }
    else if (NM_CUSTOMDRAW == pNotify->code
             && m_hwndList == pNotify->hwndFrom)
    {
        NMLVCUSTOMDRAW *pcd = (NMLVCUSTOMDRAW*)pNotify;

        if (CDDS_PREPAINT == pcd->nmcd.dwDrawStage)
        {
            SetWindowLong(m_hwndDlg, DWL_MSGRESULT, CDRF_NOTIFYITEMDRAW);
            fHandled = TRUE;
        }
        else if (CDDS_ITEMPREPAINT == pcd->nmcd.dwDrawStage)
        {
            SetBkMode(pcd->nmcd.hdc, OPAQUE);

            pcd->clrTextBk = RGB(255,255,255);

            SetWindowLong(m_hwndDlg, DWL_MSGRESULT, CDRF_NEWFONT);

            fHandled = TRUE;
        }
    }
    else if (LVN_BEGINLABELEDIT == pNotify->code)
    {
    	// enable the dialog buttons
        EnableWindow(m_hwndAdd, FALSE);
        EnableWindow(m_hwndDelete, FALSE);
        EnableWindow(m_hwndRename, FALSE);

		// get this playlist's name
		LPTSTR szName = NULL;
		NMLVDISPINFO *pInfo = (NMLVDISPINFO*)pNotify;

		do
		{
	        CPlaylistMgr * pManager = CPlaylistMgr::GetInstance();
			CPlaylist* pList = pManager->GetPlaylist(pInfo->item.iItem);
			ASSERT(pList);
			if (!pList)
			{
				fHandled = TRUE;
				break;
			}

			int iLen = _tcslen(pList->GetName()) + 1;
			szName = new TCHAR[iLen];
			ASSERT(szName);
			if (!szName)
			{
				fHandled = TRUE;
				break;
			}

			szName[iLen - 1] = 0;
			_tcscpy(szName, pList->GetName());
			ASSERT(0 == szName[iLen - 1]);
			szName[iLen - 1] = 0;

			// grab the edit box and replace the "name (path)"
			// form with just "name"
			HWND hEdit = ListView_GetEditControl(m_hwndList);
			ASSERT(hEdit);
			if (!hEdit)
			{
				fHandled = TRUE;
				break;
			}

			SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)szName);
		} while (FALSE);

		if (szName)
			delete [] szName;
    }
    else if (LVN_ENDLABELEDIT == pNotify->code)
    {
        NMLVDISPINFO *pInfo = (NMLVDISPINFO*)pNotify;

        BOOL fAcceptUserName = FALSE;
        int cSelectedFiles   = ListView_GetSelectedCount(m_hwndList);
        bool bEmpty          = true;
        bool bBad            = false;

        do
        {
            TCHAR szNewName[MAX_PATH];
            TCHAR * pszSlash, * pszExt;

            if (NULL == pInfo->item.pszText)
            {
               // The user cancelled the edit
               break;
            }

            // check to see if it's a bad name
            int  cchUserText = _tcslen(pInfo->item.pszText);

            for (int i = 0; i < cchUserText; i++)
            {
                if (!_istspace(pInfo->item.pszText[i]))
                {
                    bEmpty = false;
                }

                if (IsBadFilenameChar(pInfo->item.pszText[i]))
                {
                    bBad = true;
                    break;
                }
            }

            if (bEmpty || bBad)
            {
                LoadString( g_hInst, IDS_APP_TITLE, szCaption, MAX_PATH);
                LoadString( g_hInst, IDS_PLAYLIST_NAME_INVALID, szText, MAX_PATH);
                MessageBox( m_hwndDlg, szText, szCaption, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL );
                break;
            }

            // strip off ".asx" if they typed it
            pszExt   = _tcsrchr(pInfo->item.pszText, TEXT('.'));
            pszSlash = _tcsrchr(pInfo->item.pszText, TEXT('\\'));

            if (NULL != pszExt && pszSlash < pszExt)
            {
                 *pszExt = TEXT('\0');
                _tcsncpy(szNewName, pInfo->item.pszText, MAX_PATH);
		szNewName[ MAX_PATH - 1 ] = L'\0';
                 *pszExt = TEXT('.');
            }
            else
            {
                _tcsncpy(szNewName, pInfo->item.pszText, MAX_PATH);
		szNewName[ MAX_PATH - 1 ] = L'\0';
            }

            // let the playlist manager change the name
            CPlaylistMgr * pManager = CPlaylistMgr::GetInstance();

            if (NULL != pManager)
            {
                if( !pManager->RenamePlaylist(pInfo->item.iItem, szNewName) )
                {
                    LoadString( g_hInst, IDS_APP_TITLE, szCaption, MAX_PATH);
                    LoadString( g_hInst, IDS_RENAME_FAIL, szText, MAX_PATH);
                    MessageBox( m_hwndDlg, szText, szCaption, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL );
                }
            }

            // update the list view
            LoadAllPlaylists();
            

        } while (FALSE);

        SetWindowLong(m_hwndDlg, DWL_MSGRESULT, fAcceptUserName);

        ListView_SetItemState(m_hwndList, pInfo->item.iItem, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);

        EnableWindow(m_hwndAdd,    TRUE);
        EnableWindow(m_hwndRename, TRUE);
        EnableWindow(m_hwndDelete, TRUE);

        fHandled = TRUE;
    }
    else if (LVN_DELETEALLITEMS == pNotify->code)
    {
        SetWindowLong(m_hwndDlg, DWL_MSGRESULT, TRUE);
        fHandled = TRUE;
    }
    else if (LVN_ITEMACTIVATE == pNotify->code)
    {
    	SendMessage(m_hwndDlg, WM_COMMAND, IDOK, 0);
        fHandled = TRUE;
    }
    else if (LVN_BEGINDRAG == pNotify->code)
    {
#ifdef UNDER_CE
        SetWindowLong(m_hwndDlg, DWL_MSGRESULT, LVBD_DRAGSELECT);
#endif /* UNDER_CE */

        fHandled = TRUE;
    }
    else if (NM_RCLICK == pNotify->code)
    {
    	ClientToScreen(m_hwndList, &pnlv->ptAction);
        DisplayContextMenu(pnlv->ptAction);
        fHandled = TRUE;
    }
    else if (GN_CONTEXTMENU == pNotify->code)
	{
		if (g_AygshellHelper.Loaded())
		{
			POINT pt;
			BOOL fRet = GetCursorPos(&pt);
			ASSERT(fRet);
			DisplayContextMenu(pt);
			fHandled = TRUE;
		}
    }

    return fHandled;
}

void CAddDeleteDialog::OnSize(int cx, int cy)
{
}

⌨️ 快捷键说明

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