VC通过位图,来实现Slider控件

VC通过位图,来实现Slider控件

1、 增加 "BitmapSlider.h""BitmapSlider.cpp" "memdc.h" 到工程.好像上传不了附件,所以需要这些文件的话,找我吧,哈。

2、  增加"Picture"控件到主对话框中,

3、  增加位图,假如在工程中增加的位图如下:IDB_MP_CHANNELIDB_MP_CHANNEL_ACTIVEIDB_MP_THUMBIDB_MP_THUMB_ACTIVE

4、  改变"Picture"控件ID为:IDC_SLIDER ,在属性中,设置"Type" "Bitmap",在"Image"中选择IDB_MP_CHANNEL(即程序初始化时,以该位图显示);选上"Notify""Tabstop",对于VC6.0,在"Notify""Tabstop"前打勾,对于VS2008,设置"Notify""Tabstop"true

5、  "Picture"控件增加一个变量名:m_Slider,注意变量类型要修改为CBitmapSliderCBitmapSlider m_Slider才是我们想要的。

6、  OnInitDialog(或OnInitUpdate)中:

BOOL CMY_PlayWndDlg::OnInitDialog()

{

//函数的参数,下面会有解释

m_Slider_Seek.SetBitmapChannel( IDB_MP_CHANNEL,IDB_MP_CHANNEL_ACTIVE);

 m_Slider_Seek.SetBitmapThumb( IDB_MP_THUMB, IDB_MP_THUMB_ACTIVE, TRUE );

 

//设置范围

   m_Slider_Seek.SetRange( 0, 100 );

  //初值

 m_Slider_Seek.SetPos( 0 );

m_Slider_Seek.SetMargin(2,3,2,0);

}

 

7、  通过以上的代码,就会看到用自己的位图实现的Slider控件,本来想放图的,可是上传功能暂时关闭,哎

8、 要想不断的变化Slider控件的值,通过定时器就可以实现:SetTimerOnTimer

9、 以播放器为例,当鼠标拖动Slider控件到一个位置时,就相应的去播放。在系统自带的Slider控件中可以响应OnHScroll来实现。而我们自定义的Slider控件就要通过自己写消息处理,步骤如下

10、在头文件中增加 afx_msg LRESULT OnBitmapSliderMoving(WPARAM wParam, LPARAM lParam);

11、在源文件message map中增加 ON_MESSAGE(WM_BITMAPSLIDER_MOVING, OnBitmapSliderMoving)

12、实现OnBitmapSliderMoving函数,即在OnBitmapSliderMoving中增加自己处理的内容。

//自定义Slider控件控件的相关函数

LRESULT CMY_PlayWndDlg::OnBitmapSliderMoving(WPARAM wParam, LPARAM lParam)

{

    //。。。。。。。

     return 0;

}

 

13、附上相关函数参数,英文版的

14、         SetMargin - Sets the margins for a control.

void SetMargin (

    int nLeft,

    int nTop,

    int nRight,

    int nBottom

);

Parameters:

a)     nLeft - Specifies the width of the new left margin, in pixels.

b)     nTop - Specifies the height of the new top margin, in pixels.

c)     nRight - Specifies the width of the new right margin, in pixels.

d)     nBottom - Specifies the height of the new bottom margin, in pixels.

15、         SetBitmapThumb - Load bitmaps for a thumb

BOOL SetBitmapThumb(

    UINT nThumbID,

    UINT nActiveID = NULL,

    BOOL bTransparent = FALSE,

    COLORREF clrpTransColor = 0xFF000000,

    int iTransPixelX = 0,

    int iTransPixelY = 0

);

Parameters

a)     nThumbID - ID of bitmap resource.

b)     nActiveID - ID of bitmap resource.

c)     bTransparent - TRUE to apply transparency effect.

d)     clrpTransColor - RGB color to treat as transparent.

e)     iTransPixelX - Logical x-coordinate of a point. It's color will be treated as transparent.

f)      iTransPixelY - Logical y-coordinate of a point.

Returns: TRUE if function succeeds; otherwise FALSE

  • SetBitmapChannel - Load bitmaps for a channel

BOOL SetBitmapChannel(

    UINT nChannelID,

    UINT nActiveID = NULL,

    BOOL bTransparent = FALSE,

    COLORREF clrpTransColor = 0xFF000000,

    int iTransPixelX = 0,

    int iTransPixelY = 0

);

Parameters

  •  
    • nChannelID - ID number of the bitmap resource of the channel.
    • nActiveID - ID number of the bitmap resource of the active channel.
    • bTransparent - TRUE to apply transparency effect.
    • clrpTransColor - RGB color to treat as transparent.
    • iTransPixelX - Logical x-coordinate of a point. It's color will be treated as transparent.
    • iTransPixelY - Logical y-coordinate of a point.

Returns  TRUE if function succeeds; otherwise FALSE.

16、结束。

你可能感兴趣的:(VC通过位图,来实现Slider控件)