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

📄 cpi_playlistwindow.c

📁 VC++视频开发实例集锦(包括“远程视频监控”"语音识别系统"等13个经典例子)
💻 C
📖 第 1 页 / 共 4 页
字号:
/*
 * CoolPlayer - Blazing fast audio player.
 * Copyright (C) 2000-2001 Niek Albers
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
////////////////////////////////////////////////////////////////////////////////



#include "stdafx.h"
#include "globals.h"
#include "WindowsOS.h"
#include "CPI_Player.h"
#include "CPI_ID3.h"
#include "CPI_Playlist.h"
#include "CPI_PlaylistItem.h"
#include "CPI_PlaylistWindow.h"
#include "CPI_Indicators.h"


////////////////////////////////////////////////////////////////////////////////
//
typedef enum _CIe_PlaylistWindowMode
{
    wmQuiescent,
    wmListItem_Drag,
    wmCommandTarget_Click

} CIe_PlaylistWindowMode;
//
//
//
struct _CPs_PlaylistWindowState
{
    CIe_PlaylistWindowMode m_enWindowMode;
    CPs_CommandTarget* m_pActiveCommandTarget;
    CPs_CommandTarget* m_pFloatActiveCommandTarget;
    BOOL m_bMouseEventSet;

} glb_PLW_State;
//
////////////////////////////////////////////////////////////////////////////////





#define IDC_PL_LISTVIEW			0x0100
#define IDC_PL_FLOATINGEDIT		0x0101
#define IDC_PL_FLOATINGCOMBO	0x0102
#define CPPLM_CREATEINPLACE			(WM_APP+0x001)
#define CPPLM_DESTROYINPLACE		(WM_APP+0x002)
#define CPC_SIZEBORDER			0x4
//
#define IDC_CMDTS_CLEARSTACK		0x1
#define IDC_CMDTS_RESTACKALL		0x2
#define IDC_CMDTS_PLAYFROMHERE		0x3
#define IDC_CMDTS_UNSTACK			0x4
#define IDC_CMDTS_PLAYNOW			0x5
#define IDC_CMDTS_STOPAFTER			0x6
#define IDC_CMDTS_STOPAFTER_NOREP	0x7
#define IDC_CMDTS_PLAYNEXT			0x8
#define IDC_CMDTS_QUEUE				0x9
//
void LVCB_DrawBackgroundRect(CPs_DrawContext* pDC);
void LVCB_HeaderChanged(CP_HLISTVIEW _hListData);
void LVCB_ItemSelected(CP_HLISTVIEW _hListData, const int iItemIDX, const CP_HPLAYLISTITEM hItem);
void LVCB_ItemAction(CP_HLISTVIEW _hListData, const int iItemIDX, const CP_HPLAYLISTITEM hItem);
void LVCB_ItemDrag(CP_HLISTVIEW _hListData, const int iItemIDX, const CP_HPLAYLISTITEM hItem);
void LVCB_ItemRightClick(CP_HLISTVIEW _hListData, const int iItemIDX, const int iColumnIDX, const CP_HPLAYLISTITEM hItem);
void LVCB_ColHeaderClick(CP_HLISTVIEW _hListData, const int iColIDX);
void LVCB_UnhandledKeyPress(CP_HLISTVIEW _hListData, const int iVKey, const BOOL bAlt, const BOOL bCtrl, const BOOL bShift);
CPe_CustomDrawColour LVCB_GetTrackStackItemColour(const void* pvItemData);
CPe_CustomDrawColour LVCB_GetItemColour(const void* pvItemData);

void CPlaylistWindow_CB_onCreate(CP_HINTERFACE hInterface, const RECT* pInitialPosition);
void CPlaylistWindow_CB_onDraw(CP_HINTERFACE hInterface, CPs_DrawContext* pContext);
void CPlaylistWindow_CB_onKeyDown(CP_HINTERFACE hInterface, const unsigned int iVKeyCode, const BOOL bAlt, const BOOL bCtrl, const BOOL bShift);
void CPlaylistWindow_CB_onDropFiles(CP_HINTERFACE hInterface, HDROP hDrop);
void CPlaylistWindow_CB_onPosChange(CP_HINTERFACE hInterface, const RECT* pNewPosition, const BOOL bSizeChanged);
void CPlaylistWindow_CB_onFocus(CP_HINTERFACE hInterface, const BOOL bHasFocus);
void CPlaylistWindow_CB_onCommandMessage(CP_HINTERFACE hInterface, const WPARAM wParam, const LPARAM lParam);

void CPlaylistWindow_CB_onMouseMove(CP_HINTERFACE hInterface, const POINTS ptMouse, const unsigned short iFlags);
void CPlaylistWindow_CB_onMouseButton_LUp(CP_HINTERFACE hInterface, const POINTS ptMouse, const unsigned short iFlags);
LRESULT CPlaylistWindow_CB_onAppMessage(CP_HINTERFACE hInterface, const UINT uiMessage, const WPARAM wParam, const LPARAM lParam);
void CPlaylistWindow_CB_onClose(CP_HINTERFACE hInterface);
//
void CPlaylistWindow_CreateSubparts();
////////////////////////////////////////////////////////////////////////////////
//
//
//
void CPlaylistWindow_Create()
{
    // Init playlist window state
    glb_PLW_State.m_enWindowMode = wmQuiescent;
    glb_PLW_State.m_pActiveCommandTarget = NULL;
    glb_PLW_State.m_pFloatActiveCommandTarget = NULL;
    glb_PLW_State.m_bMouseEventSet = FALSE;

    // Create user interface window
    windows.m_hifPlaylist = IF_Create();
    IF_sethandler_onCreate(windows.m_hifPlaylist, CPlaylistWindow_CB_onCreate);
    IF_sethandler_onDraw(windows.m_hifPlaylist, CPlaylistWindow_CB_onDraw);
    IF_sethandler_onKeyDown(windows.m_hifPlaylist, CPlaylistWindow_CB_onKeyDown);
    IF_sethandler_onDropFiles(windows.m_hifPlaylist, CPlaylistWindow_CB_onDropFiles);
    IF_sethandler_onPosChange(windows.m_hifPlaylist, CPlaylistWindow_CB_onPosChange);
    IF_sethandler_onFocus(windows.m_hifPlaylist, CPlaylistWindow_CB_onFocus);
    IF_sethandler_onCommandMessage(windows.m_hifPlaylist, CPlaylistWindow_CB_onCommandMessage);
    IF_sethandler_onAppMessage(windows.m_hifPlaylist, CPlaylistWindow_CB_onAppMessage);
    IF_sethandler_onClose(windows.m_hifPlaylist, CPlaylistWindow_CB_onClose);

    // Add interface subparts
    CPlaylistWindow_CreateSubparts();

    IF_SetMinSize(windows.m_hifPlaylist, &glb_pSkin->mpl_szMinWindow);
    IF_OpenWindow(windows.m_hifPlaylist, "CoolPlayer Playlist", &options.playlist_window_pos, CPC_INTERFACE_STYLE_RESIZING);
    IF_SetVisible(windows.m_hifPlaylist, options.show_playlist);
}
//
//
//
void CPlaylistWindow_Destroy()
{
    // Cleanup windows
    IF_CloseWindow(windows.m_hifPlaylist);
    globals.m_hPlaylistViewControl = NULL;
}
//
//
//
void CPlaylistWindow_CreateSubparts()
{

    IF_RemoveAllSubparts(windows.m_hifPlaylist);

    {
        CPs_CommandTarget* pCT_Cursor;
        for(pCT_Cursor = glb_pSkin->mpl_pCommandTargets; pCT_Cursor; pCT_Cursor = (CPs_CommandTarget*)pCT_Cursor->m_pNext)
        {
            IF_AddSubPart_CommandButton(windows.m_hifPlaylist,
                                        pCT_Cursor->m_dwAlign,
                                        &pCT_Cursor->m_ptOffset,
                                        pCT_Cursor->m_pStateImage,
                                        pCT_Cursor->m_pfnVerb);
        }
    }

    {
        CPs_Indicator* pI_Cursor;
        for(pI_Cursor = glb_pSkin->mpl_pIndicators; pI_Cursor; pI_Cursor = (CPs_Indicator*)pI_Cursor->m_pNext)
        {
            IF_AddSubPart_Indicator(windows.m_hifPlaylist,
                                    pI_Cursor->m_pcName,
                                    pI_Cursor->m_dwAlign,
                                    &pI_Cursor->m_rAlign);
        }
    }
}
//
//
//
void CPlaylistWindow_SetVisible(const BOOL bNewVisibleState)
{
    CheckMenuItem(globals.main_menu_popup, MENU_PLAYLIST, MF_BYCOMMAND | (bNewVisibleState ? MF_CHECKED : 0));
    IF_SetVisible(windows.m_hifPlaylist, bNewVisibleState);
}
//
//
//
void CPlaylistWindow_CreateListView()
{
    RECT rClient;
    int iColumnIDX;

    // Create listview control
    GetClientRect(IF_GetHWnd(windows.m_hifPlaylist), &rClient);
    globals.m_hPlaylistViewControl = CLV_Create(IF_GetHWnd(windows.m_hifPlaylist),
                                     glb_pSkin->mpl_rList_Border.left, glb_pSkin->mpl_rList_Border.top,
                                     (rClient.right - glb_pSkin->mpl_rList_Border.right) - glb_pSkin->mpl_rList_Border.left,
                                     (rClient.bottom - glb_pSkin->mpl_rList_Border.bottom) - glb_pSkin->mpl_rList_Border.top);

    // Setup callbacks
    CLV_sethandler_DrawBackgroundRect(globals.m_hPlaylistViewControl, LVCB_DrawBackgroundRect);
    CLV_sethandler_HeaderChanged(globals.m_hPlaylistViewControl, LVCB_HeaderChanged);
    CLV_sethandler_ItemSelected(globals.m_hPlaylistViewControl, (wp_ItemCallback)LVCB_ItemSelected);
    CLV_sethandler_ItemAction(globals.m_hPlaylistViewControl, (wp_ItemCallback)LVCB_ItemAction);
    CLV_sethandler_ItemDrag(globals.m_hPlaylistViewControl, (wp_ItemCallback)LVCB_ItemDrag);
    CLV_sethandler_ItemRightClick(globals.m_hPlaylistViewControl, (wp_ItemSubCallback)LVCB_ItemRightClick);
    CLV_sethandler_ColHeaderClick(globals.m_hPlaylistViewControl, LVCB_ColHeaderClick);
    CLV_sethandler_UnhandledKeyPress(globals.m_hPlaylistViewControl, LVCB_UnhandledKeyPress);

    // Setup columns
    CLV_AddColumn(globals.m_hPlaylistViewControl,
                  "Stack",
                  options.playlist_column_widths[0],
                  (wp_GetItemText)CPLI_GetTrackStackPos_AsText,
                  CPLV_COLFLAG_NOHIDE);
    CLV_SetColumnCustomDrawColour(globals.m_hPlaylistViewControl, PLAYLIST_TRACKSTACK, LVCB_GetTrackStackItemColour);
    CLV_SetColumnAlign(globals.m_hPlaylistViewControl, PLAYLIST_TRACKSTACK, lcaRight);
    CLV_AddColumn(globals.m_hPlaylistViewControl,
                  "Title",
                  options.playlist_column_widths[1],
                  (wp_GetItemText)CPLI_GetTrackName,
                  options.playlist_column_visible[1] ? CPLV_COLFLAG_NONE : CPLV_COLFLAG_HIDDEN);
    CLV_AddColumn(globals.m_hPlaylistViewControl,
                  "Artist",
                  options.playlist_column_widths[2],
                  (wp_GetItemText)CPLI_GetArtist,
                  options.playlist_column_visible[2] ? CPLV_COLFLAG_NONE : CPLV_COLFLAG_HIDDEN);
    CLV_AddColumn(globals.m_hPlaylistViewControl,
                  "Album",
                  options.playlist_column_widths[3],
                  (wp_GetItemText)CPLI_GetAlbum,
                  options.playlist_column_visible[3] ? CPLV_COLFLAG_NONE : CPLV_COLFLAG_HIDDEN);
    CLV_AddColumn(globals.m_hPlaylistViewControl,
                  "Year",
                  options.playlist_column_widths[4],
                  (wp_GetItemText)CPLI_GetYear,
                  options.playlist_column_visible[4] ? CPLV_COLFLAG_NONE : CPLV_COLFLAG_HIDDEN);
    CLV_AddColumn(globals.m_hPlaylistViewControl,
                  "TrackNum",
                  options.playlist_column_widths[5],
                  (wp_GetItemText)CPLI_GetTrackNum_AsText,
                  options.playlist_column_visible[5] ? CPLV_COLFLAG_NONE : CPLV_COLFLAG_HIDDEN);
    CLV_SetColumnAlign(globals.m_hPlaylistViewControl, PLAYLIST_TRACKNUM, lcaRight);
    CLV_AddColumn(globals.m_hPlaylistViewControl,
                  "Comment",
                  options.playlist_column_widths[6],
                  (wp_GetItemText)CPLI_GetComment,
                  options.playlist_column_visible[6] ? CPLV_COLFLAG_NONE : CPLV_COLFLAG_HIDDEN);
    CLV_AddColumn(globals.m_hPlaylistViewControl,
                  "Genre",
                  options.playlist_column_widths[7],
                  (wp_GetItemText)CPLI_GetGenre,
                  options.playlist_column_visible[7] ? CPLV_COLFLAG_NONE : CPLV_COLFLAG_HIDDEN);
    CLV_AddColumn(globals.m_hPlaylistViewControl,
                  "Path",
                  options.playlist_column_widths[8],
                  (wp_GetItemText)CPLI_GetPath,
                  options.playlist_column_visible[8] ? CPLV_COLFLAG_NONE : CPLV_COLFLAG_HIDDEN);
    CLV_AddColumn(globals.m_hPlaylistViewControl,
                  "Filename",
                  options.playlist_column_widths[9],
                  (wp_GetItemText)CPLI_GetFilename,
                  options.playlist_column_visible[9] ? CPLV_COLFLAG_NONE : CPLV_COLFLAG_HIDDEN);
    CLV_AddColumn(globals.m_hPlaylistViewControl,
                  "Length",
                  options.playlist_column_widths[10],
                  (wp_GetItemText)CPLI_GetTrackLength_AsText,
                  options.playlist_column_visible[10] ? CPLV_COLFLAG_NONE : CPLV_COLFLAG_HIDDEN);
    CLV_SetColumnAlign(globals.m_hPlaylistViewControl, PLAYLIST_LENGTH, lcaRight);

    for(iColumnIDX = 1; iColumnIDX <= PLAYLIST_last; iColumnIDX++)
        CLV_SetColumnCustomDrawColour(globals.m_hPlaylistViewControl, iColumnIDX, LVCB_GetItemColour);

    CLV_SetColumnOrder(globals.m_hPlaylistViewControl, options.playlist_column_seq, PLAYLIST_last+1);
    CPL_cb_SetWindowToReflectList();
}
//
//
//
int __cdecl exp_CompareStrings(const void *elem1, const void *elem2)
{
    const char* pcElem1 = *(const char**)elem1;
    const char* pcElem2 = *(const char**)elem2;
    return stricmp(pcElem1, pcElem2);
}
//
//
//
void CPlaylistWindow_DestroyIPEdit()
{
    HWND hWnd_IPEdit;
    if(!windows.wnd_playlist_IPEdit)
        return;

    hWnd_IPEdit = windows.wnd_playlist_IPEdit;
    UnhookWindowsHookEx(globals.m_hhkListView_Posted);
    globals.m_hhkListView_Posted = NULL;
    windows.wnd_playlist_IPEdit = NULL;

    DestroyWindow(hWnd_IPEdit);

    // Write any dirty playlist items - Check all items because the selection could have
    // changed by now
   {
        char cStatusMessage[1024];
        CP_HPLAYLISTITEM hCursor;

        SetCursor(LoadCursor(NULL, IDC_WAIT));
        for(hCursor = CPL_GetFirstItem(globals.m_hPlaylist); hCursor; hCursor = CPLI_Next(hCursor))
        {
            if(CPLI_IsTagDirty(hCursor) == FALSE)
                continue;

            sprintf(cStatusMessage, "Tagging \"%s\"", CPLI_GetFilename(hCursor));
            CPIC_SetIndicatorValue("status", cStatusMessage);
            UpdateWindow(IF_GetHWnd(windows.m_hifPlaylist));

            CPLI_WriteTag(hCursor);
        }
        SetCursor(LoadCursor(NULL, IDC_ARROW));
        CPIC_SetIndicatorValue("status", NULL);
    } 
}
//
//
//
LRESULT CALLBACK exp_ListViewHookProc_Posted(int iCode, WPARAM wParam, LPARAM lParam)
{
    if(iCode == HC_ACTION && windows.wnd_playlist_IPEdit)
    {
        MSG* pMSG = (MSG*)lParam;

        // If any window (apart from the IP window) has a mouse click - close the IP window
        if( (pMSG->message == WM_LBUTTONDOWN
                || pMSG->message == WM_MBUTTONDOWN
                || pMSG->message == WM_RBUTTONDOWN
                || pMSG->message == WM_NCLBUTTONDOWN
                || pMSG->message == WM_NCMBUTTONDOWN

⌨️ 快捷键说明

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