|
I have wondered drawing background on a slider control in MFC
In fact, there are many methods, but i can't write the code efficiently owing to deficient skill.
And then, i saw this article(?) and found your code.
i immediately used your code to new project which is on dialog base in MFC.
i draw(drag & drop) slider control on the dialog and add your code(SliderCtrlEx.cpp, .h) this project.
When i execute it, the slider control is shown normally. but there is one problem.
The center line and the tick marks aren't drawn.
i already saw the question, 'Center Line and Tick Marks'.
however, my problem is different from that question because i applied your code as it is.
m_Slider1.clearCallback();
m_Slider1.clearColors();
m_Slider1.SetRange(0,maxRange,TRUE); // maxRange is 1000 or 2000
m_Slider1.SetTicFreq(ticfreq); // ticfreq is 50 ~ 500
i want to politely ask the answer on my problem.
In case of dialog base in MFC, there is something that should be added or changed.
i call OnChgclrs() in the last of the function 'OnInitDialog()'.
And m_Slider1.Refresh(); in the last of the function OnPaint() as below.
void Cslider_ctrl_exDlg::OnPaint()
{
...
m_Slider1.Refresh();
CDialogEx::OnPaint();
}
the below url is my blog and i posted debugging bitmaps and the full source code of the Dlg class.
http://blog.naver.com/kdepirate/220232619356
The others are same as your project, but my project is the dialog base that not has the view class in SDI or MDI as you know.
i am waiting for your answer or other professionals.
thank you.
modified 7-Jan-15 1:05am.
|
|
|
|
|
There is CSliderCtrlEx control In my project, but when compiled with UNICODE, there are some errors as below:
...\SliderCtrlEx.cpp(37) : error C2664: 'GetProcAddress' : cannot convert parameter 2 from 'unsigned short [13]' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
...\SliderCtrlEx.cpp(647) : error C2664: 'CreateFileW' : cannot convert parameter 1 from 'const char *' to 'const unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe
If there is a Unicode version, it's better!
-- modified at 11:54 Tuesday 5th June, 2007
|
|
|
|
|
I never did the work needed to support UNICODE as I never needed it at the time. Sorry.
|
|
|
|
|
Adding _T("") macro to the strings and LPCSTR to parameters in GetProcAddress() and CreateFileW() will solve the problems. Now it can compiled with UNICODE with no errors.
|
|
|
|
|
chocm wrote: Adding _T("") macro to the strings and LPCSTR to parameters in GetProcAddress() and CreateFileW() will solve the problems. Now it can compiled with UNICODE with no errors
Thanks! In my copious spare time, I will update the article. Much appreciated.
|
|
|
|
|
My project doesn't display center line and tick marks. What should I do to display it? Here's my code:
m_SliderTrack.SetRange(0,1000);<br />
m_SliderTrack.SetTicFreq(1000);<br />
m_SliderTrack.AddColor(0,1000,RGB(255,0,0)); <br />
m_SliderTrack.Refresh();
|
|
|
|
|
With SetTicFreq(1000) you have disabled tick marks. I never tested the code with that situation in mind.
|
|
|
|
|
And what about Center Line?
|
|
|
|
|
Don't know. As I said, I never tested that.
What have your investigations in debugging this revealed?
|
|
|
|
|
Hi! This work ist great!
Is there a way to make a Dll out of this an use it in e.g. VB6
thx Bernhard
|
|
|
|
|
There are some tutorials on DLLs on this site you might want to check out. Given that this is already a library, it shouldn't be too hard.
|
|
|
|
|
I'm subclassing CSliderCtrlEx to implement a custom threshold selector for a motion detection app. I needed something that is a sort of combination of CProgressCtrl and a CSliderCtrl.
The progress control displays the current value of the measured motion, the slider control allows the user to choose the motion threshold.
By using CSliderCtrlEx and changing the background colours I was able to do this quite easily.
Thank you very much for this very neat control!
Cheers,
Maitreya.
|
|
|
|
|
I've added a slider control, created a variable, changed the class to CSliderCntrlEx, etc. The control's appearance remains the standard.
If it helps, the code always seems to hit:
// If we don't have any special coloring to do, skip all the silliness...
if(loopMax <= 0)
{
*pResult = CDRF_DODEFAULT;
}
and then just returns... never progresses any further.
Any ideas?
Jason
|
|
|
|
|
Sorry about the delay in responding; I've been on vacation.
That check is for determining if any colors have been assigned. If no colors have been assigned, there is no need to do anything special. If you want to see it go on, make sure you put in some color ranges. Use the AddColor() methods as demonstrated in the demo program.
int loopMax = colorList.GetSize();
LPNMCUSTOMDRAW lpCustDraw = (LPNMCUSTOMDRAW)pNMHDR;
...
if(lpCustDraw->dwDrawStage == CDDS_PREPAINT)
{
...
if(loopMax <= 0)
{
*pResult = CDRF_DODEFAULT;
}
...
}
|
|
|
|
|
(
nxvnbcvfbnc nvbn vnvb n nvcn vcnvc vc n v -D ;P;)
|
|
|
|
|
|
Hi,
your article gave me a good introduction about writing a custom CSliderCtrl. I wanted to use a derived CSliderCtrl as a a "marker bar" for a linear list of elements, where each element has a specific state and this state is represented with a specific color. The user can then lookup elements with a specific color code (aka state) by moving the thumb box to the element.
For this I wanted the thumb look like a 3D transparent cursor, that has the size of one element (down to a minimum size). But the CSliderCtrl seems to have only have one size for the thumbs. Or is there any way to change that? For the drawing it is no problem, since I can draw whatever I want during the custom draw state. But for the mouse handling this is a problem if I have a large thumb rect that can only be moved from a smaller inner part of the rectangle (the size returned from GetThumbRect).
Do you have any ideas on this?
Thanks
Dirk
|
|
|
|
|
Sorry, I've no good ideas on this. In fact, I've noticed on other custom-drawn sliders that sometimes the thumb is hard to grab. This seems to happen on those with "fancy" looking thumbs.
If you find out something, please following up to this comment with what you learn.
Good luck
|
|
|
|
|
Hi,
it seems that there is a message TBM_SETTHUMBLENGTH where you can control the thumb width, e.g.:
// Must have the TBS_FIXEDLENGTH style
slider.ModifyStyle(0, TBS_FIXEDLENGTH);
int width = ::SendMessage (slider, TBM_GETTHUMBLENGTH, 0, 0);
::SendMessage (slider, TBM_SETTHUMBLENGTH, width*2, 0);
But this seems to size the slider in both directions, not only in the width. The slider control seems to calculate the height of the slider dependant on the width.
I decided for my problem to go with a custom drawn static control, since also the methaphor of the PageUp and PageDown function of the slider does not fit into my problem domain.
Thanks
Dirk
|
|
|
|
|
Greetings,
Another reader wrote me saying that this project did not display the channel (centerline) on his display unless he changed to 256 color depth and then back again!
I have been unable to reproduce the problem which makes it difficult to debug.
His setup was on Window 2000, 1600x1200, 16-bit depth. The screen shots he sent me showed that the tick marks and background colors were OK, but the center line had disappeared. Also, the ticks within the control had "shifted" slightly.
Oddly, rebooting his machine restored the problem (that is, it reversed the correction that going to 8-bit depth then back to 16-bit depth)!
Anybody have any ideas on how to reproduce the problem on my Windows 2000 machine. Anybody else have this problem?
Thanks for your help on this!
-- Harold
|
|
|
|
|
Hello,
ist very easy. Look in at the Colors of the new Controls like CSliderCtrl. In the centerline is an mix from COLOR_BTNSHADOW & COLOR_BTNHIGHLIGHT (I didnt know the correct naming). So in a monochrome Bitmap it is impossible to get the correct centerline. Only in new controls from 2000 and XP.
Ocrana
|
|
|
|
|
Now we can all create Gay-like programs!!
;P
|
|
|
|
|
Hey,
Who are you calling beautiful?
In programming you can do anything (by Paul DiLascia)
|
|
|
|
|