Hi! Sorry that it took some time for me to reply, but we had a very good party on friday, so I wasn't able to write code till today :)
I just had a look into the matter and wrote some example app. I hope I understood what you want to do correctly... So you have a panel with more than one slider on it. All sliders have attributes like a name and other properties. The class for this special slider is called Light with wxSlider as it's base class. You now want to send the attributes of these sliders to COM1 when the slider is moved.
--- If I got it all wrong, don't read any further :) --- I think you could do it in two ways. The first one would be the easier solution while the second could be a bit harder to implement. Anyway it all depends on what you want. You could actually go without wxCommandEvent::SetClientData() and do it like you started.
#ifndef __LIGHT_H
#define __LIGHT_H
#include <wx/wx.h>
class Light : public wxSlider
{
wxString name;
int someotherparameter;
public:
Light(wxWindow* parent, int id, int val, int min, int max, wxString name, int other);
private:
void OnChange(wxScrollEvent& e);
DECLARE_EVENT_TABLE()
};
#endif
#include "light.h"
BEGIN_EVENT_TABLE(Light, wxSlider)
EVT_SCROLL(Light::OnChange) END_EVENT_TABLE()
Light::Light(wxWindow* parent, int id,int val, int min, int max, wxString name, int other)
:wxSlider(parent, id, val, min, max, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL)
{
this->name = name;
}
void Light::OnChange(wxScrollEvent &event) {
int level = event.GetPosition() + 100;
wxString message;
message << "Name: " << name << ", other things: " << someotherparameter;
message << ", level: " << level;
wxLogMessage(message);
}
In the above code I programmed a Light class like you did and an eventhandler for this class. Now, everytime the slider is moved, a wxScrollEvent is generated and OnChange() is called. OnChange() is the eventhandler for Light. The positive thing is that OnChange() is implemented specifically for this class, so that every instance of Light has it's own handler, not a general one that handles all wxScrollEvent events. So I can simply get the needed attributes of Light by either simply using the like I did (name, someotherparameter) or write set/get methods for that. wxLogMessage is in my case another frame with a wxLogTextCtrl as the log target. Everytime the slider is moved I get all the parameters listed up as a string, e.g. "Name: EX1, other tings: 5, level: 106". You could break there and send the name and stuff to COM1.
The other solution could be to write your own event class. That way you could implement it so that the event itself holds all info you need (like you could call myevent.GetName() or stuff). The advantage would be that you could plug the eventhandler to you main dialog or frame and it would handle all slider events, get the needed stuff and send it to COM1.
I hope I got it right and this helps a little. If you've got further questions reply. I can mail my example to you if you like.
upcaseupCASE ----------------------------------- If it was hard to write, it should be hard to read!- Do. Or do not. There is no try! |