   Reacting to Input in MFC
  Hi there!I'm just getting started with MFC and having a little trouble :-)After I had created a dialog, I added a slider-control in the VisualStudio GUI editor. Now I want to add some code that should be executed, whenever the the slider is moved...somekind of a "OnChange" method.But when I double-click the slider, VS creates this method for me:void DlgView::OnNMCustomdrawZoom(NMHDR *pNMHDR, LRESULT *pResult){LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);// TODO: Add your control notification handler code here*pResult = 0;}and that seems to be absolutely useless... :-(How can I get this working?And is there a way to access the slider's value? I mean I have no variable or something, just the stupid control on my dialog. How can I access that?Thanks for your help!(BTW: I found no good tuts on that, so I hope you won't punish me for posting here?) ;-)Thanks!!!!   
  You should first tell us what version of Visual Studio you are using.  It is different in different versions but I will try and help you though.  To get the value of the slider you need to attach a variable to it.  Depending on which version of VC++ u are using.  if you are using 6.0 you would just to go class wizard and do it that way.  If you are using VS.net 2002 (im not sure if its the same as 2003 or 2005) then you just right click the control and click add variable.  Then you would set the range of the Trackbar with SetRange(int nMin, nMax, bRedraw=FALSE)  Then you can get the position of the slider with GetPos()Just use the classwizard in 6.0 to get to the notifications.  I believe it is TB_THUMBTRACK and TB_THUMBPOSITION for the mouse.  But I haven't figured out how to do this in VS.net 2002 since I am just getting started learning it.  Does anyone know how to add these events in 2003 or do you need to code it yourself.  Thanks.Jack   ;  highly recommendread in this orderIntroduction to MFC Programming with Visual C++ by Richard M. JonesProgramming Windows With MFC by Jeff ProsiseKuphryn   ;  These seem to be quite expensive books (173€??? WTF!!!!)... And all I need is an answer to my question, I don't want to dig deeper into MFC than this ;-)"You should first tell us what version of Visual Studio you are using"VS2005 that is :-)"To get the value of the slider you need to attach a variable to it."Allright, that was quite easy!"Then you would set the range of the Trackbar with SetRange"How can I do this? There's no object providing this method :-(The slider seems not to be represented in the code - it's just a graphic in the GUI editor..."Just use the classwizard in 6.0 to get to the notifications."There's a "Event-handler-wizard" when I right-click the slider. But it only offers meNM_OUTOFMEMORY, NM_RELEASEDCAPTURE and NM_THEMCHANGED. And that doesn't sound too good...Thanks for your help so far! Any more ideas?   ;  Accessing the slider's value / setting appropriate parameters is pretty easy. If you have a control you've placed in the dialog editor, there are two ways you can do this. One is to use the GetDlgItem() function to get a pointer to the CSliderCtrl object. Like this:CSliderCtrl* pSlider = (CSliderCtrl*)GetDlgItem(ID_OF_YOUR_SLIDER);pSlider->SetRange(0,100);The other way is to add a variable for this control with the CSliderCtrl type. Just right-click the control in the GUI editor, select "Add Variable", and then make sure the "control variable" box is checked in the "Add Member Variable Wizard." Then you can use this variable directly to access the control.Now, as for your other question, about reacting to changes in the slider... that one's a bit harder. MFC isn't very helpful here; only four notification messages are provided for slider controls, and none of them do what you want. If you really need to react every time the slider's position changes, you might have to consider deriving a class from CSliderCtrl and adding the behavior yourself.I'm not too sure of the internal workings of the CSliderCtrl class - you could probably do it by handling mousedown / mousemove messages (and maybe keypresses as well), but there might be an easier way (perhaps known by someone with more MFC experience than me). This is one of the shortcomings of MFC; as a thin layer over the Win32 API, it inherits a lot of the annoying problems thereof. Oftentimes an MFC class is functionality-sparse because all it's doing is wrapping a really old-fashioned Win32 window class directly.If I may ask, though, why are you using MFC with Visual Studio 2005? I've used MFC since Visual Studio 6, but recently I decided to give .NET Windows Forms a try and I'm never going back. That's not to say I don't like MFC. After going through years of pain and trials with an API, you kinda get attached to it, you know? ;-) But for me, it was time to move on. MFC is good enough for a lot of things, but to really get up-to-date functionality (and much easier use!) Windows Forms is IMHO a better way to go.[Edited by - MrAccident on June 21, 2006 11:51:54 PM];  Hey, thanks for your reply! That's going to help a lot :-)The reason I'm using MFC ist that.....ummm....öhhhh.... ^^The whole thing just has to be very simple (I don't want to invest much time in coding around with the GUI),I want to use my own C++ code without problems (when I create a .NET app there's always this strange code I don't understand (is it called managed C++???),and I want to be able to use OpenGL without problems....The point is that this is supposed to be a simple editor, so it can be as messed up as it wants ;-)Maybe I'll use a scroll bar instead of the slider? I'll have a look into this...   ;  By the way: would it be possible to create a "windows forms application" (that's .NET, right?) and simply render to a window's background via OpenGL?Maybe that would be better than MFC (which is making me more and more angry every minute) ;-)   ;  Moved sliders don't send any kind of "change" message. However, they send a WM_HSCROLL or WM_VSCROLL message when they are "moved", just like a standard scroll bar.HTH,   ;Quote:Original post by Emmanuel DelogetMoved sliders don't send any kind of "change" message. However, they send a WM_HSCROLL or WM_VSCROLL message when they are "moved", just like a standard scroll bar.*smacks forehead*I knew there was something I was forgetting. It's this sort of thing that makes MFC so lovably annoying.As for you other question, yes, it should be possible. You can obtain the window handle of a Windows Forms window just as easily as you can with a CWnd. However, if that's all you're doing with this project, MFC should do just fine, despite its quirks. :-)   ;  Allright, then here's my next noobish question:Where would I catch those "WM_HSCROLL"-style messages? I can't see a method for this in the pre generated code - do I have to write it my own? In which class should I put it? And how should it look like?Or is there a wizzard to create this function?Thanks ao much (once again) ;-)   