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

How to use ModalDialog ????

Anonymous
Not applicable
Hello,

i'm trying to use modalDialog class so as to have a window with a textEdit, a label and two button( cancel and ok).

I tried this :

- In GRC file :
'GDLG'  4000  Modal   100  100  100  100  "Test Window" {
TextEdit   20  20  60  20  SmallPlain   255
}
- In cpp file :
DG::ModalDialog* modalWindow = new DG::ModalDialog(4000);
if(!modalWindow->Invoke())
    ACAPI_WriteReport("Invoke failed",true);
But the invoke always failed.
May be my grc file is not correctly written, i don't know.
If somebody already used Modaldialog and could help me, i would thank him a lot.

Thank you.

Sébastien
10 REPLIES 10
Ralph Wessel
Mentor
atila-diffusion wrote:
i'm trying to use modalDialog class so as to have a window with a textEdit, a label and two button( cancel and ok).
But the invoke always failed.
May be my grc file is not correctly written, i don't know.
Your resource IDs should start from 32500 (except for palettes and modeless dialogs, which start from 32400).
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
I changed my ressourceId to 32520 but the invoke failed again.

Is it better to use this fonction :
DG::ModalDialog* modalWindow = new DG::ModalDialog(32520);
modalWindow->Invoke();

or this fonction :
DGModalDialog (Fill_GDLGID, Fill_Handler, (DGUserData) &prefsData)
like in the exemple ???

Thank you
Ralph Wessel
Mentor
atila-diffusion wrote:
I changed my ressourceId to 32520 but the invoke failed again.
Is it better to use this fonction :
ModalDialog
or this fonction :
DGModalDialog
like in the exemple ???
Check that your resources compiled with the new ID too.
I use DGModalDialog for several reasons:
  • - All the DG functions have better documentation;
    - It works across more versions of ArchiCAD;
    - I have my own dialog class anyway (wrapping the DG functions) so I can write:
    Dialog about(aboutResID);
    about.show();
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
I suppose you would not want to give me your class ?

Or may be a simple exemple of using which make me able to get back data from textedit.

Thank you
Anonymous
Not applicable
I succeeded to create a modalDialog with two buttons ok and cancel and with a textedit with the DGModalDialog.

But I can't write into my textedit, do you know where could be the problem?


'GDLG'  32500    Modal    0    0  420  460  "Window test"  {
/* [  1] */ Button             340  425   70   20  LargePlain     "OK"
/* [  2] */ Button             260  425   70   20  LargePlain     "Cancel"
/* [  3] */ TextEdit			8    4  250   20  SmallPlain		30
}
static short DGCALLBACK myWindow_Handler (short				message,
									  short				dialogID,
									  short				item,
									  DGUserData		userData,
									  DGMessageData		msgData)
{

	msgData = msgData;
	userData = userData;
	item = item;
	dialogID = dialogID;
		
	switch (message) 
	{
		case DG_MSG_INIT:
			
			break;

		case DG_MSG_CLICK:
			
			if(item == 1) 
				ACAPI_WriteReport("OK",true);

			break;

		case DG_MSG_CLOSE:
							
			break;
	}

	return 1;

}		// Fill_Handler



static void Do_myWindow (void)
{
	GSResModule 	filNum;

	// Get the dialog from our resource file
	filNum = ACAPI_UseOwnResModule ();
	DGModalDialog (32500, myWindow_Handler,0);
	ACAPI_ResetResModule (filNum);
	


}		// Do_FillSettings
Thanks
Anonymous
Not applicable
hello, It's me again,

I found how to et retrieve text data from the textEdit (DGGetItemText for them who are looking for it), but I do not succeed to write into this one since my keyboard, i only can fill it by Copy/Paste.

If somebody knows why I can't write with my keyboard in my TextEdit , Thank you in advance


::::::::::::::::::::::EDIT ::::::::::::::::::::::
I found the solution,

in the callback function I had to add this in the switch(message) :
case DG_MSG_FILTERCHAR:
				 test[0] = char(msgData);
				 test[1] = '\0';
				 strcat(contentKeyValidation,test);
				DGSetItemText (32509, 2, contentKeyValidation);
			break;
:::::::::::::::::::END EDIT :::::::::::::::::::
Oleg
Expert
Hi Atila,

Currently I use DG:: classes and I dont remember about this callback exactly, so guessing.

I think you need to try "return 0;" instead "return 1" in your exampe.
I dont think you need handle FILTERCHAR at all.

Except DialogManager documentation you can look in DG_Test example.

Oleg.
Anonymous
Not applicable
Hi,

you're right, the "return 0 is a mistake, but I do not find how to write in the editbox, the FILTERCHAR is the only way i found to enter any text.
All caracters seems to be filtered.
Oleg
Expert
Hmm, may be I am wrong,
but I think "return 1" was the reason why EditBox didnt work, as it mean all chars were filtered out.
Are you tried "return 0" and remove FILTERCHAR handler ?
If it dont work, then I dont know what is a reason.

Oleg