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

📄 downloadui.cpp

📁 FreeAMP(MP3播放)程序源代码-用来研究MP3解码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void DownloadUI::UIThreadFunc(void* arg)
{
    DownloadUI* ui = (DownloadUI*)arg;

    ui->CreateUI();
}

Error DownloadUI::Init(int32 startup_type) 
{ 
    ParseArgs(m_context->argc, m_context->argv);

    if(startup_type == PRIMARY_UI)
    {
        ShowWindow(m_hwnd, SW_SHOWNORMAL);
    }

    return kError_NoErr;
}


BOOL DownloadUI::InitDialog()
{
    char title[100];
    
    GetWindowText(m_hwnd, title, 100);
    strcat(title, BRANDING);
    SetWindowText(m_hwnd, title);
    
    // get hwnds for all my controls
    m_hwndList = GetDlgItem(m_hwnd, IDC_LIST);
    m_hwndInfo = GetDlgItem(m_hwnd, IDC_INFO);
    m_hwndPause = GetDlgItem(m_hwnd, IDC_PAUSE);
    m_hwndCancel = GetDlgItem(m_hwnd, IDC_CANCEL);
    m_hwndResume = GetDlgItem(m_hwnd, IDC_RESUME);
    m_hwndClose = GetDlgItem(m_hwnd, IDC_CLOSE);
    m_hwndProgress = GetDlgItem(m_hwnd, IDC_OVERALL_PROGRESS);
    m_hwndText = GetDlgItem(m_hwnd, IDC_FREETRACKS);
    m_hwndCheck = GetDlgItem(m_hwnd, IDC_CHECK1);
    
    // Set the proc address as a property 
    // of the window so it can get it
    SetProp(m_hwndText, 
            "oldproc",
            (HANDLE)GetWindowLong(m_hwndText, GWL_WNDPROC));

    SetProp(m_hwndText, 
            "ui",
            (HANDLE)this);

    // Subclass the window so we can draw it
    SetWindowLong(  m_hwndText, 
                    GWL_WNDPROC, 
                    (DWORD)::FreeTracksWndProc ); 


    // Set the proc address as a property 
    // of the window so it can get it
    SetProp(m_hwndList, 
            "oldproc",
            (HANDLE)GetWindowLong(m_hwndList, GWL_WNDPROC));

    SetProp(m_hwndList, 
            "ui",
            (HANDLE)this);

    // Subclass the window so we can draw it
    SetWindowLong(m_hwndList, 
                    GWL_WNDPROC, 
                  (DWORD)::ListWndProc ); 

    // Set the proc address as a property 
    // of the window so it can get it
    SetProp(m_hwndProgress, 
            "oldproc",
            (HANDLE)GetWindowLong(m_hwndProgress, GWL_WNDPROC));

    SetProp(m_hwndProgress, 
            "ui",
            (HANDLE)this);

    // Subclass the window so we can draw it
    SetWindowLong(m_hwndProgress, 
                    GWL_WNDPROC, 
                  (DWORD)::ProgressWndProc ); 

    HINSTANCE hinst = (HINSTANCE)GetWindowLong(m_hwnd, GWL_HINSTANCE);
    HICON appIcon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_EXE_ICON));

    SetClassLong(m_hwnd, GCL_HICON, (LONG)appIcon);

    // initialize controls
    // first let's add our columns
    RECT rect;
    GetClientRect(m_hwndList, &rect);

    LV_COLUMN lvc;

    lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
    lvc.fmt = LVCFMT_LEFT; // left align column
    lvc.cx = (rect.right-rect.left)/2; // width of column in pixels
    lvc.pszText = "Song Title";
    lvc.iSubItem = 0;

    ListView_InsertColumn(m_hwndList, 0, &lvc);

    if((rect.right-rect.left)%2) // squeeze out every last pixel :)
        lvc.cx += 1;

    lvc.pszText = "Status";
    lvc.iSubItem = 1;

    ListView_InsertColumn(m_hwndList, 1, &lvc);

    lvc.pszText = "";
    lvc.cx = (rect.right-rect.left); // width of column in pixels
    lvc.iSubItem = 0;

    ListView_InsertColumn(m_hwndInfo, 0, &lvc);

    // init the images    
    m_noteImage = ImageList_Create(16, 16, ILC_MASK, 1, 0);
    HBITMAP bmp = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_NOTE));
    ImageList_AddMasked(m_noteImage, bmp, RGB(255,0,0));
    DeleteObject(bmp);

    m_progressBitmap = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_PROGRESS));

    // Set progress bitmap for overall progress view
    SetProp(m_hwndProgress, 
            "bitmap",
            (HANDLE)m_progressBitmap);

    ListView_SetImageList(m_hwndList, m_noteImage, LVSIL_SMALL);

    // Add items to info view
    LV_ITEM item;
    uint32 i;

    item.mask = LVIF_PARAM | LVIF_STATE;
    item.state = 0;
    item.stateMask = 0;
    item.iSubItem = 0;
    item.lParam = NULL;

    for(i = 0; i < 7; i++)
    {
        item.iItem = i;
        ListView_InsertItem(m_hwndInfo, &item);
    }

    // Add Items that are currently in the download manager
    /*DownloadItem* dli = NULL;
    i = 0;

    while(dli = m_dlm->ItemAt(i++))
    {
        item.mask = LVIF_PARAM | LVIF_STATE;
        item.state = 0;
        item.stateMask = 0;
        item.iItem = ListView_GetItemCount(m_hwndList);
        item.iSubItem = 0;
        item.lParam = (LPARAM)dli;

        ListView_InsertItem(m_hwndList, &item);

        if(dli->GetState() == kDownloadItemState_Queued ||
           dli->GetState() == kDownloadItemState_Downloading)
        {
            // bring window into view
            ShowWindow(m_hwnd, SW_SHOW);
            SetForegroundWindow(m_hwnd);
        }
    }

    UpdateOverallProgress();*/

	bool checkSet = false;
	m_prefs->GetPrefBoolean(kCloseDLMOnCompletePref, &checkSet);
	Button_SetCheck(m_hwndCheck, checkSet);
	
    m_handCursor = LoadCursor(g_hInstance, MAKEINTRESOURCE(IDC_HAND));

    if (strcasecmp(BRANDING_COMPANY, "EMusic") == 0)
    {
       SetWindowText(GetDlgItem(m_hwnd, IDC_DLMTEXT), szEMusicText);
       SetWindowText(GetDlgItem(m_hwnd, IDC_FREETRACKS), szEMusicURLText);
    }
    else
    {
       SetWindowText(GetDlgItem(m_hwnd, IDC_DLMTEXT), szFreeAmpText);
       SetWindowText(GetDlgItem(m_hwnd, IDC_FREETRACKS), szFreeAmpURLText);
    }

    m_uiSemaphore->Signal();
    return TRUE;
}

BOOL DownloadUI::DrawItem(int32 controlId, DRAWITEMSTRUCT* dis)
{
    BOOL result = TRUE;

    switch(controlId)
    {
        case IDC_FREETRACKS:
        {
            HFONT font = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
            HPEN pen = CreatePen(PS_SOLID, 1, RGB(0,0,238));
            HFONT oldFont;
            HPEN oldPen;
            char url[256];

            GetWindowText(dis->hwndItem, url, sizeof(url));

            oldFont = (HFONT)SelectObject(dis->hDC, font);
            oldPen = (HPEN)SelectObject(dis->hDC, pen);
               
            RECT clientRect;

            GetClientRect(dis->hwndItem, &clientRect);

            // Set the text background and foreground colors to the
            // standard window colors
            SetTextColor(dis->hDC, RGB(0,0,238));
            SetBkColor(dis->hDC, GetSysColor(COLOR_3DFACE));
             
            RECT rcClip = clientRect;
            int height = 0;

            height = DrawText(   
                        dis->hDC, 
                        url,
                        strlen(url),
                        &rcClip,
                        DT_LEFT|DT_WORDBREAK|DT_SINGLELINE|DT_CALCRECT);

            height = DrawText(   
                        dis->hDC, 
                        url,
                        strlen(url),
                        &rcClip,
                        DT_LEFT|DT_WORDBREAK|DT_SINGLELINE);

            rcClip.bottom = rcClip.top + height + 1;

            MoveToEx(dis->hDC, rcClip.left, rcClip.bottom, NULL);
            LineTo(dis->hDC, rcClip.right, rcClip.bottom);

            SelectObject(dis->hDC, oldFont);
            SelectObject(dis->hDC, oldPen);

            m_urlRect = rcClip;

            DeleteObject(font);
            DeleteObject(pen);
            break;
        }
        case IDC_OVERALL_PROGRESS:
        {
            HFONT font = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
            HFONT oldFont;
           
            if(m_progressBitmap)
            {
                string displayString;
                ostringstream ost;
                float total = m_totalBytes;
                float recvd = m_doneBytes;
                uint32 percent = 0;
                RECT clientRect;
                HDC hDc;
                HBITMAP hBitmap, hSavedBitmap;

                GetClientRect(m_hwndProgress, &clientRect);

                hDc = CreateCompatibleDC(dis->hDC);
                hBitmap = CreateCompatibleBitmap(dis->hDC, 
                           clientRect.right - clientRect.left,
                           clientRect.bottom - clientRect.top);
                hSavedBitmap = (HBITMAP)SelectObject(hDc, hBitmap);           
                oldFont = (HFONT)SelectObject(hDc, font);
            
                // Set the text background and foreground colors to the
                // standard window colors
                SetTextColor(hDc, GetSysColor(COLOR_WINDOWTEXT));
                SetBkColor(hDc, GetSysColor(COLOR_3DFACE));

                HBRUSH brush = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
                FillRect(hDc, &clientRect, brush);
                DeleteObject(brush);

                ost.precision(2);
                ost.flags(ios_base::fixed);

                if(total)
                    percent = (uint32)recvd/total*100;

                ost << percent << "%, " << m_doneItems << " of " << m_totalItems << " items (";

                if(total >= 1048576)
                {
                    total /= 1048576;
                    recvd /= 1048576;
                    
                    ost << recvd << " of " << total << " MB) ";
                }
                else if(total >= 1024)
                {
                    total /= 1024;
                    recvd /= 1024;
                    ost << recvd << " of " << total << " KB)";
                }
                else
                {
                    ost << m_doneBytes << " of " << m_totalBytes << " Bytes)";
                }

                displayString = string("Overall Progress:");

                SIZE stringSize;
                RECT rcClip = clientRect;

                GetTextExtentPoint32(hDc, displayString.c_str(), 
                                    displayString.size(), &stringSize);

                rcClip.left += 3;
                rcClip.top += ((rcClip.bottom - rcClip.top) - stringSize.cy)/2;
                rcClip.bottom = rcClip.top + stringSize.cy;

                ExtTextOut( hDc, 
                            rcClip.left, rcClip.top, 
                            ETO_CLIPPED | ETO_OPAQUE,
                            &rcClip, 
                            displayString.c_str(),
                            displayString.size(),
                            NULL);

                rcClip.left += stringSize.cx + kElementPadding;

                displayString = ost.str();

                GetTextExtentPoint32(hDc, displayString.c_str(), 
                                    displayString.size(), &stringSize);

                int32 progressWidth = 100;
                int32 bmpWidth = (float)(progressWidth - 3) * (float)percent/(float)100;
                int32 count = bmpWidth/(kProgressWidth);
                int32 remainder = bmpWidth%(kProgressWidth);

                HDC memDC = CreateCompatibleDC(hDc);              
                HBITMAP oldBitmap = (HBITMAP)SelectObject(memDC, m_progressBitmap);
                RECT progressRect = clientRect;

                progressRect.left = rcClip.left;
                progressRect.top += ((clientRect.bottom - clientRect.top) - kProgressHeight)/2 - 1;
                progressRect.bottom = progressRect.top + kProgressHeight + 2;
                progressRect.right = progressRect.left + progressWidth;

                DrawEdge(hDc, &progressRect, EDGE_SUNKEN, BF_RECT);

                uint32 i = 0;

                for(i = 0; i< count; i++)
                {
                    BitBlt(hDc, progressRect.left + 2 + i*kProgressWidth, progressRect.top + 2, kProgressWidth, kProgressHeight, 
                           memDC, 0, 0, SRCCOPY);

                }

                if(remainder)
                {
                    BitBlt(hDc, progressRect.left + 2 + i*kProgressWidth, progressRect.top + 2, remainder, kProgressHeight, 
                           memDC, 0, 0, SRCCOPY);
                }


                SelectObject(memDC, oldBitmap);
                DeleteDC(memDC);

                uint32 pad = 0;

                if(progressWidth)
                    pad = (progressWidth + kElementPadding);

                rcClip.left += pad;

                ExtTextOut( hDc, 
                            rcClip.left, rcClip.top, 
                            ETO_CLIPPED | ETO_OPAQUE,
                            &rcClip, 
                            displayString.c_str(),
                            displayString.size(),
                            NULL);

                BitBlt(dis->hDC, dis->rcItem.left, dis->rcItem.top,
                                 dis->rcItem.right - dis->rcItem.left, 
                                 dis->rcItem.bottom - dis->rcItem.top, 
                       hDc, 0, 0, SRCCOPY);          

                SelectObject(hDc, hSavedBitmap);
                DeleteObject(hBitmap);
                SelectObject(hDc, oldFont);
                DeleteDC(hDc);
            }

            DeleteObject(font);

            break;
        }

        case IDC_LIST:
        {
            uint32 uiFlags = ILD_TRANSPARENT;
            RECT rcClip;
            HIMAGELIST himl;

⌨️ 快捷键说明

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