Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Change focus event

Emkave
Booster

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:

Emkave_0-1732985822992.png

 

or

 

Emkave_1-1732985895811.png

or

 

Emkave_2-1732985924330.png

 

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

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).

View solution in original post

4 REPLIES 4
Miklos Vegh
Graphisoft
Graphisoft

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 ();
};

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.

 

Emkave_0-1735564368120.png

 

Emkave_2-1735564588975.png

 

 

Solution

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).

Thank you for the solution! It really helped!

Setup info provided by author

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!