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

Modeless or Palette Dialog help

Anonymous
Not applicable
Hi
hope someone can help me with a Modeless or Palette Example Code.
I understand how to create a modal dialog but not modeless/palette. I want a palette dialog to have buttons. so far I can't get the dialog to response to the button click event. my code goes to the DG_MSG_INIT of the callback than leaves the function altogether never to return.
1 REPLY 1
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

I think you forgot to call ACAPI_RegisterModelessWindow function in DG_MSG_INIT, that's why you won't get any further messages.
I wrote you an example code to show a simple palette with 2 buttons:
// Note that dialID could be different from dialog's resourceID 
static short	myDialID = 0; 
 
// ----------------------------------------------------------------------------- 
// 
// ----------------------------------------------------------------------------- 
static GSErrCode __ACENV_CALL	PaletteAPIControlCallBack (Int32 referenceID, API_PaletteMessageID messageID, GS::IntPtr /*param*/) 
{ 
	if (referenceID == myDialID) { 
		switch (messageID) { 
			case APIPalMsg_ClosePalette:		DGModelessClose (myDialID); 
												break; 
			case APIPalMsg_HidePalette_Begin:	DGHideModelessDialog (myDialID); 
												break; 
			case APIPalMsg_HidePalette_End:		DGShowModelessDialog (myDialID, DG_DF_FIRST); 
												break; 
			case APIPalMsg_DisableItems_Begin: 
			case APIPalMsg_DisableItems_End:	// actually do nothing, because the input finish functionality the buttons have to stay enabled 
			case APIPalMsg_IsPaletteVisible: 
			case APIPalMsg_OpenPalette:			break; 
		} 
	} 
 
	return NoError; 
} 
 
// ----------------------------------------------------------------------------- 
// 'GDLG' resource in (RINT) .grc file 
// ----------------------------------------------------------------------------- 
 
'GDLG'  32400  Palette | leftCaption | grow | close      0    0  196   28  "Example Palette" { 
/* [  1] */ Button				  88    4   70   20	LargePlain  "Close" 
/* [  2] */ Button				   8    4   70   20	LargePlain  "Update" 
} 
 
const short CloseButtonID	= 1; 
const short UpdateButtonID	= 2; 
 
// ----------------------------------------------------------------------------- 
// Callback function for the palette 
// ----------------------------------------------------------------------------- 
 
static short DGCALLBACK CntlDlgCallBack (short message, short dialID, short item, DGUserData /*userData*/, DGMessageData msgData) 
{ 
	switch (message) { 
		case DG_MSG_INIT: 
			DGSetFocus (dialID, DG_NO_ITEM); 
 
			if (ACAPI_RegisterModelessWindow (dialID, PaletteAPIControlCallBack, 
						API_PalEnabled_FloorPlan + API_PalEnabled_Section + API_PalEnabled_Elevation + 
						API_PalEnabled_InteriorElevation + API_PalEnabled_Detail + API_PalEnabled_Worksheet + API_PalEnabled_3D + API_PalEnabled_Layout) != NoError) 
				DBPrintf ("ACAPI_RegisterModelessWindow failed\n"); 
			break; 
 
		case DG_MSG_ACTIVATE:		break; 
		case DG_MSG_UPDATE:			break; 
		case DG_MSG_CHANGE:			break; 
		case DG_MSG_DOUBLECLICK:	break; 
 
		case DG_MSG_CLICK: 
			switch (item) { 
				case UpdateButtonID:	// handle update button click event! 
										break; 
				case CloseButtonID: 
				case DG_CLOSEBOX: 
						return item;	// this will result in a DG_MSG_CLOSE message 
			} 
			break; 
 
		case DG_MSG_GROW: 
			{ 
				short	vgrow = DGGetVGrow (msgData); 
				short	hgrow = DGGetHGrow (msgData); 
				DGBeginMoveGrowItems (dialID); 
				DGMoveItem (dialID, NavCloseButton, hgrow, vgrow); 
				DGMoveItem (dialID, NavUpdateButton, hgrow, vgrow); 
				DGEndMoveGrowItems (dialID); 
			} 
			break; 
 
		case DG_MSG_CLOSE:
			ACAPI_UnregisterModelessWindow (myDialID); 
			myDialID = 0; 
			break; 
 
		default: 
			break; 
	} 
 
	return (0); 
}		// CntlDlgCallBack 
 
// ----------------------------------------------------------------------------- 
// Initialize/open our palette 
// ----------------------------------------------------------------------------- 
 
static bool		Do_PaletteInit (void) 
{ 
	if (myDialID == 0 || !DGIsDialogOpen (myDialID)) 
		myDialID = DGModelessInit (ACAPI_GetOwnResModule (), 32400, ACAPI_GetOwnResModule (), CntlDlgCallBack, NULL, 1); 
 
	return myDialID != 0; 
}		// Do_PaletteInit


Regards,
Tibor