MFC音乐播放器


一、继承CButton 实现按钮自绘

1.ON_WM_SETCURSOR() 改变指针

BOOL C2PicBtn::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{

::SetCursor(LoadCursor(NULL, IDC_HAND));

return true;//CButton::OnSetCursor(pWnd, nHitTest, message);
}

2.绘制bitmap指定颜色透明

TransparentBlt(dc->GetSafeHdc(),   //目标dc

        0,    //x

        0,    //y

rect.Width()*0.8,    //宽度

rect.Height()*0.8,    //高度

memDC.GetSafeHdc(),  //源dc

0, 0, bitStruct.bmWidth, bitStruct.bmHeight,  //与目标dc 参数类型相同

RGB(255, 0, 255)    //目标颜色

);

3.重绘通过虚函数DrawItem 不是消息  另外按钮owner draw 设为true接受自绘

 

4.向父窗口发送消息

消息类型 BN_CLICKED  WM_COMMAND的一种 绑定方法ON_BN_CLICKED(id,pfn)

void CMyCtr::PostClickEvent()
{
CWnd* parent = GetParent();
if (parent != NULL)
{
WPARAM wp = MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED);
LPARAM lp = (LPARAM)m_hWnd;
parent->PostMessage(WM_COMMAND, wp, lp);
}
}

 

parent->SendMessage(WM_USER_ITEMDBCLCK, wp,lp);  绑定方式 ON_MESSAGE(WM_USER_ITEMDBCLCK, OnItemBDCLCK)

 

自定义消息类型

#define WM_USER_ITEMDBCLCK WM_USER+1

 

create窗口带滚动条

dwStyle = dwStyle|WS_VSCROLL | WS_CHILD | WS_VISIBLE;

滚动条响应函数

void MyMusicList::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值

CRect rect;
GetClientRect(&rect);
int minpos = 0, maxpos = 0;
maxpos = curBottom - rect.Height();
if (maxpos < 0)maxpos = 1;
SetScrollRange(SB_VERT, minpos, maxpos);
int curpos = 0;
curpos = GetScrollPos(SB_VERT);
switch (nSBCode)
{
case SB_TOP:curpos = minpos; break;
case SB_BOTTOM: curpos = maxpos; break;
case SB_ENDSCROLL:break;
case SB_LINEUP:if (curpos>minpos)curpos-=5; break;
case SB_LINEDOWN:if (curpos < maxpos)curpos+=5; break;
case SB_THUMBPOSITION:curpos = nPos; break;
case SB_THUMBTRACK:curpos = nPos; break;
case SB_PAGEDOWN:
{
SCROLLINFO info;
GetScrollInfo(SB_VERT, &info, SIF_ALL);
if (curpos < maxpos)
curpos = min(maxpos, curpos + (int)info.nPage);

}break;
case SB_PAGEUP:
{
SCROLLINFO info;
GetScrollInfo(SB_VERT, &info, SIF_ALL);
if (curpos > minpos)
curpos = max(minpos, curpos - (int)info.nPage);

}break;
}
if (curpos > maxpos || curpos < minpos)curpos = 0;
SetScrollPos(SB_VERT, curpos);
ScrollWindow(0, curTop-curpos);
curTop = curpos;
UpdateWindow();
// CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
}

 

滚轮滚动控制滚动条

BOOL MyMusicList::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{

if (zDelta < 0)
{
OnVScroll(SB_LINEDOWN, GetScrollPos(SB_VERT), GetScrollBarCtrl(SB_VERT));
}
else if (zDelta > 0)
{
OnVScroll(SB_LINEUP, GetScrollPos(SB_VERT), GetScrollBarCtrl(SB_VERT));
}
return CWnd::OnMouseWheel(nFlags, zDelta, pt);
}

 

智能推荐

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告