Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: How to get the instance of a UIElement? (Read 1292 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How to get the instance of a UIElement?

I'm about to use an ugly hack unless anybody can help me with the following:

- My component exposes a uielement derived from ui_element_instance XYZ and a service ABC derived from service_base.

class XYZ : public ui_element_instance, public CWindowImpl<XYZ>{ }

class XYZUIElement : public ui_element_impl_withpopup<XYZ> { }
 
class NOVTABLE ABC : public service_base
{
    void SomeMethod() { XYZ.DoSomething() }
}


I can instantiate both just find but how do I get a reference to XYZ from ABC at runtime?
I'd like ABC to call methods of XYZ.

Re: How to get the instance of a UIElement?

Reply #1
You need some sort of scheme to keep track of the instances of your class. Unless there's something built-in to fb2k to keep track of instances you need to roll something yourself, like having it self-register on a common list when being created and de-register when it's destroyed.

In general there's no singular object unless you somehow artificially constrain your UI element to be unique. The registration process would be similar, except it'd manipulate central storage for a single object pointer.

In any way, ABC could then consult that list and interact naturally with those instances.
Stay sane, exile.

Re: How to get the instance of a UIElement?

Reply #2
I was recently poking around the source for the built in equalizer....

https://www.foobar2000.org/equalizer

and noticed it used pfc::instanceTracker from pfc\other.h. It looks like you use it like this...

Code: [Select]
class _Notify
{
public:
    virtual void do_something() = 0;
};

using Notify = pfc::instanceTracker<_Notify>;

class XYZ : public Notify, public ui_element_instance, public CWindowImpl<XYZ>
{
public:
    void do_something() override
    {
    }
 };
Then from inside ABC or whatever...

Code: [Select]
		for(pfc::const_iterator<Notify*> walk = Notify::instanceList().first(); walk.is_valid(); ++walk) {
(*walk)->do_something();
}

You might be to use the new range based for support in the latest SDKs - not tested.


Re: How to get the instance of a UIElement?

Reply #3
I was recently poking around the source for the built in equalizer....

https://www.foobar2000.org/equalizer

and noticed it used pfc::instanceTracker from pfc\other.h. It looks like you use it like this...
...
You might be to use the new range based for support in the latest SDKs - not tested.

Thx. I'll have a look at it.