欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

downloadui.cpp

freeamp有名的媒体播放器
CPP
第 1 页 / 共 5 页
字号:
           break;
           
       case kDownloadItemState_Downloading:
           EnableWindow(m_hwndPause, TRUE);
           EnableWindow(m_hwndCancel, TRUE);
           EnableWindow(m_hwndResume, FALSE);
           SetWindowText(m_hwndResume, "Resume");
           break;
       
       case kDownloadItemState_Cancelled:
       case kDownloadItemState_Error:
           EnableWindow(m_hwndPause, FALSE);
           EnableWindow(m_hwndCancel, FALSE);
           EnableWindow(m_hwndResume, TRUE);
           SetWindowText(m_hwndResume, "Resume");
           break;

       case kDownloadItemState_Paused:
           EnableWindow(m_hwndPause, FALSE);
           EnableWindow(m_hwndCancel, TRUE);
           EnableWindow(m_hwndResume, TRUE);
           SetWindowText(m_hwndResume, "Resume");
           break;
       
       case kDownloadItemState_Done:
           EnableWindow(m_hwndPause, FALSE);
           EnableWindow(m_hwndCancel, FALSE);
           EnableWindow(m_hwndResume, FALSE);
           SetWindowText(m_hwndResume, "Resume");
           break;

       default:
           break;
   }
}

BOOL CALLBACK DownloadUI::MainProc(	HWND hwnd, 
						            UINT msg, 
						            WPARAM wParam, 
						            LPARAM lParam )
{
	BOOL result = FALSE;
    static DownloadUI* m_ui = NULL;

	switch(msg)
	{
		case WM_INITDIALOG:
		{
            m_ui = (DownloadUI*)lParam;

            m_ui->SetWindowHandle(hwnd);

            result = m_ui->InitDialog();

            result = FALSE;
			break;
		}     

        case WM_INITMENUPOPUP:
        {
            HMENU menuPopup = (HMENU)wParam;
            BOOL fSystemMenu = (BOOL) HIWORD(lParam);

            if(fSystemMenu)
            {
                int32 count = GetMenuItemCount(menuPopup);

                for(int32 i = 0; i < count; i++)
                {
                    int32 id = GetMenuItemID(menuPopup, i);

                    if(61488 == id || id == 61440) // MAXIMIZE & SIZE COMMAND
                    {
                        EnableMenuItem(menuPopup, id, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
                    }
                }
            }

            result = TRUE;
            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_INFO)
                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);

            result =  TRUE;
            break;
        }

        case WM_DRAWITEM:
        {
            result = m_ui->DrawItem(wParam, (DRAWITEMSTRUCT*) lParam);
            break;
        }

		case WM_COMMAND:
		{
            result = m_ui->Command(wParam, (HWND)lParam);
            break;
        }     
        
        case WM_HELP:
        {
            m_ui->ShowHelp(Download_Manager);
            return 1;
        }
            
        case WM_NOTIFY:
        {
            result = m_ui->Notify(wParam, (NMHDR*)lParam);
            break;
        }  

		case WM_CLOSE:
		{
			ShowWindow(hwnd, SW_HIDE);
			result = TRUE;
			break;
        }

        case WM_DESTROY:
        {
            result = m_ui->Destroy();
            break;
        }
	}

	return result;
}

uint32 DownloadUI::CalcStringEllipsis(HDC hdc, string& displayString, int32 columnWidth)
{
    const TCHAR szEllipsis[] = TEXT("...");
    SIZE   sizeString;
    SIZE   sizeEllipsis;
    string temp;
    
    // Adjust the column width to take into account the edges
    //columnWidth -= 4;

    temp = displayString;        

    GetTextExtentPoint32(hdc, temp.c_str(), temp.size(), &sizeString);       

    // If the width of the string is greater than the column width shave
    // the string and add the ellipsis
    if(sizeString.cx >= columnWidth)
    {
        GetTextExtentPoint32(hdc, szEllipsis, strlen(szEllipsis), &sizeEllipsis);
       
        while(temp.size() > 1)
        {
            temp.erase(temp.size() - 1, 1);

            GetTextExtentPoint32(hdc, temp.c_str(), temp.size(), &sizeString);
            
            if((sizeString.cx + sizeEllipsis.cx) < columnWidth)
            {
                // The string with the ellipsis finally fits                
                // Concatenate the two strings and break out of the loop
                temp += szEllipsis;
                displayString = temp;
                break;
            }
            else if(temp.size() == 1)
            {
                temp += szEllipsis;
                displayString = temp;
                break;
            }
        }
    }

    GetTextExtentPoint32(hdc, displayString.c_str(), displayString.size(), &sizeString);

    return sizeString.cx;
}

void DownloadUI::UpdateOverallProgress()
{
    uint32 itemCount =  ListView_GetItemCount(m_hwndList);
    uint32 totalBytes = 0, doneBytes = 0;
    uint32 totalItems = 0, doneItems = 0;
    DownloadItem* dli = NULL;

    if(itemCount)
    {
        LV_ITEM item;

        for(uint32 i = 0; i < itemCount; i++)
        {
            item.mask = LVIF_PARAM;
            item.iItem = i;
            item.lParam = 0;

            if(ListView_GetItem(m_hwndList, &item))
            {
                dli = (DownloadItem*)item.lParam;

                DownloadItemState state = dli->GetState();

                if(state == kDownloadItemState_Queued ||
                    state == kDownloadItemState_Downloading)
                {
                    totalItems++;
                    totalBytes += dli->GetTotalBytes();
                    doneBytes += dli->GetBytesReceived();
                }
                else if(state == kDownloadItemState_Done)
                {
                    doneItems++;
                    totalItems++;
                    totalBytes += dli->GetTotalBytes();
                    doneBytes += dli->GetTotalBytes();
                }
            }
        }
    }

    m_totalBytes = totalBytes;
    m_doneBytes = doneBytes;
    m_totalItems = totalItems;
    m_doneItems = doneItems;
    InvalidateRect(m_hwndProgress, NULL, FALSE);
}

LRESULT WINAPI 
ListWndProc(HWND hwnd, 
            UINT msg, 
            WPARAM wParam, 
            LPARAM lParam)
{
    DownloadUI* ui = (DownloadUI*)GetProp( hwnd, "ui" );

    //  Pass all non-custom messages to old window proc
	return ui->ListWndProc(hwnd, msg, wParam, lParam);
}

LRESULT DownloadUI::ListWndProc(HWND hwnd, 
                                UINT msg, 
                                WPARAM wParam, 
                                LPARAM lParam)
{
    WNDPROC lpOldProc = (WNDPROC)GetProp( hwnd, "oldproc" );

    switch(msg)
	{
		case WM_ERASEBKGND:
		{
            if (m_duringUpdate)
               return 1;
            break;
		}
    }

    return CallWindowProc(lpOldProc, hwnd, msg, wParam, lParam);
}


LRESULT WINAPI ProgressWndProc(HWND hwnd, 
                               UINT msg, 
                               WPARAM wParam, 
                               LPARAM lParam)
{
    WNDPROC lpOldProc = (WNDPROC)GetProp( hwnd, "oldproc" );

    switch(msg)
	{
		case WM_ERASEBKGND:
		{
            return 1;
		}
    }

    return CallWindowProc(lpOldProc, hwnd, msg, wParam, lParam);
}

LRESULT WINAPI 
FreeTracksWndProc(HWND hwnd, 
                  UINT msg, 
                  WPARAM wParam, 
                  LPARAM lParam)
{
    DownloadUI* ui = (DownloadUI*)GetProp( hwnd, "ui" );

	

    //  Pass all non-custom messages to old window proc
	return ui->FreeTracksWndProc(hwnd, msg, wParam, lParam);
}

LRESULT DownloadUI::FreeTracksWndProc(HWND hwnd, 
                                      UINT msg, 
                                      WPARAM wParam, 
                                      LPARAM lParam)
{
    WNDPROC lpOldProc = (WNDPROC)GetProp( hwnd, "oldproc" );

    switch(msg)
	{
		case WM_DESTROY:   
		{
			//  Put back old window proc and
			SetWindowLong( hwnd, GWL_WNDPROC, (DWORD)lpOldProc );

			// remove window property
			RemoveProp( hwnd, "oldproc" );
            RemoveProp( hwnd, "ui" ); 
			break;
		}

        case WM_SETCURSOR:   
		{
		    if(m_overURL)
            {
                SetCursor(m_handCursor);
                return TRUE;
            }
			break;
		}

        case WM_MOUSEMOVE:
        {
            POINT pt;

		    pt.x = LOWORD(lParam);  // horizontal position of cursor 
            pt.y = HIWORD(lParam);  // vertical position of cursor 

            if(PtInRect(&m_urlRect, pt))
                m_overURL = true;
            else
                m_overURL = false;
			break;
		}

        case WM_LBUTTONDOWN:
        {
            POINT pt;

		    pt.x = LOWORD(lParam);  // horizontal position of cursor 
            pt.y = HIWORD(lParam);  // vertical position of cursor 

            if(PtInRect(&m_urlRect, pt))
            {
                if (strcasecmp(BRANDING_COMPANY, "EMusic") == 0)
                    ShellExecute(hwnd, "open", szEMusicURL, NULL, 
                                 NULL, SW_SHOWNORMAL);
                else
                    ShellExecute(hwnd, "open", szFreeAmpURL, NULL, 
                                 NULL, SW_SHOWNORMAL);
            }
                
			break;
		}
    }

    return CallWindowProc(lpOldProc, hwnd, msg, wParam, lParam);
}

void DownloadUI::ShowHelp(uint32 topic)
{
    string            oHelpFile;
    char              dir[MAX_PATH];
    uint32            len = sizeof(dir);

    m_context->prefs->GetInstallDirectory(dir, &len);
    oHelpFile = string(dir);
    oHelpFile += string("\\"HELP_FILE);    

    WinHelp(m_hwnd, oHelpFile.c_str(), HELP_CONTEXT, topic);
}        

⌨️ 快捷键说明

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