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

📄 playlistview.cpp

📁 FreeAMP(MP3播放)程序源代码-用来研究MP3解码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                int32 middle;

                ListView_GetItemRect(hwnd, hti.iItem, &itemRect, LVIR_BOUNDS);

                middle = itemRect.top + (itemRect.bottom - itemRect.top)/2;

                if(hti.pt.y >= middle)
                {                    
                    insertIndex++; 
                }
			}

            char buf[256];
            sprintf(buf, "insert: %d\r\n", insertIndex);

            OutputDebugString(buf);

            vector<uint32> items;
            uint32 selected = ListView_GetSelectedCount(hwnd);
            uint32 count = ListView_GetItemCount(hwnd);
            uint32 index = 0;
            uint32 found = 0;

            for(index = 0, found = 0; found < selected && index < count; index++)
            {
                uint32 state = ListView_GetItemState(hwnd, 
                                                     index, 
                                                     LVIS_SELECTED);
                if(state & LVIS_SELECTED)
                {
                    items.push_back(index);
                    found++;
                }
            }

            m_plm->MoveItems(&items, insertIndex);

            break;
        }

        case UWM_DROPURLS:
            filesAreURLs = true;
        case WM_DROPFILES:
        {
            HDROP dropHandle = (HDROP)wParam;
            uint32 count;
            char url[1024];
            char path[MAX_PATH];
            vector<string> fileList;

            count = DragQueryFile(  dropHandle,
                                    -1L,
                                    url,
                                    sizeof(url));

            for(uint32 i = 0; i < count; i++)
            {
                DragQueryFile(  dropHandle,
                                i,
                                url,
                                sizeof(url));

                if(!filesAreURLs)
                {
                    uint32 length = sizeof(url);
                    strcpy(path, url);

                    // if this is a file drop it could be
                    // a couple things: a link, a dir, or 
                    // an mp3

                    char* extension = NULL;

                    extension = strrchr(path, '.');

                    if(extension && strcasecmp(extension, ".lnk") == 0)
                    { 
                        string link = path;

                        ResolveLink(link);

                        strcpy(path, link.c_str());
                    }

                    struct stat st;

                    stat(path, &st);

                    if(st.st_mode & _S_IFDIR)
                    {
                        vector<string> query;

                        query.push_back("*.mp1");
                        query.push_back("*.mp2");
                        query.push_back("*.mp3");
                        query.push_back("*.ogg");

                        ::SetCursor(LoadCursor(NULL, IDC_WAIT));
                        FindMusicFiles(path, fileList, query);
                        ::SetCursor(LoadCursor(NULL, IDC_ARROW));

                        continue;
                    }
                    else
                    {
                        FilePathToURL(path, url, &length);
                    }
                }

                fileList.push_back(url);
            }

            // we know that we are gonna be adding a 
            // bunch of items so let windows know.
            // it will make the adds more efficient
            uint32 newSize = ListView_GetItemCount(hwnd);
            newSize += fileList.size();
            ListView_SetItemCount(hwnd, newSize);

            LV_HITTESTINFO hti;
            RECT itemRect;

            DragQueryPoint(dropHandle, &hti.pt);
            int32 index = ListView_HitTest(hwnd, &hti);

            if(index < 0)
            {
                m_plm->AddItems(fileList);
            }
            else
            {   
                int32 middle;

                ListView_GetItemRect(hwnd, hti.iItem, &itemRect, LVIR_BOUNDS);

                middle = itemRect.top + (itemRect.bottom - itemRect.top)/2;

                if(hti.pt.y >= middle)
                    index++; 

                m_plm->AddItems(fileList, index);
            }

            SetFocus(hwnd);

            //char buf[256];
            //sprintf(buf, "x: %d   y: %d\r\n", pt.x, pt.y);
            //OutputDebugString(buf);
   
            break;
        }

        case WM_DRAWITEM:
        {
            DRAWITEMSTRUCT* dis = (DRAWITEMSTRUCT*) lParam;

            if(dis->CtlType == ODT_HEADER)
            {
                RECT rcClip = rcClip = dis->rcItem;
                UINT oldAlign;

                oldAlign = SetTextAlign(dis->hDC, TA_CENTER | TA_TOP );

                UINT left = rcClip.left + ((rcClip.right - rcClip.left)/2);
                UINT top = rcClip.top + 2; // + ((rcClip.bottom - rcClip.top)/2);

                ExtTextOut( dis->hDC,left, top, 
                        ETO_CLIPPED | ETO_OPAQUE,
                        &rcClip, 
                        "#",
                        strlen("#"),
                        NULL);

                SetTextAlign(dis->hDC, oldAlign);
            }

            break;
        }

        case WM_ERASEBKGND:
        {
            HDC hdc = (HDC) wParam;

            SCROLLINFO si;
            uint32 columnWidth = ListView_GetColumnWidth(hwnd, 0);
            
            RECT headerRect;
            GetClientRect(m_hPlaylistHeader, &headerRect);

            uint32 headerHeight = headerRect.bottom - headerRect.top;

            si.cbSize = sizeof(SCROLLINFO);
            si.fMask = SIF_ALL;

            GetScrollInfo(hwnd, SB_HORZ, &si);
            
            RECT rectClient, rectColumn;

            GetClientRect(hwnd, &rectClient);
            
            rectClient.top += headerHeight;

            if(si.nPos < columnWidth)
            {
                rectColumn = rectClient;
                rectColumn.right = rectColumn.left + columnWidth - si.nPos - 1;
                rectClient.left = rectColumn.right;
                
                COLORREF scrollColor = GetSysColor(COLOR_SCROLLBAR);
                COLORREF winColor = GetSysColor(COLOR_WINDOW);

                if(scrollColor == winColor)
                {
                    HBRUSH brush;
                    int r = GetRValue(scrollColor);
                    int g = GetGValue(scrollColor);
                    int b = GetBValue(scrollColor);

                    if(( r + g + b)/3 < 128)
                    {
                        r -= 25;
                        g -= 25;
                        b -= 25;

                        if(r < 0)
                            r = 0;
                        if(g < 0)
                            g = 0;
                        if(b < 0)
                            b = 0;
                    }
                    else
                    {
                        r += 25;
                        g += 25;
                        b += 25;

                        if(r > 255)
                            r = 255;
                        if(g > 255)
                            g = 255;
                        if(b > 255)
                            b = 255;
                    }

                    brush = CreateSolidBrush(RGB(r, g, b));

                    FillRect(hdc, &rectColumn, brush);
                    DeleteObject(brush);
                }
                else
                {
                    FillRect(hdc, &rectColumn, (HBRUSH)(COLOR_SCROLLBAR + 1)); //(COLOR_INFOBK + 1));
                }
            }

            FillRect(hdc, &rectClient, (HBRUSH)GetClassLong(hwnd, GCL_HBRBACKGROUND));

            return TRUE;
            break;
        }

        case WM_KEYDOWN:
        {
            // Ctrl + "+"
            if(wParam == VK_ADD && (GetKeyState(VK_CONTROL) < 0))
            {
                //  Disable repaints.
                SendMessage(m_hPlaylistView, WM_SETREDRAW, FALSE, 0);
                ShowWindow( m_hPlaylistView, SW_HIDE );

                //  Resize all columns
                HWND hwndList = GetDlgItem(m_hWnd, IDC_PLAYLISTBOX);
                HWND header = ListView_GetHeader(hwndList);
                int nCols   = Header_GetItemCount(header);
                for( int i = 1; i < nCols; i++ )
                {
                     ResizeHeader(hwnd, i);
                }
                               
                //  Enable repaints.
                ShowWindow( m_hPlaylistView, SW_SHOW);
                SendMessage(m_hPlaylistView, WM_SETREDRAW, TRUE, 0);
                return 0;
            }
            break;
        }

        case WM_NOTIFY:
        {
            int idCtrl = wParam; 
            HD_NOTIFY* hdn = (HD_NOTIFY*) lParam; 
            static int32 itemTrack = -1;
            static int32 oldWidth = 0;

            if(hdn->hdr.code == HDN_BEGINTRACKW)
            {
                if(hdn->iItem == 0 /*|| hdn->iItem == 4*/)
                    return TRUE; 

                //oldWidth = ListView_GetColumnWidth(hwnd, hdn->iItem);

                //itemTrack = hdn->iItem;
            }
            /*else if(hdn->hdr.code == HDN_ITEMCHANGINGW)
            {
                if(hdn->pitem->mask & HDI_WIDTH)                    
                {
                    if(hdn->iItem == itemTrack)
                    {
                        int32 currentWidth = ListView_GetColumnWidth(hwnd, hdn->iItem);
                        int32 nextHeaderWidth = ListView_GetColumnWidth(hwnd, hdn->iItem + 1);

                        int32 headerResizeAmount = hdn->pitem->cxy - currentWidth;

                        if(nextHeaderWidth - headerResizeAmount < 1)
                        {
                            return TRUE;
                        }
                    }
                }
            }
            else if(hdn->hdr.code == HDN_ITEMCHANGEDW)
            {
                if(hdn->iItem == itemTrack)
                {
                    int32 newWidth = ListView_GetColumnWidth(hwnd, hdn->iItem);
                    
                    int32 headerResizeAmount = newWidth - oldWidth;

                    int32 nextHeaderWidth = ListView_GetColumnWidth(hwnd, hdn->iItem + 1);

                    nextHeaderWidth -= headerResizeAmount;

                    ListView_SetColumnWidth(hwnd, hdn->iItem + 1, nextHeaderWidth);

                    oldWidth = newWidth;
                }
            }
            else if(hdn->hdr.code == HDN_ENDTRACKW)
            {
                itemTrack = -1;   
                oldWidth = 0;
            }*/
            else if(hdn->hdr.code == HDN_DIVIDERDBLCLICKW)
            {
                ResizeHeader(hwnd, hdn->iItem);

                return TRUE;
            }

            break;
        }
    } 
	
	//  Pass all non-custom messages to old window proc
	return CallWindowProc(lpOldProc, hwnd, msg, wParam, lParam );
}

int MusicBrowserUI::GetColumnIndex(const char *columnTitle)
{
    return (m_columnInfo.FindColumn((char  *)columnTitle));
}

const char *MusicBrowserUI::GetColumnText(int column)
{
    return (m_columnInfo.FindTitle(column));
}

⌨️ 快捷键说明

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