Jump to content
  • Advertisement
Sign in to follow this  

Particle Editor in MFC

This topic is 4136 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, so I'm completely new to MFC and I'm trying to implement a particle editor in an application. My viewing window is in the FormView dialog, and so are all of my sliders to control selected attributes. I have CSliderCtrl's for each of them but I want to set the range and position for them when the application starts up because I already have a default emitter loaded in and rendering. I can't seem to find an event to initialize these values in, can anyone offer any advise, I may be doing this completely wrong also, I'm a total n00b @ MFC. Thanks for your time

Share this post

Link to post
Share on other sites
You have a class whose instance represents window on which those sliders reside. It can be a CDialog or CFormView or whatever. Within resource editor you place a slider or two here and there and add in that class variables of type CSliderCtrl for each of yours sliders. For example, if you decide to house sliders in your CFormView derived class:

class CMyFormView : public CFormView
CSliderCtrl m_slider1;
CSliderCtrl m_slider2;

Next you need to connect those slider instances with onscreen sliders. This is done in DoDataExchange function. So with the above CMyFormView, you would have something like this:

void CMyFormView::DoDataExchange(CDataExchange* pDX)
DDX_Control(pDX, IDC_SLIDER1, m_slider1);
DDX_Control(pDX, IDC_SLIDER2, m_slider2);

My assumption here is that your onscreen sliders have IDs named IDC_SLIDER1 and IDC_SLIDER2.

Now that connection is established, you can set slider default values. The function where this can be done is different for various types of classes which hold those slider instances. For CViewForm derived classes you could use OnInitialUpdate, for CDialog derived classes the usual place is OnInitDialog and so on.

void CMyFormView::OnInitialUpdate()
// these three come from MFC appwizard so just leave them as they are

// do your own initialization

By default, MFC sliders are in the range from 0 to 100 but you can setup whatever range you like. Take a look at MSDN docs for CSliderCtrl.

And then your would be probably interested in reading slider values when user slides them. What I do is to add handlers for slider NM_CUSTOMDRAW message. So, again with the above example, in your CFormView derived class you add functions:

class CMyFormView : public CFormView
void OnSlider1(NMHDR *pNMHDR, LRESULT *pResult);
void OnSlider2(NMHDR *pNMHDR, LRESULT *pResult);

Note that the exact function signature depends on the type of message it handles. These are for slider NM_CUSTOMDRAW, other message types may require different signatures. Use MSDN for further info. Next, you need to connect these handlers with its message:


There... On NM_CUSTOMDRAW coming from IDC_SLIDER1, MFC should invoke your OnSlider1 function. The only thing left is to define those handlers:

void CMyFormView::OnSlider1(NMHDR *pNMHDR, LRESULT *pResult)
// MFC likes to put these but they are not necessary
// TODO: Add your control notification handler code here
*pResult = 0;

// update controls with new values
UpdateData( TRUE );

// current slider value
int pos = m_slider1.GetPos();

// do whatever you want with 'pos'

BTW, most of these things can be done without any typing, with just a few mouse clicks here and there in MSVS resource editor and it does all this setup for you. For some reasons I made a bad habit of typing everything manually (that damn Linux and its "visual" IDEs, see now what they have done to me) so really can't remember the "visual" way of doing it. Sorry.

Oh, and in the future, for any MFC questions you should look at CodeProject website. They have a humongous section devoted to MFC.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!