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

📄 adddeletedlg.cpp

📁 media player 控件源码 用EVC编译可以进行对WINCE下media player控制
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
///////////////////////////////////////////////////////////////////////////////
// File: AddDeleteDlg.h
//
// Desc: This file contains the implementation for the Organize Playlists
//       dialog.
//
///////////////////////////////////////////////////////////////////////////////

#include <windows.h>
#include <commctrl.h>

#include "resource.h"

#include "AddDeleteDlg.h"
#include "playlistmgr.h"
#include "CEPlayerUtil.h"
#include "PlayerWindow.h"

#include "aygshell_helper.h"

#define MAX_PLAYLIST_NAME 60

extern bool g_bSmallScreen;

CAddDeleteDialog::CAddDeleteDialog(HWND hwndParent, HWND hwndMain) :
    CBaseDialog(hwndParent, IDD_PLAYLIST_ADD_DELETE),
    m_hwndAdd(NULL),
    m_hwndDelete(NULL),
    m_hwndRename(NULL),
    m_hwndList(NULL),
    m_hwndMain(NULL),
    m_hwndStatic(NULL),
    m_iCurrentPlaylist(-1),
    m_fSipOn(FALSE)
{
	memset(&m_shai, 0, sizeof(SHACTIVATEINFO));
	m_shai.cbSize = sizeof(SHACTIVATEINFO);
}

HRESULT CAddDeleteDialog::AddPlaylist(LPTSTR szPlaylistName, int iPos)
{
	// validate arguments
	if (NULL == szPlaylistName)
	{
		ASSERT(FALSE);
		return E_INVALIDARG;
	}

	LVITEM item;
	memset(&item, 0, sizeof (item));

	item.mask    = LVIF_TEXT | LVIF_PARAM;
	item.iItem   = ListView_GetItemCount(m_hwndList);
	item.pszText = szPlaylistName;

	if (iPos >= 0)
		item.iItem = iPos;

	int nIndex = ListView_InsertItem(m_hwndList, &item);

    return (nIndex >= 0) ? S_OK : E_FAIL;
}

HRESULT CAddDeleteDialog::DeletePlaylist(int iPlaylist)
{
    HRESULT hr;

    do
    {
        LVITEM item;

        memset(&item, 0, sizeof (item));

        item.mask = LVIF_PARAM;
        item.iItem = iPlaylist;

        if (!ListView_GetItem(m_hwndList, &item))
        {
            hr = E_FAIL;
            break;
        }

        delete [] (TCHAR*)item.pszText;

        if (!ListView_DeleteItem(m_hwndList, iPlaylist))
        {
            hr = E_FAIL;
            break;
        }

        hr = S_OK;
    } while (FALSE);

    return hr;
}

void CAddDeleteDialog::DisplayContextMenu(POINT ptAction)
{
    HMENU hmenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDM_PLAYLISTS_CONTEXT));

    if (NULL == hmenu)
    {
        return;
    }

    HMENU hmenuDD = GetSubMenu(hmenu, 0);

    if (NULL != hmenuDD)
    {
        int cSelected = ListView_GetSelectedCount(m_hwndList);

        // optionally disable various menu items, based on count of selected items
        if (1 != cSelected)
        {
           EnableMenuItem(hmenuDD, ID_CREATE_COPY, MF_BYCOMMAND | MF_GRAYED);
           EnableMenuItem(hmenuDD, IDC_RENAME_PLAYLIST, MF_BYCOMMAND | MF_GRAYED);
        }

        if (cSelected <= 0)
        {
           EnableMenuItem(hmenuDD, IDC_DELETE_PLAYLIST, MF_BYCOMMAND | MF_GRAYED);
        }

        TrackPopupMenuEx(hmenuDD, TPM_LEFTALIGN | TPM_TOPALIGN, ptAction.x,
                         ptAction.y, m_hwndDlg, NULL);
    }

    DestroyMenu(hmenu);
}

HRESULT CAddDeleteDialog::LoadAllPlaylists()
{
	CPlaylistMgr * pManager = CPlaylistMgr::GetInstance();
	int iFileCount;

	if (NULL != pManager)
		iFileCount = pManager->GetPlaylistCount();
	else
		iFileCount = 0;

	ListView_DeleteAllItems(m_hwndList);
	ListView_SetItemCount(m_hwndList, iFileCount);

	if (!pManager) return S_OK;

	for (int i = 0; i < iFileCount; i++)
	{
		LPTSTR szName = pManager->GetDisplayName(i);
		AddPlaylist(szName, i);
		if (szName) delete [] szName;
	}

    return S_OK;
}

BOOL CAddDeleteDialog::DialogProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
    BOOL fHandled = FALSE;
    int iCommand = HIWORD(wParam);
    int iControl = LOWORD(wParam);

    switch (msg)
    {
        case WM_INITDIALOG:
            OnInitDialog();
            fHandled = TRUE;
            if( g_bSmallScreen && g_AygshellHelper.Loaded() )
            {
                SHINITDLGINFO shidi;
                shidi.dwMask = SHIDIM_FLAGS;
                shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_SIPDOWN | SHIDIF_DONEBUTTON;
                shidi.hDlg = m_hwndDlg;
                g_AygshellHelper.SHInitDialog( &shidi );
            }
        break;

        case WM_COMMAND:
            if (0 == iCommand || 0x1000 == iCommand)
            {
                fHandled = OnCommand(iControl);
            }
        break;

        case WM_NOTIFY:
            fHandled = OnNotify((NMHDR*)lParam);
        break;

		case WM_SETTINGCHANGE:
			if (g_bSmallScreen && g_AygshellHelper.Loaded())
			{
				BOOL fRet, fSipOn;

				// fHandled = 0 if WM_SETTINGSCHANGE handled
				fRet = g_AygshellHelper.SHHandleWMSettingChange(
								m_hwndDlg, wParam, lParam, &m_shai);
				ASSERT(fRet);

				SIPINFO si;
				memset(&si, 0, sizeof(SIPINFO));
				si.cbSize = sizeof(SIPINFO);
				fRet = g_AygshellHelper.SHSipInfo(
						SPI_GETSIPINFO, (UINT)lParam, &si, 0);
				ASSERT(fRet);
				fSipOn = (si.fdwFlags & SIPF_ON);

				// if SIP status changed, snap listview ctl to dlg
				if (fSipOn != m_fSipOn)
				{
					// resize listview control inside dialog
					RECT rcDlg, rcLst;
					int i = -1;

					fRet = GetWindowRect(m_hwndDlg, &rcDlg); ASSERT(fRet);
					fRet = GetWindowRect(m_hwndList, &rcLst); ASSERT(fRet);
					fRet = SetWindowPos(m_hwndList, NULL, 0, 0,
								rcLst.right - rcLst.left,
								rcDlg.bottom - 10 - rcLst.top,
								SWP_NOMOVE | SWP_NOREPOSITION |
								SWP_NOZORDER); ASSERT(fRet);

					i = ListView_GetNextItem(m_hwndList, -1, LVNI_SELECTED);
					if (i >= 0) ListView_EnsureVisible(m_hwndList, i, FALSE);
				}

				m_fSipOn = fSipOn;
				fHandled = FALSE;	// fHandled = 0 if WM_SETTINGSCHANGE handled
			}
			else fHandled = TRUE;	// return non-zero if WM_SETTINGSCHANGE not handled
		break;
    }

    return fHandled;
}

BOOL CAddDeleteDialog::OnCommand(int iControl)
{
    int iPlaylist = -1;
    HRESULT hr = S_OK;
    HWND hwndEdit = NULL;
    BOOL fHandled = FALSE;
    LPCTSTR szFullName;
    TCHAR szNewName[MAX_PATH];
    TCHAR szCaption[MAX_PATH];
    TCHAR szText[MAX_PATH];
    int iItem;
    int iItemBefore;
    int cItem;
    int cmd;
    CPlaylist * pNewPlaylist = NULL;
    CPlaylist * pPlaylist    = NULL;
    CPlaylistMgr * pManager  = CPlaylistMgr::GetInstance();

    switch (iControl)
    {
        case ID_OPEN_PLAYLIST:
            if (NULL == pManager)
            {
                break;
            }

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

            iPlaylist = ListView_GetNextItem(m_hwndList, -1, LVNI_SELECTED);
            if (iPlaylist < 0)
            {
                break;
            }

            hr = S_OK;

            pManager->SetCurrentPlaylist(iPlaylist);
        break;

        case ID_CREATE_COPY:
            if (NULL == pManager)
            {
                break;
            }

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

            iPlaylist = ListView_GetNextItem(m_hwndList, -1, LVNI_SELECTED);
            if (iPlaylist < 0)
            {
                break;
            }

            pPlaylist = pManager->GetPlaylist(iPlaylist);

            if (pPlaylist)
            {
                szFullName = pPlaylist->GetPath();
            }
            else
            {
                break;
            }

            if (!pManager->CreateUniqueName(szNewName, MAX_PATH))
            {
                break;
            }

            if (!CopyFile(szFullName, szNewName, FALSE))
            {
                hr = HRESULT_FROM_WIN32(GetLastError());
                break;
            }

            {
                int iList = pManager->AddPlaylist(szNewName, iPlaylist+1);
                if (-1 == iList)
                {
                    hr = E_FAIL;
                    break;
                }

                // szNewName will be unique within it's folder, but not
                // necessarily unique across the file system.  So
                // differentiate the display name if necessary by adding
                // the path (szPath is NULL if playlist is unique)
                LPTSTR szName = pManager->GetDisplayName(iList);
                hr = AddPlaylist(szName, iPlaylist+1);
                if (szName) delete [] szName;
                if (FAILED(hr)) break;
            }

            if (iPlaylist < m_iCurrentPlaylist)
            {
                m_iCurrentPlaylist++;
            }

            LoadAllPlaylists();

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

        case IDC_NEW_PLAYLIST:
            pNewPlaylist = NULL;

            if (NULL == pManager)
            {
                break;
            }

            do
            {
                if (!CPlaylistMgr::CreateUniqueName(szNewName, MAX_PATH))
                {
                    break;
                }

                int iIndex = pManager->AddPlaylist(szNewName);
                if (iIndex < 0)
                {
                    hr = E_FAIL;
                    break;
                }

                pNewPlaylist = pManager->GetPlaylist(iIndex);
                if (NULL == pNewPlaylist)
                {
                    hr = E_FAIL;
                    break;
                }

                pNewPlaylist->IsCEPlaylist(true);
                if (!pNewPlaylist->Save())
                {
                    pNewPlaylist = NULL;
                    break;
                }

                LoadAllPlaylists();

                ListView_EnsureVisible(m_hwndList, iIndex, FALSE);

                SetFocus(m_hwndList);
                hwndEdit = ListView_EditLabel(m_hwndList, iIndex);
                SendMessage(hwndEdit, EM_SETLIMITTEXT, MAX_PLAYLIST_NAME, 0);
            } while (FALSE);

            pNewPlaylist = NULL;

            fHandled = TRUE;
            break;
        break;

        case IDC_DELETE_PLAYLIST:
            if (NULL == pManager)
            {

⌨️ 快捷键说明

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