<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Modal Dialog X Button (Close Box) - How to properly handle or remove? in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Modal-Dialog-X-Button-Close-Box-How-to-properly-handle-or-remove/m-p/685856#M10722</link>
    <description>&lt;P&gt;I have a Modal dialog created with DGModalDialog and I'm having trouble with the X (close) button in the title bar.&lt;/P&gt;
&lt;P&gt;GRC Definition:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;'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);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Problem:&lt;BR /&gt;- Clicking the Cancel button (item 3) correctly closes the dialog&lt;BR /&gt;- Clicking the X button in the title bar does NOT close the dialog&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;Questions:&lt;BR /&gt;1. How do I properly handle the X button click on a Modal dialog?&lt;BR /&gt;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)&lt;/P&gt;
&lt;P&gt;Using ArchiCAD API 28 on Windows.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Dec 2025 15:35:12 GMT</pubDate>
    <dc:creator>Steve Sunny</dc:creator>
    <dc:date>2025-12-04T15:35:12Z</dc:date>
    <item>
      <title>Modal Dialog X Button (Close Box) - How to properly handle or remove?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Modal-Dialog-X-Button-Close-Box-How-to-properly-handle-or-remove/m-p/685856#M10722</link>
      <description>&lt;P&gt;I have a Modal dialog created with DGModalDialog and I'm having trouble with the X (close) button in the title bar.&lt;/P&gt;
&lt;P&gt;GRC Definition:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;'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);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Problem:&lt;BR /&gt;- Clicking the Cancel button (item 3) correctly closes the dialog&lt;BR /&gt;- Clicking the X button in the title bar does NOT close the dialog&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;Questions:&lt;BR /&gt;1. How do I properly handle the X button click on a Modal dialog?&lt;BR /&gt;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)&lt;/P&gt;
&lt;P&gt;Using ArchiCAD API 28 on Windows.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Dec 2025 15:35:12 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Modal-Dialog-X-Button-Close-Box-How-to-properly-handle-or-remove/m-p/685856#M10722</guid>
      <dc:creator>Steve Sunny</dc:creator>
      <dc:date>2025-12-04T15:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: Modal Dialog X Button (Close Box) - How to properly handle or remove?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Modal-Dialog-X-Button-Close-Box-How-to-properly-handle-or-remove/m-p/686263#M10725</link>
      <description>&lt;P&gt;Afaik the X button has a fixed number of 1.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;'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
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;// 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

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;switch (message) {
  case DG_MSG_INIT:
// ...
    break;
  case DG_MSG_CLICK:
    switch (item) {
    case DG_OK:
      result = item;

      break;
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;DG_OK&lt;/EM&gt; and &lt;EM&gt;DG_CANCEL&lt;/EM&gt; are defined in DGDefs.h.&lt;/P&gt;
&lt;P&gt;Here I don't have a Cancel button, it is here only as a placeholder. Per its documentation:&lt;BR /&gt;"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 &lt;TT&gt;&lt;FONT style="background-color: #0078d7;" color="#ffffff"&gt;DG_OK&lt;/FONT&gt;&lt;/TT&gt;). Most modal dialogs also have a Cancel button which should be the second in the item list (its item ID is &lt;TT&gt;DG_CANCEL&lt;/TT&gt;). Except for some special cases, pressing the &lt;TT&gt;ENTER&lt;/TT&gt; or the &lt;TT&gt;ESC&lt;/TT&gt; key has the same effect as clicking the default or the cancel button, respectively. For details see the &lt;A href="https://community.graphisoft.com/DialogKBInterface.html" target="_blank" rel="noopener"&gt;dialog keyboard interface&lt;/A&gt; page.&lt;BR /&gt;---&lt;/P&gt;
&lt;DIV id="content" class="inset"&gt;
&lt;P&gt;&lt;STRONG&gt;DGModalDialog&lt;/STRONG&gt; 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 &lt;TT&gt;DG_MSG_CLICK&lt;/TT&gt; message with &lt;TT&gt;&lt;FONT style="background-color: #0078d7;" color="#ffffff"&gt;DG_OK&lt;/FONT&gt;&lt;/TT&gt; or &lt;TT&gt;DG_CANCEL&lt;/TT&gt; as the &lt;EM&gt;item&lt;/EM&gt; parameter. On Windows, if the user clicks the close box in the caption the &lt;EM&gt;item&lt;/EM&gt; parameter is &lt;TT&gt;DG_CANCEL&lt;/TT&gt; (or &lt;TT&gt;&lt;FONT style="background-color: #0078d7;" color="#ffffff"&gt;DG_OK&lt;/FONT&gt;&lt;/TT&gt; if there is no Cancel button in the dialog)."&lt;/P&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take this with a grain of salt, I also have my own UI problems, but this might help.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Dec 2025 12:48:49 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Modal-Dialog-X-Button-Close-Box-How-to-properly-handle-or-remove/m-p/686263#M10725</guid>
      <dc:creator>Sam Karli</dc:creator>
      <dc:date>2025-12-08T12:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: Modal Dialog X Button (Close Box) - How to properly handle or remove?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Modal-Dialog-X-Button-Close-Box-How-to-properly-handle-or-remove/m-p/686514#M10726</link>
      <description>&lt;P&gt;Hi Sam,&lt;/P&gt;&lt;P&gt;Thank you for your help! Your solution worked perfectly.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;For anyone else with this issue, the key is:&lt;BR /&gt;- Item 1 = Default/OK button&lt;BR /&gt;- Item 2 = Cancel button (X button triggers this automatically)&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Wed, 10 Dec 2025 04:57:06 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Modal-Dialog-X-Button-Close-Box-How-to-properly-handle-or-remove/m-p/686514#M10726</guid>
      <dc:creator>Steve Sunny</dc:creator>
      <dc:date>2025-12-10T04:57:06Z</dc:date>
    </item>
  </channel>
</rss>

