DialogWindow

I am just starting out with Juce and am having trouble. Doxygen gives a log of info but sometimes not enough for me and I have not been able to find examples of what I want to do. (This is windows and my only windows experience is with MFC).

I started with the “Hello World” example code. I was able to add sliders, button, text, etc to the box and capture the expected inputs. But now I want click a button that opens a dialog box with sliders and buttons on it.

I assume trying to use DialogWindow to do this. First I created and new class derived from DialogWindow. In the constructor I add the controls. Then in MainComponent::buttonClicked, I do the following:

MyDlg *y = new ChannelDlg(x, Colour(0xffeedd), true);
y->showDialog("Hi",y,y,Colour(0xffeedd),true);

This renders a dialog box that is transparent and has no controls. Since doxygen says do not use showDialog I tried to use launchOptions with no success either.

Is there any sample code or tutorial that creates a modeless dialog box started from another dialog and uses the launchOptions?. (I case I have a different understanding of modeless what I mean is the original window that opened the dialog box is still responsive and can take input.

Thanks,
Mark

I always use the static method of the DialogWindow class. First create the component i want to show then just add it as the content of the dialog.

class MyComponent : public Component
{
};
MyComponent comp;
DialogWindow::showModalDialog ("Title", &comp, nullptr, Colours::white, true, false, false);

and that seems to work for me.

Have a look in the JUCE demo project, search for “DialogWindow::LaunchOptions” and you’ll see the colour selector demo is shown in this way.

If you don’t wan’t your window to be modal however I think you just have to call LaunchOptions::create() and then setVisible. Using the same example: [code] DialogWindow::LaunchOptions o;

        o.content.setOwned (new ColourSelector());
        o.content->setSize (400, 400);

        o.dialogTitle                   = "Colour Selector Demo";
        o.dialogBackgroundColour        = Colours::grey;
        o.escapeKeyTriggersCloseButton  = true;
        o.useNativeTitleBar             = false;
        o.resizable                     = true;

        o.create()->setVisible (true);

[/code]

You’ll have to make sure you close the window before shutting down your app though or you’ll hit assertions.

1 Like

Thanks for the replies.
I got it to work.

Mark.

Hello! I would like some help regarding DialogWindow and Texteditor etc.

I’d like to Save a “Preset” to my presets.xml file and the DialogWindow should just take the name of the preset as an input and then close after enter has been pressed (if esc is pressed or closed with mouse, then no preset is created). Now the TextEditor is editable etc, but it will only close with a mouse press and the code is not “halted”. I’d like that the editor will be frozen while the dialogwindow is active.

Currently I’m stuck here: (TextEditor “ted” is created in the header privates).

DialogWindow::LaunchOptions lopt;
lopt.dialogTitle=(“Save Preset”);
lopt.escapeKeyTriggersCloseButton = true;
lopt.resizable = false;
lopt.useNativeTitleBar = true;
lopt.useBottomRightCornerResizer = false;
lopt.componentToCentreAround = this;

ted.setSize(200, 40);
lopt.content.set(&ted, true);
lopt.create()->setVisible(true);

DBG("WTF IS HAPPENING");

Ok! Some progress. I added a TextButton saveBut{“Save”} to the content of the window (which is a texteditor). I now have a problem closing the window - since it should close automatically when closing the window.

Currently the window pointer is stored into wndw = lopt.launchAsync();
And when the savebut is pressed:
lopt.content.set(nullptr, false);
wndw->exitModalState(0);

is called. However a memory error is given:
HEAP[AudioPluginHost.exe]: Invalid address specified to RtlValidateHeap( 000001BCF2C90000, 000001BCF8F50FA8 )

What memory address exactly is invalid, any ideas?