Clicky

Hi,

I am taking over a project that consist of an ActiveX controls library. So controls are created dynamically by using this library.
The first problem I am facing is that this library provides sliders as well and at the moment there are only standard MFC sliders implemented that don't take into account the property settings (background color, thumb color) of the control.
Since I am quite new to ATL/MFC I don't really know achive this custom drawing with ATL.

I hope I've provided enough info to help me solve this problem, otherwise feel free to ask for details.
Thanks a lot
Greg

So here is the code of how the slider is created on the OnCreate message.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
LRESULT CCybSlider::OnCreate( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
{
	// Set the default style for the tab control
	DWORD dwStyle = WS_VISIBLE | WS_TABSTOP | WS_CHILD | TBS_AUTOTICKS;
	// Vertical
	if ( m_bVertical )
	{
		dwStyle |= TBS_VERT;
		// Horizontal alignement
		switch ( m_horizAlign )
		{
		case chaLeft:
			dwStyle |= TBS_LEFT;
			break;
		case chaCenter:
			dwStyle |= TBS_BOTH;
			break;
		case chaRight:
			dwStyle |= TBS_RIGHT;
			break;
		}
	}
	else
	{
		dwStyle |= TBS_HORZ;
		// Vertical alignement
		switch ( m_vertAlign )
		{
		case cvaTop:
			dwStyle |= TBS_TOP;
			break;
		case cvaCenter:
			dwStyle |= TBS_BOTH;
			break;
		case cvaBottom:
			dwStyle |= TBS_BOTTOM;
			break;
		}
	}
	// Ticks
	if ( ! m_bTicks )
		dwStyle |= TBS_NOTICKS;

	// Create the slider control with the correct style
	RECT rc;
	GetWindowRect(&rc);
        //m_Slider is a CContainedWindow member variable
	m_Slider.Create(m_hWnd, rc, NULL, dwStyle, 0, CYB_SLIDER_CTRL_ID);

	// Attach the window to an MFC CSliderCtrl for easy function call
        //m_SliderCtrl is a simple CSliderCtrl member variable
	m_SliderCtrl.Attach(m_Slider.m_hWnd);

	m_bInit = true;
	ApplyLineIncrementChange();
	ApplyPageIncrementChange();
	ApplyMinValueChange();
	ApplyMaxValueChange();
	ApplyTickFrequencyChange();
	m_bInit = false;
	ApplyValueChange(m_nValue);
	
	

	return CYB_SLIDER_PARENT::OnCreate( uMsg, wParam, lParam, bHandled );
}

asked 12/14/2010 06:33

Greg767's gravatar image

Greg767 ♦♦


8 Answers:
Have a look at this? This one shows how to subclass button but see how to subclass slidebar.

http://msdn.microsoft.com/en-us/library/3ka2f8c6%28v=VS.80%29.aspx


http://www.functionx.com/visualc/classes/slider1.htm
link
DeepuAbrahamK's gravatar image

DeepuAbrahamK

Greg767,

I changed the zones for this question from

--Windows ATL / WTL / COM Programming
--Windows MFC Programming
--ActiveX

to
--Windows ATL / WTL / COM Programming
--Windows MFC Programming
--ActiveX
--Miscellaneous Programming


Vee_Mod
Community Support Moderator
link
Vee_Mod's gravatar image

Vee_Mod

Greg767,

A message has been sent to some additional experts asking them to review your question. We will check back again to see if you are getting the help you need.

This request included Experts from Windows ATL / WTL / COM Programming, Miscellaneous Programming, Windows MFC Programming, ActiveX.

Please do not respond to this comment; we will be monitoring your question for activity from the Experts.

Thank you for using Experts Exchange,

Vee_Mod
Community Support Moderator
http://www.qa.downappz.com/Q_26682268.html
link
Vee_Mod's gravatar image

Vee_Mod

@DeepuAbrahamK: Thanks for the links. I am going to look into how to subclass a slider, but I am not sure if that will lead me towards custom drawing it.

AFAIK, to be able to custom draw a slider I need to intercept NM_CUSTOMDRAW message and redraw it accoding to its drawing phases. There are enough tutorials on this for MFC, but I haven't found anything for ATL. Do you have more info on this?

Thanks
Greg
link
Greg767's gravatar image

Greg767

OK, I am getting close.
I chose the ActiveX control route, where I can intercept the NM_CUSTOMDRAW message. Now I can draw the thumb, but when doing this:
1:
pDC->FillSolidRect(0, 0, rClient.Width(), rClient.Height(), RGB(145, 176, 191));

It draws on top of the channel and tics, so they not show anymore.

So how do I draw a colored background and preserve channel and tics?

Thanks a lot
Greg
link
Greg767's gravatar image

Greg767

Ohh geez I thought I was deleting only the last comment.
link
Greg767's gravatar image

Greg767

No code snippets were provided, only links to external websites.
link
Greg767's gravatar image

Greg767

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×1
×36
×6

Asked: 12/14/2010 06:33

Seen: 643 times

Last updated: 12/16/2010 02:47