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

How to make the basic modal dialog using resource?

Soonbum Jeong
Newcomer
Dear developers,

I saw the DG_Test.
But I didn't understand the codes.
I wish to know how to make the basic modal dialog using resource.

Following is my code. This is incomplete code.

...

static short DGCALLBACK place_Euroform_Handler (short			message,
												short			dialogID,
												short			item,
												DGUserData		userData,
												DGMessageData	msgData)
{
	return 0;
}		// Callback function for DG

...

GSErrCode __ACENV_CALL	CommandHandler (const API_MenuParams *menuParams)
{
	GSErrCode	err = NoError;
	bool		isOK;
	DGUserData	userData;

	isOK = DGModalDialog (ACAPI_GetOwnResModule (), 32510, ACAPI_GetOwnResModule (), place_Euroform_Handler, userData == DG_OK);

	return err;
}

...
Following is .grc file.

...

#include "DGDefs.h"
#include "DGWinDefs.h"

/* ------------------------------------------------------------ place Euroform */

'GDLG'	32510	Modal	40	40	300	400	"" {
/* [  1] */ Button				170  350   70   20  LargePlain		"OK"
/* [  2] */ Button				100  350   70   20  LargePlain		"Cancel"
/* [  3] */ CenterText			  8    4  250   12  SmallPlain		"Sample text"
}

'DLGH'	32510	DLG_32510 {
1	"OK Button"			Button_0
2	"Cancel Button"		Button_1
3	"Text"				CenterText_0
}


Environment
- Windows 7
- Visual Studio 2010
- API v19 and ArchiCAD 19
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

I would recommend you to read our blog post: http://archicadapi.graphisoft.com/hello-world-part-2-dialog-with-text-svg-icon-and-button

It demonstrates how to create a basic dialog using GRC resource.
I summarize the most important parts for you:

You can define the look of your dialog in your GRC resource file. If your GRC looks like this:
'GDLG'  32500  Modal	 40   40  300  130  "Hello World Example Dialog" {
/* [  1] */ Button	145  102  150   21	LargePlain  "Close"
/* [  2] */ LeftText	145   55  150   40	LargePlain  "Hello World"
/* [  3] */ Icon	  5    5  120  120	32500
}

'DLGH'  32500  DLG_32500 {
1	"Close Button"		Button_0
2	"Hello World Text"	LeftText_0
3	"Earth Icon"		IconItem_0
}
Then you should create a C++ class for your dialog inherited from the DG::ModalDialog class.
#include	"DGModule.hpp"

class HelloWorldDialog : public DG::ModalDialog,
			 public DG::ButtonItemObserver,
			 public DG::CompoundItemObserver
{
protected:
	enum Controls {
		ButtonID	= 1,
		LeftTextID	= 2,
		IconItemID	= 3
	};

	DG::Button	closeButton;
	DG::LeftText	helloWorldText;
	DG::IconItem	earthIcon;

	virtual void	ButtonClicked	(const DG::ButtonClickEvent& ev) override;

public:
	HelloWorldDialog ();
	~HelloWorldDialog ();
};

HelloWorldDialog::HelloWorldDialog () :
	DG::ModalDialog (ACAPI_GetOwnResModule (), 32500, ACAPI_GetOwnResModule ()),
	closeButton	(GetReference (), ButtonID),
	helloWorldText	(GetReference (), LeftTextID),
	earthIcon	(GetReference (), IconItemID)
{
	AttachToAllItems (*this);
}

HelloWorldDialog::~HelloWorldDialog ()
{
}

void HelloWorldDialog::ButtonClicked (const DG::ButtonClickEvent& ev)
{
	if (ev.GetSource () == &closeButton)
		PostCloseRequest (Accept);
}
And finally you can show your dialog by creating an instance from your class and calling its Invoke method:
static void	ShowDialog ()
{
	HelloWorldDialog dialog;
	dialog.Invoke ();
}

View solution in original post

2 REPLIES 2
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

I would recommend you to read our blog post: http://archicadapi.graphisoft.com/hello-world-part-2-dialog-with-text-svg-icon-and-button

It demonstrates how to create a basic dialog using GRC resource.
I summarize the most important parts for you:

You can define the look of your dialog in your GRC resource file. If your GRC looks like this:
'GDLG'  32500  Modal	 40   40  300  130  "Hello World Example Dialog" {
/* [  1] */ Button	145  102  150   21	LargePlain  "Close"
/* [  2] */ LeftText	145   55  150   40	LargePlain  "Hello World"
/* [  3] */ Icon	  5    5  120  120	32500
}

'DLGH'  32500  DLG_32500 {
1	"Close Button"		Button_0
2	"Hello World Text"	LeftText_0
3	"Earth Icon"		IconItem_0
}
Then you should create a C++ class for your dialog inherited from the DG::ModalDialog class.
#include	"DGModule.hpp"

class HelloWorldDialog : public DG::ModalDialog,
			 public DG::ButtonItemObserver,
			 public DG::CompoundItemObserver
{
protected:
	enum Controls {
		ButtonID	= 1,
		LeftTextID	= 2,
		IconItemID	= 3
	};

	DG::Button	closeButton;
	DG::LeftText	helloWorldText;
	DG::IconItem	earthIcon;

	virtual void	ButtonClicked	(const DG::ButtonClickEvent& ev) override;

public:
	HelloWorldDialog ();
	~HelloWorldDialog ();
};

HelloWorldDialog::HelloWorldDialog () :
	DG::ModalDialog (ACAPI_GetOwnResModule (), 32500, ACAPI_GetOwnResModule ()),
	closeButton	(GetReference (), ButtonID),
	helloWorldText	(GetReference (), LeftTextID),
	earthIcon	(GetReference (), IconItemID)
{
	AttachToAllItems (*this);
}

HelloWorldDialog::~HelloWorldDialog ()
{
}

void HelloWorldDialog::ButtonClicked (const DG::ButtonClickEvent& ev)
{
	if (ev.GetSource () == &closeButton)
		PostCloseRequest (Accept);
}
And finally you can show your dialog by creating an instance from your class and calling its Invoke method:
static void	ShowDialog ()
{
	HelloWorldDialog dialog;
	dialog.Invoke ();
}
Soonbum Jeong
Newcomer
Thank you, Tibor Lorántfy!
You gave me the best solution!