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

📄 npfreeamp.c

📁 freeamp有名的媒体播放器
💻 C
📖 第 1 页 / 共 3 页
字号:
								 * the new window. */
	{
		if( (window == NULL) || ( window->window == NULL ) ) {
			/* There is now no window to use. get rid of the old
			 * one and exit. */
			SetWindowLong( This->fPlatform.fhWnd, GWL_WNDPROC, (LONG)This->fPlatform.fDefaultWindowProc);
			This->fPlatform.fDefaultWindowProc = NULL;
			This->fPlatform.fhWnd = NULL;
			return NPERR_NO_ERROR;
		}

		else if ( This->fPlatform.fhWnd == (HWND) window->window ) {
			/* The new window is the same as the old one. Redraw and get out. */

			InvalidateRect( This->fPlatform.fhWnd, NULL, TRUE );

			UpdateWindow( This->fPlatform.fhWnd );


			return NPERR_NO_ERROR;
		}
		else {
			/* Clean up the old window, so that we can subclass the new
			 * one later. */
			SetWindowLong( This->fPlatform.fhWnd, GWL_WNDPROC, (LONG)This->fPlatform.fDefaultWindowProc);
			This->fPlatform.fDefaultWindowProc = NULL;
			This->fPlatform.fhWnd = NULL;
		}
	}
	else if( (window == NULL) || ( window->window == NULL ) ) {
		/* We can just get out of here if there is no current
		 * window and there is no new window to use. */
		return NPERR_NO_ERROR;
	}

	/* At this point, we will subclass
	 * window->window so that we can begin drawing and
	 * receiving window messages. */
	This->fPlatform.fDefaultWindowProc = (WNDPROC)SetWindowLong( (HWND)window->window, GWL_WNDPROC, (LONG)PluginWindowProc);
	This->fPlatform.fhWnd = (HWND) window->window;
	SetProp( This->fPlatform.fhWnd, gInstanceLookupString, (HANDLE)This);


    hDc = GetDC(This->fPlatform.fhWnd);
    GetTextExtentPoint32(hDc, "j100%", 4, &sSize);
    ReleaseDC(This->fPlatform.fhWnd, hDc);
    GetClientRect(This->fPlatform.fhWnd, &sRect);

    This->fPlatform.sBorder.left = (sRect.right - sRect.left) / 2 - iBoxWidth;
    This->fPlatform.sBorder.right = (sRect.right - sRect.left) / 2 + iBoxWidth;
    This->fPlatform.sBorder.top = (sRect.bottom - sRect.top) / 2 - (sSize.cy * 8);
    This->fPlatform.sBorder.bottom = (sRect.bottom - sRect.top) / 2 + (sSize.cy * 7);

    This->fPlatform.sImportRect.left = This->fPlatform.sBorder.left + 10; 
    This->fPlatform.sImportRect.top = This->fPlatform.sBorder.top + (sSize.cy * 9) + (sSize.cy / 2);
    This->fPlatform.sImportRect.right = This->fPlatform.sImportRect.left +
        ((This->fPlatform.sBorder.right - This->fPlatform.sBorder.left) / 2) - 20;
    This->fPlatform.sImportRect.bottom = This->fPlatform.sImportRect.top + 20;

    This->fPlatform.sDeleteRect.left = 
       (This->fPlatform.sBorder.left + (This->fPlatform.sBorder.right - This->fPlatform.sBorder.left) / 2) + 10,
    This->fPlatform.sDeleteRect.top = This->fPlatform.sImportRect.top;
    This->fPlatform.sDeleteRect.right = This->fPlatform.sBorder.right - 10;
    This->fPlatform.sDeleteRect.bottom = This->fPlatform.sImportRect.bottom;
    
    This->fPlatform.hImportWnd = CreateWindow("BUTTON", "Import into MyMusic", WS_VISIBLE | WS_CHILD | BS_RADIOBUTTON,  
        This->fPlatform.sImportRect.left, This->fPlatform.sImportRect.top,
        This->fPlatform.sImportRect.right - This->fPlatform.sImportRect.left,
        This->fPlatform.sImportRect.bottom - This->fPlatform.sImportRect.top,
        This->fPlatform.fhWnd, (HMENU)iImportButton, (HANDLE)g_hInst, NULL);
    This->fPlatform.hDeleteWnd = CreateWindow("BUTTON", "Delete after playing", WS_VISIBLE | WS_CHILD | BS_RADIOBUTTON, 
        This->fPlatform.sDeleteRect.left, This->fPlatform.sDeleteRect.top,
        This->fPlatform.sDeleteRect.right - This->fPlatform.sDeleteRect.left,
        This->fPlatform.sDeleteRect.bottom - This->fPlatform.sDeleteRect.top,
        This->fPlatform.fhWnd, (HMENU)iDeleteButton, (HANDLE)g_hInst, NULL);

    SendMessage(This->fPlatform.hImportWnd, BM_SETCHECK, 1, 0);
    SendMessage(This->fPlatform.hDeleteWnd, BM_SETCHECK, 0, 0);

    //EnableWindow(This->fPlatform.hDeleteWnd, FALSE);
    //EnableWindow(This->fPlatform.hImportWnd, FALSE);

	InvalidateRect( This->fPlatform.fhWnd, NULL, TRUE );
	UpdateWindow( This->fPlatform.fhWnd );
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++
 * PlatformHandleEvent
 *
 * Handle platform-specific events.
 +++++++++++++++++++++++++++++++++++++++++++++++++*/
int16
PlatformHandleEvent( PluginInstance* This, void* event )
{
	/* Windows Plugins use the Windows event call-back mechanism
	   for events. (See PluginWindowProc) */
	return 0;
}

void Paint(PluginInstance* This, HWND hWnd, HDC hdc)
{
    RECT    sRect, sBorder, sFill;
    HDC     hMemDc;
    SIZE    sSize;
    LOGFONT sFont;
    HFONT   hFont, hSmallFont, hOldFont;
    HBRUSH  hBrush, hOldBrush;
    BITMAP  sInfo;
    char    szPercent[16];

    sBorder = This->fPlatform.sBorder;

    memset(&sFont, 0, sizeof(LOGFONT));
    sFont.lfHeight = 20;
    strcpy(sFont.lfFaceName, "Arial");
    hFont = CreateFontIndirect(&sFont);
    sFont.lfHeight = 12;
    hSmallFont = CreateFontIndirect(&sFont);

    hOldFont = SelectObject(hdc, hFont);
    GetClientRect(hWnd, &sRect);

    // Fill the left side
    sFill.left = 0;
    sFill.top = 0;
    sFill.bottom = sRect.bottom;
    sFill.right = sBorder.left;
    FillRect(hdc, &sFill, GetStockObject(BLACK_BRUSH));

    // Fill the top side
    sFill.left = sBorder.left;
    sFill.top = 0;
    sFill.bottom = sBorder.top;
    sFill.right = sBorder.right;
    FillRect(hdc, &sFill, GetStockObject(BLACK_BRUSH));

    // Fill the right side
    sFill.left = sBorder.right;
    sFill.top = 0;
    sFill.bottom = sRect.bottom;
    sFill.right = sRect.right;
    FillRect(hdc, &sFill, GetStockObject(BLACK_BRUSH));

    // Fill the bottom side
    sFill.left = sBorder.left;
    sFill.top = sBorder.bottom;
    sFill.right = sBorder.right;
    sFill.bottom = sRect.bottom;
    FillRect(hdc, &sFill, GetStockObject(BLACK_BRUSH));

    if (This->fPlatform.sProgressRect.left == -1)
    {
        This->fPlatform.sProgressRect.left = 
           ((sRect.right - sRect.left) / 2) - 100;
        This->fPlatform.sProgressRect.right = 
            This->fPlatform.sProgressRect.left + 200; 
    }

    GetTextExtentPoint32(hdc, "j100%", 4, &sSize);
    sSize.cy -= 3;
    
    sRect.top = (sRect.bottom - sRect.top) / 2 - (sSize.cy * 7);
    sRect.left = sBorder.left;
    sRect.right = sBorder.right;

    DrawText(hdc, szText1, strlen(szText1), &sRect, DT_CENTER);
    sRect.top += sSize.cy * 2;
    
    DrawText(hdc, This->szFileName, strlen(This->szFileName), &sRect, DT_CENTER);
    sRect.top += sSize.cy * 2;
    
    DrawText(hdc, szText2, strlen(szText2), &sRect, DT_CENTER);
    sRect.top += sSize.cy * 2;

    if (This->fPlatform.sProgressRect.top == -1)
    {
        This->fPlatform.sProgressRect.top = sRect.top;
        This->fPlatform.sProgressRect.bottom = sRect.top + 20;
    }

    sRect = This->fPlatform.sProgressRect;
    MoveToEx(hdc, sRect.left, sRect.top, NULL);
    LineTo(hdc, sRect.right, sRect.top);
    LineTo(hdc, sRect.right, sRect.bottom);
    LineTo(hdc, sRect.left, sRect.bottom);
    LineTo(hdc, sRect.left, sRect.top);

    hBrush = CreateSolidBrush(GetSysColor(COLOR_ACTIVECAPTION));

    hOldBrush = SelectObject(hdc, hBrush);
    Rectangle(hdc, sRect.left, sRect.top, 
              sRect.left + (This->iPercentDone * 2) + 1, sRect.bottom + 1);

    sprintf(szPercent, "%d%%   ", This->iPercentDone);
    TextOut(hdc, sRect.right + 5, sRect.top, szPercent, strlen(szPercent));
    
    DeleteObject(hBrush);

    hMemDc = CreateCompatibleDC(hdc);

    GetObject(This->fPlatform.hEmusic, sizeof(BITMAP), &sInfo);
    SelectObject(hMemDc, This->fPlatform.hEmusic);
    BitBlt(hdc, sBorder.right - sInfo.bmWidth, 
                sBorder.bottom - sInfo.bmHeight,
                sInfo.bmWidth, sInfo.bmHeight,
           hMemDc, 0, 0, SRCCOPY);

    if (This->bFreeAmp)
    {
        GetObject(This->fPlatform.hFreeamp, sizeof(BITMAP), &sInfo);
        SelectObject(hMemDc, This->fPlatform.hFreeamp);
        BitBlt(hdc, sBorder.left,
                    sBorder.bottom - sInfo.bmHeight,
                    sInfo.bmWidth, sInfo.bmHeight,
               hMemDc, 0, 0, SRCCOPY);

        sRect.left = sBorder.left + sInfo.bmWidth;
        sRect.top = sBorder.bottom - sInfo.bmHeight;
        sRect.right = sBorder.right - sInfo.bmWidth;
        sRect.bottom = sBorder.bottom;
    }
    else
    {
        sRect.left = sBorder.left;
        sRect.top = sBorder.bottom - sInfo.bmHeight;
        sRect.right = sBorder.right - sInfo.bmWidth;
        sRect.bottom = sBorder.bottom;
    }    

    hBrush = CreateSolidBrush(RGB(153, 153, 153));
    FillRect(hdc, &sRect, hBrush);
    DeleteObject(hBrush);
          
    hBrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
    sRect = This->fPlatform.sBorder;
    sRect.top = This->fPlatform.sImportRect.top - 2;
    sRect.bottom = This->fPlatform.sBorder.bottom - sInfo.bmHeight;
    FillRect(hdc, &sRect, hBrush);
    DeleteObject(hBrush);

    if (This->bFreeAmp)
    {
       SelectObject(hdc, hSmallFont);
       GetTextExtentPoint32(hdc, szSponsor, strlen(szSponsor), &sSize);
       SetBkColor(hdc, GetSysColor(COLOR_3DFACE));
       TextOut(hdc, sBorder.right - (sSize.cx + 2), 
            This->fPlatform.sBorder.bottom - sInfo.bmHeight - (sSize.cy + 2),
            szSponsor, strlen(szSponsor));
    }

    SelectObject(hdc, hOldBrush);
    SelectObject(hdc, hOldFont);      
    DeleteObject(hFont);
    DeleteObject(hSmallFont);
    DeleteDC(hMemDc);
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++
 * PluginWindowProc
 *
 * Handle the Windows window-event loop.
 +++++++++++++++++++++++++++++++++++++++++++++++++*/
LRESULT CALLBACK PluginWindowProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	PluginInstance* This = (PluginInstance*) GetProp(hWnd, gInstanceLookupString);

	switch( Msg ) {
		case WM_PAINT: {
			PAINTSTRUCT paintStruct;
			HDC hdc;

			hdc = BeginPaint( hWnd, &paintStruct );
            Paint(This, hWnd, hdc);
			EndPaint( hWnd, &paintStruct );
			break;
		}
        case WM_SIZE: {
            RECT sRect;
            HDC  hDc;
            SIZE sSize;
            
            hDc = GetDC(This->fPlatform.fhWnd);
            GetTextExtentPoint32(hDc, "j100%", 4, &sSize);
            ReleaseDC(This->fPlatform.fhWnd, hDc);
            GetClientRect(hWnd, &sRect);
            
            This->fPlatform.sProgressRect.top = -1;
            This->fPlatform.sProgressRect.left = -1;
            
            This->fPlatform.sBorder.left = (sRect.right - sRect.left) / 2 - iBoxWidth;
            This->fPlatform.sBorder.right = (sRect.right - sRect.left) / 2 + iBoxWidth;
            This->fPlatform.sBorder.top = (sRect.bottom - sRect.top) / 2 - (sSize.cy * 8);
            This->fPlatform.sBorder.bottom = (sRect.bottom - sRect.top) / 2 + (sSize.cy * 7);
        
            This->fPlatform.sImportRect.left = This->fPlatform.sBorder.left + 10; 
            This->fPlatform.sImportRect.top = This->fPlatform.sBorder.top + (sSize.cy * 9) + (sSize.cy / 2);
            This->fPlatform.sImportRect.right = This->fPlatform.sImportRect.left +
                ((This->fPlatform.sBorder.right - This->fPlatform.sBorder.left) / 2) - 20;
            This->fPlatform.sImportRect.bottom = This->fPlatform.sImportRect.top + 20;
        
            This->fPlatform.sDeleteRect.left = 
               (This->fPlatform.sBorder.left + (This->fPlatform.sBorder.right - This->fPlatform.sBorder.left) / 2) + 10,
            This->fPlatform.sDeleteRect.top = This->fPlatform.sImportRect.top;
            This->fPlatform.sDeleteRect.right = This->fPlatform.sBorder.right - 10;
            This->fPlatform.sDeleteRect.bottom = This->fPlatform.sImportRect.bottom;
            
            SetWindowPos(This->fPlatform.hImportWnd, NULL, 
                This->fPlatform.sImportRect.left,
                This->fPlatform.sImportRect.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
            SetWindowPos(This->fPlatform.hDeleteWnd, NULL, 
                This->fPlatform.sDeleteRect.left,
                This->fPlatform.sDeleteRect.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
        }
        case WM_COMMAND:
        {
            if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == iImportButton)
            {
               SendMessage(This->fPlatform.hImportWnd, BM_SETCHECK, 1, 0);
               SendMessage(This->fPlatform.hDeleteWnd, BM_SETCHECK, 0, 0);
            }   
            if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == iDeleteButton)
            {
               SendMessage(This->fPlatform.hImportWnd, BM_SETCHECK, 0, 0);
               SendMessage(This->fPlatform.hDeleteWnd, BM_SETCHECK, 1, 0);
            }   
        
        }
		default: {
			This->fPlatform.fDefaultWindowProc( hWnd, Msg, wParam, lParam);
		}
	}
	return 0;
}

⌨️ 快捷键说明

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