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

📄 dialog.cpp

📁 vc++ mp3 源码下载 使用vc写的mp3 播放器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*____________________________________________________________________________

        FreeAmp - The Free MP3 Player

        Portions Copyright (C) 1999 EMusic.com

        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., 675 Mass Ave, Cambridge, MA 02139, USA.

        $Id: Dialog.cpp,v 1.63 2000/01/21 10:01:20 elrod Exp $
____________________________________________________________________________*/

#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <direct.h>

#include "config.h"
#include "utility.h"
#include "resource.h"
#include "Win32MusicBrowser.h"
#include "eventdata.h"
#include "help.h"
#include "preferences.h"

#define UWM_EMPTYDBCHECK WM_USER + 69
 

TBBUTTON tbButtons[] = {
    { 0, ID_FILE_NEWPLAYLIST, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, -1},
    { 1, ID_FILE_SAVEPLAYLIST, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, -1},
	{ 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, -1},
    { 2, ID_FILE_IMPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, -1},
	{ 3, ID_EDIT_REMOVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, -1},
	{ 4, ID_EDIT_EDITINFO, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, -1},
    { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, -1},
    { 5, ID_EDIT_ADDTRACK, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, -1},
    { 6, ID_EDIT_ADDFILE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, -1},
    { 7, ID_EDIT_MOVEUP, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, -1},
    { 8, ID_EDIT_MOVEDOWN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, -1} 
};

static BOOL CALLBACK MainDlgProc(HWND hwnd, UINT msg, 
                                 WPARAM wParam, LPARAM lParam )
{
    MusicBrowserUI* ui = (MusicBrowserUI*)GetWindowLong(hwnd, GWL_USERDATA);
    switch (msg)
    {
        case WM_INITDIALOG:
        {
            ui = (MusicBrowserUI*)lParam;
            assert(ui != NULL);
            SetWindowLong(hwnd, GWL_USERDATA, (LONG)ui);
            
        	ui->InitDialog(hwnd);
        	ui->SetMinMaxInfo();
            return 1;
        }
        default:
            return ui->DialogProc(hwnd, msg, wParam, lParam);
    }
}        

BOOL MusicBrowserUI::DialogProc(HWND hwnd, UINT msg, 
                                WPARAM wParam, LPARAM lParam )
{
    bool filesAreURLs = false;

    switch (msg)
    {
        case WM_DESTROY:
        {
            Destroy();
            break;
        }

		case WM_CLOSE:
        {
			Close();
            return 1;
        }    

        case UWM_DROPURLS:
            filesAreURLs = true;
        case WM_DROPFILES:
        {
            DropFiles((HDROP)wParam, filesAreURLs);
            return 0;
        }

        case WM_SYSCOLORCHANGE:
        {
            SendMessage(m_hMusicView, WM_SYSCOLORCHANGE, 0, 0);
            SendMessage(m_hPlaylistView, WM_SYSCOLORCHANGE, 0, 0);
            SendMessage(m_hRebar, WM_SYSCOLORCHANGE, 0, 0);

             // update REBARBANDINFO for all rebar bands
            REBARBANDINFO rbb;

	        rbb.cbSize = sizeof(REBARBANDINFO);
	        rbb.fMask = RBBIM_COLORS;
	        rbb.clrFore = GetSysColor(COLOR_BTNTEXT);
	        rbb.clrBack = GetSysColor(COLOR_BTNFACE );	       

            SendMessage(m_hRebar, RB_SETBANDINFO, 0, (LPARAM)&rbb);
            SendMessage(m_hToolbar, WM_SYSCOLORCHANGE, 0, 0);
            break;
        }

		case WM_SIZE:
        {
            SizeWindow(wParam, LOWORD(lParam), HIWORD(lParam));
            return 1;
        } 
		case WM_NOTIFY:
            return Notify(wParam, (LPNMHDR)lParam);
            
		case WM_GETMINMAXINFO:
            GetMinMaxInfo((MINMAXINFO *)lParam);
            break;

        case WM_SETCURSOR:
            return SetCursor(LOWORD(lParam), HIWORD(lParam));
            break;

        case WM_MOUSEMOVE:
        {
            POINT sPoint;   
            sPoint.x = LOWORD(lParam);
            sPoint.y = HIWORD(lParam);  
            MouseMove((uint32)wParam, sPoint);
            return 1;
        }

        case WM_LBUTTONDOWN:
            MouseButtonDown(wParam, LOWORD(lParam), HIWORD(lParam));
            return 1;

        case WM_LBUTTONUP:
            MouseButtonUp(wParam, LOWORD(lParam), HIWORD(lParam));
            return 1;
            
        case UWM_EMPTYDBCHECK:
            EmptyDBCheck();
            return 1;

        case WM_HELP:
            ShowHelp(Music_Browser);
            return 1;

        case WM_COMMAND:
        {
        	switch(LOWORD(wParam))
            {
                case 2: // what is this? we get it when we press ESC.
                    if(m_bSearchInProgress)
                    {
                        StartStopMusicSearch();  
                    }
                    return 1;

                case ID_POPUP_RENAME:
                    RenameEvent();
                    break;

                case ID_POPUP_ADDTRACK_PLAY:
                    AddTrackAndPlayEvent();
                    break;

                case ID_POPUP_PLAY:
                    PlayNowEvent();
                    break;

                case ID_FILE_NEWPLAYLIST:
                    NewPlaylist();
                    return 1;

                case ID_FILE_OPENPLAYLIST:
                    OpenPlaylist();
                    return 1;

                case ID_FILE_SAVEPLAYLIST:
                    SavePlaylist();
                    return 1;

                case ID_FILE_SAVEASPLAYLIST:
                    SavePlaylistAs();
                    return 1;

                case ID_FILE_IMPORT:
                    ImportTracksAndPlaylists();
                    return 1;

                case ID_FILE_EXPORTPLAYLIST:
                    ExportPlaylistEvent();
                    return 1;
                
                case ID_FILE_SEARCHFORMUSIC:
                    StartStopMusicSearch();
                    return 1;
                
                case ID_FILE_CLOSEPLAYLIST:
                    Close();
                    return 1;

                case ID_EDIT_UNDO_ACTION:
                    m_oPlm->Undo();
                    return 1;

                case ID_EDIT_REDO_ACTION:
                    m_oPlm->Redo();
                    return 1;

                case ID_POPUP_ADDTRACK:
                case ID_EDIT_ADDTRACK:
                    AddTrackEvent();
                    return 1;

                case ID_EDIT_ADDFILE:
                    AddFileEvent(m_hWnd);
                    return 1;

                case ID_POPUP_REMOVE:
                case ID_EDIT_REMOVE:
                    RemoveEvent();
                    return 1;

                case ID_POPUP_MOVEUP:
                case ID_EDIT_MOVEUP:
                    MoveUpEvent();
                    return 1;

                case ID_POPUP_MOVEDOWN:
                case ID_EDIT_MOVEDOWN:
                    MoveDownEvent();
                    return 1;

                case ID_EDIT_CLEARPLAYLIST:
                    ClearPlaylistEvent();
                    return 1;

                case ID_POPUP_EDITPLAYLIST:
                case ID_EDIT_EDITPLAYLIST:
                    EditPlaylistEvent();
                    return 1;

                case ID_POPUP_EDITINFO:
                case ID_EDIT_EDITINFO:
                    EditInfoEvent();
                    return 1;
                
                case ID_VIEW_MUSICCATALOG:
                    ExpandCollapseEvent();
                    return 1;

                case ID_VIEW_OPTIONS:
                    m_context->target->AcceptEvent(new ShowPreferencesEvent());
                    return 1;
                    

                case ID_CONTROLS_PLAYPAUSE:
                case ID_CONTROLS_STOP:
                case ID_CONTROLS_PREVIOUSSONG:
                case ID_CONTROLS_NEXTSONG:
                case ID_CONTROLS_NORMALORDER:
                case ID_CONTROLS_SHUFFLE:
                case ID_CONTROLS_REPEATNONE:
                case ID_CONTROLS_REPEATONE:
                case ID_CONTROLS_REPEATALL:
                    PlayerControlsEvent(LOWORD(wParam));
                    return 1;


                case ID_SORT_ARTIST:
                case ID_SORT_ALBUM:
                case ID_SORT_TITLE:
                case ID_SORT_LENGTH:
                case ID_SORT_YEAR:
                case ID_SORT_TRACK:
                case ID_SORT_GENRE:
                case ID_SORT_LOCATION:
                case ID_SORT_RANDOMIZE:
                case IDC_RANDOMIZE:
                    SortEvent(LOWORD(wParam));
                    return 1;


                case ID_HELP_CONTENTS:
                    ShowHelp(Music_Browser);
                    return 1;

                case ID_HELP_FREEAMPWEBSITE:
                    ShellExecute(   hwnd, 
                                    "open", 
                                    "http://www.freeamp.org/", 
                                    NULL, 
                                    NULL, 
                                    SW_SHOWNORMAL);
                    return 1;

                case ID_HELP_EMUSICCOMWEBSITE:
                    ShellExecute(   hwnd, 
                                    "open", 
                                    "http://www.emusic.com/", 
                                    NULL, 
                                    NULL, 
                                    SW_SHOWNORMAL);
                    return 1;

                case ID_HELP_ABOUT:
                    m_context->target->AcceptEvent(new ShowPreferencesEvent(6));
                    return 1;
            }    
        }     

        case WM_DRAWITEM:
        {
            return DrawItem(wParam, (DRAWITEMSTRUCT*) lParam);

            break;
        }
        
        case WM_MEASUREITEM:
        {
            MEASUREITEMSTRUCT* mis = (MEASUREITEMSTRUCT*) lParam;
            TEXTMETRIC tm;
            HDC hdc;
	        HFONT hFont;
	        HWND hwndLV;


            // Make sure the control is the listview control
            if (mis->CtlType != ODT_LISTVIEW || mis->CtlID != IDC_PLAYLISTBOX)
                return FALSE;

	        // Get the handle of the ListView control we're using
	        hwndLV = GetDlgItem(hwnd, mis->CtlID);

	        // Get the font the control is currently using
	        hFont = (HFONT)(DWORD) SendMessage(hwndLV, WM_GETFONT, 0, 0L);

	        // Set the font of the DC to the same font the control is using
            hdc = GetDC(hwndLV);
	        SelectObject(hdc, hFont);

            // Get the height of the font used by the control
            if (!GetTextMetrics(hdc, &tm))
                return FALSE;

            // Add a little extra space between items
            mis->itemHeight = tm.tmHeight + 1;

            // Make sure there is enough room for the images which are CY_SMICON high
            if (mis->itemHeight < 17)
    	        mis->itemHeight = 17;

	        // Clean up
	        ReleaseDC(hwndLV, hdc);

            return TRUE;

            break;
        }

    }
    
    return 0;
}

bool MusicBrowserUI::CreateMainDialog()
{
    MSG   msg;

	m_hWnd = CreateDialogParam( g_hinst, 
                    MAKEINTRESOURCE(IDD_MUSICBROWSER),
                    NULL,
                    (DLGPROC)MainDlgProc, 
                    (LPARAM)this);
    if(m_hWnd)
    {
        if(m_pParent)
        {
            RECT sRect;
            
            GetWindowRect(m_hParent, &sRect);
            SetWindowPos(m_hWnd, NULL, sRect.left + 20, sRect.top + 20,
                         0, 0, SWP_NOZORDER|SWP_NOSIZE);

⌨️ 快捷键说明

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