Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / DialogBlocks - Create a dialog application?

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. DialogBlocks - Create a dialog application?
#2852
Posted by: 2003-11-05 20:33:47
Hi,

what format do i need for creating a dialog based app?

I tried creating a wxApp child class which loaded my dialog which worked great until i closed the dialog, then the app carried on running. There was no way for me to kill it.

I tried implementing the application in the dialog class, but the call to IMPLEMENT_APP fails.

Can anyone point me in the right direction?

Thanks
Message2. Re: DialogBlocks - Create a dialog application?
#2854
Posted by: upCASE 2003-11-05 21:02:03
Hi Skute!
It's not that complecated, you're on the right track and will be done in just a minute :))

Problem is that dialogs normally have their own event loop. This is necessary when using dialogs modal (so the dialog is on top of all the action going on in a frame you created it from). That means that if the frame is closed, the parent of the dialog dies and so the dialog will be destroyed. Since there is no parent when using only a dialog instead of a frame, the dialog is closed and then there's a return to the normal wxApp event loop. So, what you'll have to do is implement an event handler to Destroy the dialog correctly and terminate the wxApp.
Do it like this:

In your dialog class derived from wxDialog add a method like OnQuit() and implement it.

bool MainApp::OnInit() //stating point of the application
{	//Create the dialog
   MyDialog *win = new MyDialog("Bla", wxDefaultPosition,wxDefaultSize);
   win->Centre(); // center the dialog on screen
   win->Show(TRUE); // show the dialog on screen
   SetTopWindow( win ); // make dialog the zop window
   
   return true;
}

BEGIN_EVENT_TABLE(MyDialog, wxDialog)
   EVT_CLOSE( MyDialog::OnQuit)
END_EVENT_TABLE()
...
...
//Perform quit operation: Destroy the dialog and all its contents
void MainDialog::OnQuit(wxCommandEvent & WXUNUSED(event))
{
    Destroy(); // this calls all needed detructors
}
...
...

Now if you're closing the dialog, it should destroy the whole app.

upcase
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message3. Re: DialogBlocks - Create a dialog application?
#2856
Posted by: 2003-11-05 22:49:32
Thanks :)

It worked great!
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
¥1,290.00 ·
 
 
¥918.00 ·
 
 
¥890.00 ·
 
 
¥294.00 ·
 
 
¥430.00 ·
 
 
¥1,380.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0