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

📄 droptarget.cpp

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

        HDC hdc = GetDC(m_hwnd);

        HBRUSH oldBrush = (HBRUSH)SelectObject(hdc, m_insertBrush);

        // draw new
        PatBlt(hdc,
               itemRect.left, 
               itemRect.top, 
               itemRect.right - itemRect.left, 
               itemRect.bottom - itemRect.top, 
               PATINVERT);

        SelectObject(hdc, oldBrush);

        ReleaseDC(m_hwnd, hdc);

        m_insertRect = itemRect;
    }
   
	return NOERROR;
}

STDMETHODIMP DropTarget::DragOver(DWORD dwKeyState, 
                                  POINTL pt, 
                                  LPDWORD pdwEffect) 
{
    //OutputDebugString("Drag Over\r\n");

    if(m_acceptFormat && m_enabled) 
    {
        *pdwEffect = DROPEFFECT_COPY; 

        if(m_allowMove && !m_targetIsSource)
        {
            if(dwKeyState & MK_CONTROL)
                *pdwEffect = DROPEFFECT_COPY; 
            else
                *pdwEffect = DROPEFFECT_MOVE; 
        }
    }
	else 
        *pdwEffect = DROPEFFECT_NONE; 

    
    if(m_acceptFormat && m_enabled)
    {
        // draw a line to indicate insertion point in list
        LV_HITTESTINFO hti;
        RECT itemRect;

        hti.pt.x = pt.x;
        hti.pt.y = pt.y;

        MapWindowPoints(NULL, m_hwnd, (LPPOINT)&hti.pt, 1);

        m_oldItem = ListView_HitTest(m_hwnd, &hti);

		bool checkScroll = true;
        if (m_oldItem == 0)
			checkScroll = false;

        if(m_oldItem < 0)
        {
            itemRect = m_insertRect;
        }
        else
        {   
            int middle;

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

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

            if(hti.pt.y < middle)
            {
                if(m_oldItem == 0)
                {
                    itemRect.bottom = itemRect.top + 2;
					checkScroll = true;
                }
                else
                {
                    itemRect.bottom = itemRect.top;
                    itemRect.top -= 2;
                }
                //OutputDebugString("top\r\n");
            }
            else
            {
                itemRect.top = itemRect.bottom - 2;
                //itemRect.bottom;
                //OutputDebugString("bottom\r\n");
            }
        }

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

        //sprintf(buf, "%d, %d, %d, %d\r\n", 
        //    itemRect.top, itemRect.left, itemRect.bottom, itemRect.right);
        //OutputDebugString(buf);

		bool scrolling = m_scrolling;

        if(!m_scrolling)
        {
            ImageList_DragShowNolock(FALSE);
       
            HDC hdc = GetDC(m_hwnd);

            HBRUSH oldBrush = (HBRUSH)SelectObject(hdc, m_insertBrush);

            //OutputDebugString("erase old - drag over\r\n");
            // erase old
            PatBlt(hdc,
                   m_insertRect.left, 
                   m_insertRect.top, 
                   m_insertRect.right - m_insertRect.left, 
                   m_insertRect.bottom - m_insertRect.top, 
                   PATINVERT);

            //OutputDebugString("draw new - drag over\r\n");

            // draw new
            PatBlt(hdc,
                   itemRect.left, 
                   itemRect.top, 
                   itemRect.right - itemRect.left, 
                   itemRect.bottom - itemRect.top, 
                   PATINVERT);

            SelectObject(hdc, oldBrush);

            ReleaseDC(m_hwnd, hdc);

            m_insertRect = itemRect;

            ImageList_DragShowNolock(TRUE);
        }

		if (checkScroll)
            CheckAutoScroll(hti.pt); 
    }

	return NOERROR;
}


STDMETHODIMP DropTarget::DragLeave() 
{   
    if(m_acceptFormat)
    {
        AutoScroll(SCROLL_OFF);

        ImageList_DragShowNolock(FALSE);

        HDC hdc = GetDC(m_hwnd);

        HBRUSH oldBrush = (HBRUSH)SelectObject(hdc, m_insertBrush);

        // erase old
        PatBlt(hdc,
               m_insertRect.left, 
               m_insertRect.top, 
               m_insertRect.right - m_insertRect.left, 
               m_insertRect.bottom - m_insertRect.top, 
               PATINVERT);

        // erase old
        SelectObject(hdc, oldBrush);

        ReleaseDC(m_hwnd, hdc);

        ImageList_DragShowNolock(TRUE);
    }

    m_acceptFormat = false;
    m_allowMove = false;

    return NOERROR;
}

STDMETHODIMP DropTarget::Drop(LPDATAOBJECT pDataObj,
                              DWORD dwKeyState, 
                              POINTL pt, 
                              LPDWORD pdwEffect) 
{   
    FORMATETC fmtetc;   
    STGMEDIUM medium;   
    HGLOBAL hGlobal;
    HRESULT hr;
 
    *pdwEffect = DROPEFFECT_NONE;
    hr = NOERROR;

    AutoScroll(SCROLL_OFF);

    if(m_acceptFormat && m_enabled) 
    {   
        if(m_oldItem > 0)
            m_oldItem--;

        //ListView_RedrawItems(m_hwnd, m_oldItem, m_oldItem + 1);
        ImageList_DragShowNolock(FALSE);

        HDC hdc = GetDC(m_hwnd);

        HBRUSH oldBrush = (HBRUSH)SelectObject(hdc, m_insertBrush);

        // erase old
        PatBlt(hdc,
               m_insertRect.left, 
               m_insertRect.top, 
               m_insertRect.right - m_insertRect.left, 
               m_insertRect.bottom - m_insertRect.top, 
               PATINVERT);

        // erase old
        SelectObject(hdc, oldBrush);

        ReleaseDC(m_hwnd, hdc);

        AutoScroll(SCROLL_OFF);

        ImageList_DragShowNolock(TRUE);

        // User has dropped on us. First, try getting data in the 
        // private FreeAmp format

        fmtetc.cfFormat = RegisterClipboardFormat(CFSTR_FREEAMP_CATALOGITEM);
        fmtetc.ptd = NULL;
        fmtetc.dwAspect = DVASPECT_CONTENT;  
        fmtetc.lindex = -1;
        fmtetc.tymed = TYMED_HGLOBAL;       
        
        hr = pDataObj->GetData(&fmtetc, &medium);
        if(!FAILED(hr)) 
        {
            // Import the data and release it.
            hGlobal = medium.hGlobal;

            // need to update the point so we know 
            // where it was droppped in the window
            DROPFILES* df = (DROPFILES*)GlobalLock(hGlobal);
            df->pt.x = pt.x;
            df->pt.y = pt.y;

            MapWindowPoints(NULL, m_hwnd, (LPPOINT)&df->pt, 1);

            GlobalUnlock(hGlobal);

            // our format is the same as the DROPFILES format
            // except we pass URLs not paths... 
            SendMessage(m_hwnd, UWM_DROPURLS, (WPARAM)hGlobal, 0);
           
            ReleaseStgMedium(&medium);
            *pdwEffect = DROPEFFECT_COPY;

            return NOERROR;
        }

        fmtetc.cfFormat = RegisterClipboardFormat(CFSTR_FREEAMP_PLAYLISTITEM);
        fmtetc.ptd = NULL;
        fmtetc.dwAspect = DVASPECT_CONTENT;  
        fmtetc.lindex = -1;
        fmtetc.tymed = TYMED_HGLOBAL;       
        
        hr = pDataObj->GetData(&fmtetc, &medium);
        if(!FAILED(hr)) 
        {
            // if target is source we simply do an internal move
            if(m_targetIsSource)
            {
                *pdwEffect = DROPEFFECT_NONE;

                MapWindowPoints(NULL, m_hwnd, (LPPOINT)&pt, 1);
                
                SendMessage(m_hwnd, UWM_MOVEITEMS, 0, (LPARAM)&pt);
            }
            else // we export the items to the target
            {
                // Import the data and release it.
                hGlobal = medium.hGlobal;

                // need to update the point so we know 
                // where it was droppped in the window
                DROPFILES* df = (DROPFILES*)GlobalLock(hGlobal);
                df->pt.x = pt.x;
                df->pt.y = pt.y;

                MapWindowPoints(NULL, m_hwnd, (LPPOINT)&df->pt, 1);

                GlobalUnlock(hGlobal);

                // our format is the same as the DROPFILES format
                // except we pass URLs not paths... 
                SendMessage(m_hwnd, UWM_DROPURLS, (WPARAM)hGlobal, 0);

                if(dwKeyState & MK_CONTROL)
                    *pdwEffect = DROPEFFECT_COPY;
                else
                    *pdwEffect = DROPEFFECT_MOVE;
            }

            ReleaseStgMedium(&medium);

            return NOERROR;
        }
        
        // if not our format, try getting CF_HDROP data from drag source
        fmtetc.cfFormat = CF_HDROP;
        fmtetc.ptd = NULL;
        fmtetc.dwAspect = DVASPECT_CONTENT;  
        fmtetc.lindex = -1;
        fmtetc.tymed = TYMED_HGLOBAL;       
    
        hr = pDataObj->GetData(&fmtetc, &medium);

        if(!FAILED(hr)) 
        {
            // Import the data and release it.
            hGlobal = medium.hGlobal;

            // need to update the point so we know 
            // where it was droppped in the window
            DROPFILES* df = (DROPFILES*)GlobalLock(hGlobal);
            df->pt.x = pt.x;
            df->pt.y = pt.y;

            MapWindowPoints(NULL, m_hwnd, (LPPOINT)&df->pt, 1);

            GlobalUnlock(hGlobal);

            SendMessage(m_hwnd, WM_DROPFILES, (WPARAM)hGlobal, 0);

            ReleaseStgMedium(&medium);
            *pdwEffect = DROPEFFECT_COPY;

            return NOERROR;
        }
    }

	return hr;      
}

⌨️ 快捷键说明

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