2024-11-30 06:04 PM - last edited a month ago by Laszlo Nagy
Hello. I am trying to implement one algorithm but for that I need somehow to detect that you have opened a certain window in Archicad that changes the focus of the application to that window, for ex. a modal dialogue or windows such as those:
or
or
I guess you got it. Do you know any Archicad API command that could help detecting such focus changes? I have been searching for that command, however, I am either blind or the command does not exist. Thank you in advance!
Operating system used: Windows 11
Solved! Go to Solution.
yesterday - last edited yesterday
You should implement a new class having the DG::ApplicationObserver as a base, this way inheriting the virtual notification functions which will be overridden. Then you attach the instance of your class to the DG::Application (which is a DG::EventSource). When the events emerge, DG::Application (the EventSource) will call the overridden virtual functions in your attached observer class. You can try something like this:
class AppObserver: public DG::ApplicationObserver
{
private:
bool isInModalState = false;
public:
AppObserver ();
~AppObserver ();
bool IsInModalState () const;
protected:
virtual void ModalStateBegin (void) override;
virtual void ModalStateEnd (void) override;
};
AppObserver::AppObserver ()
{
DG::Application::GetInstance ()->Attach (*this);
}
AppObserver::~AppObserver ()
{
DG::Application::GetInstance ()->Detach (*this);
}
bool IsInModalState () const
{
return isInModalState;
}
void AppObserver::ModalStateBegin (void)
{
isInModalState = true;
}
void AppObserver::ModalStateEnd (void)
{
isInModalState = false;
}
(I did not try to compile these lines).
4 weeks ago
Hi, there is a function in the DG.h header file:
DG_DLL_EXPORT bool CCALL DGIsInModalState (void);
This can be used to decide whether a modal dialog is open or not.
And if you attach to the DG::ApplicationObserver, you will be notified about modal state change.
class DG_DLL_EXPORT ApplicationObserver: public GS::EventObserver
{
...
virtual void ModalStateBegin (void);
virtual void ModalStateEnd (void);
...
public:
ApplicationObserver ();
virtual ~ApplicationObserver ();
};
Monday - last edited Tuesday by Laszlo Nagy
Hi. Thank you for the help. I suppose those functions should be overridden and are invoked by Archicad itself, right? Shouldn't I somehow attach it to Archicad or? I just added the solution to the code, and put a breakpoint to debug, but nothing happened. None of those functions were invoked by Archicad or anything else. In the screenshots you will see some of my attempts to invoke the functions by overriding or defining them, however nothing happened.
yesterday - last edited yesterday
You should implement a new class having the DG::ApplicationObserver as a base, this way inheriting the virtual notification functions which will be overridden. Then you attach the instance of your class to the DG::Application (which is a DG::EventSource). When the events emerge, DG::Application (the EventSource) will call the overridden virtual functions in your attached observer class. You can try something like this:
class AppObserver: public DG::ApplicationObserver
{
private:
bool isInModalState = false;
public:
AppObserver ();
~AppObserver ();
bool IsInModalState () const;
protected:
virtual void ModalStateBegin (void) override;
virtual void ModalStateEnd (void) override;
};
AppObserver::AppObserver ()
{
DG::Application::GetInstance ()->Attach (*this);
}
AppObserver::~AppObserver ()
{
DG::Application::GetInstance ()->Detach (*this);
}
bool IsInModalState () const
{
return isInModalState;
}
void AppObserver::ModalStateBegin (void)
{
isInModalState = true;
}
void AppObserver::ModalStateEnd (void)
{
isInModalState = false;
}
(I did not try to compile these lines).
yesterday
Thank you for the solution! It really helped!