cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 
cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 
Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Modal Dialog X Button (Close Box) - How to properly handle or remove?

Steve Sunny
Contributor

I have a Modal dialog created with DGModalDialog and I'm having trouble with the X (close) button in the title bar.

GRC Definition:

 

'GDLG' 32500 Modal 0 0 680 640 "My Dialog" {
/* [ 1] */ TextEdit 15 45 540 25 LargePlain 256
/* [ 2] */ Button 565 45 100 25 LargePlain "Search"
/* [ 3] */ Button 565 600 100 30 LargePlain "Cancel"
}

Callback (simplified):
static short DGCALLBACK MyDialogCallback(short message, short dialogID, short item,
DGUserData userData, DGMessageData msgData)
{
switch (message) {
case DG_MSG_INIT:
return 0;

case DG_MSG_CLICK:
if (item == 3) { // Cancel button
return 3; // Close dialog - THIS WORKS
}
break;

case DG_MSG_CLOSE:
return 3; // Close dialog
}
return 0;
}

// Called with:
short result = DGModalDialog(resModule, 32500, resModule, MyDialogCallback, 0);

 

Problem:
- Clicking the Cancel button (item 3) correctly closes the dialog
- Clicking the X button in the title bar does NOT close the dialog

When X is clicked, I see DG_MSG_CLICK with item=2 first (my Search button!), then item=3, then DG_MSG_CLOSE. Even returning the button ID from all handlers doesn't close the dialog on X click.

Questions:
1. How do I properly handle the X button click on a Modal dialog?
2. Is there a way to remove just the X button while keeping the title bar? (I know Palettes have noClose flag, but Modal dialogs don't seem to have this option)

Using ArchiCAD API 28 on Windows.

2 ACCEPTED SOLUTIONS

Accepted Solutions
Solution
Sam Karli
Advocate

Afaik the X button has a fixed number of 1.

'GDLG'  SettingsPageId  Modal   0      0  300  70  "Settings" {
/* [  1] */ Button				      284   40   16  20  SmallPlain  ""
/* [  2] */ LeftText            0      0  145  20  SmallPlain  vCenter  "Loglevel"
/* [  3] */ PopupControl        150    0  150  20  24 5
/* [  4] */ LeftText            0     20  245  20  SmallPlain  vCenter  "Minimum number of edges to create an arc"
/* [  5] */ IntEdit             250   20   50  20  SmallPlain  "0" "1000"
}

'DLGH'  SettingsPageId  DLG_SettingsPageId {
1	"Close window"		                                Button_OK
2	"Loglevel"		                                    LeftText_LogLev
3	"Select Loglevel"		                              PopupControl_LogLev
4	"Minimum number of edges to create an arc"		    LeftText_ArcEdges
5	"Select Minimum number of edges to create an arc" IntEdit_ArcEdges
}

 

// For PolygonReducer.grc

#define SettingsPageId        32705

#define Button_OK             1
#define Button_Cancel         2
#define LeftText_LogLev       3
#define PopupControl_LogLev   4
#define LeftText_ArcEdges     5
#define IntEdit_ArcEdges      6

 

switch (message) {
  case DG_MSG_INIT:
// ...
    break;
  case DG_MSG_CLICK:
    switch (item) {
    case DG_OK:
      result = item;

      break;
    }
}

 

DG_OK and DG_CANCEL are defined in DGDefs.h.

Here I don't have a Cancel button, it is here only as a placeholder. Per its documentation:
"Modal dialogs have a so called default button which appears with a bold outline. The default button always should be the first dialog item in the dialog's item list (its item ID is DG_OK). Most modal dialogs also have a Cancel button which should be the second in the item list (its item ID is DG_CANCEL). Except for some special cases, pressing the ENTER or the ESC key has the same effect as clicking the default or the cancel button, respectively. For details see the dialog keyboard interface page.
---

DGModalDialog returns only if the modal dialog is closed. The user usually closes a modal dialog by clicking the OK or the Cancel button. The dialog callback function receives a DG_MSG_CLICK message with DG_OK or DG_CANCEL as the item parameter. On Windows, if the user clicks the close box in the caption the item parameter is DG_CANCEL (or DG_OK if there is no Cancel button in the dialog)."

 

Take this with a grain of salt, I also have my own UI problems, but this might help.

GDL/Python/C++ dev

View solution in original post

Solution
Steve Sunny
Contributor

Hi Sam,

Thank you for your help! Your solution worked perfectly.

Moving the Cancel button to Item 2 in the GRC resource file fixed the X button issue. The dialog now closes correctly when clicking the X button - no special workaround code needed.

For anyone else with this issue, the key is:
- Item 1 = Default/OK button
- Item 2 = Cancel button (X button triggers this automatically)

Thanks again!

Steve

View solution in original post

2 REPLIES 2
Solution
Sam Karli
Advocate

Afaik the X button has a fixed number of 1.

'GDLG'  SettingsPageId  Modal   0      0  300  70  "Settings" {
/* [  1] */ Button				      284   40   16  20  SmallPlain  ""
/* [  2] */ LeftText            0      0  145  20  SmallPlain  vCenter  "Loglevel"
/* [  3] */ PopupControl        150    0  150  20  24 5
/* [  4] */ LeftText            0     20  245  20  SmallPlain  vCenter  "Minimum number of edges to create an arc"
/* [  5] */ IntEdit             250   20   50  20  SmallPlain  "0" "1000"
}

'DLGH'  SettingsPageId  DLG_SettingsPageId {
1	"Close window"		                                Button_OK
2	"Loglevel"		                                    LeftText_LogLev
3	"Select Loglevel"		                              PopupControl_LogLev
4	"Minimum number of edges to create an arc"		    LeftText_ArcEdges
5	"Select Minimum number of edges to create an arc" IntEdit_ArcEdges
}

 

// For PolygonReducer.grc

#define SettingsPageId        32705

#define Button_OK             1
#define Button_Cancel         2
#define LeftText_LogLev       3
#define PopupControl_LogLev   4
#define LeftText_ArcEdges     5
#define IntEdit_ArcEdges      6

 

switch (message) {
  case DG_MSG_INIT:
// ...
    break;
  case DG_MSG_CLICK:
    switch (item) {
    case DG_OK:
      result = item;

      break;
    }
}

 

DG_OK and DG_CANCEL are defined in DGDefs.h.

Here I don't have a Cancel button, it is here only as a placeholder. Per its documentation:
"Modal dialogs have a so called default button which appears with a bold outline. The default button always should be the first dialog item in the dialog's item list (its item ID is DG_OK). Most modal dialogs also have a Cancel button which should be the second in the item list (its item ID is DG_CANCEL). Except for some special cases, pressing the ENTER or the ESC key has the same effect as clicking the default or the cancel button, respectively. For details see the dialog keyboard interface page.
---

DGModalDialog returns only if the modal dialog is closed. The user usually closes a modal dialog by clicking the OK or the Cancel button. The dialog callback function receives a DG_MSG_CLICK message with DG_OK or DG_CANCEL as the item parameter. On Windows, if the user clicks the close box in the caption the item parameter is DG_CANCEL (or DG_OK if there is no Cancel button in the dialog)."

 

Take this with a grain of salt, I also have my own UI problems, but this might help.

GDL/Python/C++ dev
Solution
Steve Sunny
Contributor

Hi Sam,

Thank you for your help! Your solution worked perfectly.

Moving the Cancel button to Item 2 in the GRC resource file fixed the X button issue. The dialog now closes correctly when clicking the X button - no special workaround code needed.

For anyone else with this issue, the key is:
- Item 1 = Default/OK button
- Item 2 = Cancel button (X button triggers this automatically)

Thanks again!

Steve