Page 1 of 1

Win32 - Frames don't close

Posted: Tue Sep 21, 2004 2:27 pm
by dessaya
Hello, I'm new to wxWidgets and I'm having this little problem.

My application compiles and runs perfectly under Linux/GTK+2. I'm trying to make it run on Windows 98. I compiled wxWidgets 2.4.2 using Cygwin/g++ 3.3.3. My app compiles with no errors/warnings, but when I run it, it behaves oddly. I create a wxSplashScreen with timeout, and it just doesn't close. It stays there forever. And the main window does the same. I have to kill the application to close all the frames.

The wxWidgets samples compile and run with no problems, so there's something wrong with my code... but I just can't find the error.

I have reduced the code to a bare minimum:

Code: Select all

#include "wx/wx.h"

class TpApp: public wxApp
{
    virtual bool OnInit();
};

IMPLEMENT_APP(TpApp)

bool TpApp::OnInit()
{
	wxMessageBox("Hello", "Hello");
	return TRUE;
}
The dialog box is showed, and when I click on OK, the dialog closes, but the program hangs and I have to kill it.

Is there anything wrong in this code?

Thanks for your help,

Diego Essaya

Posted: Tue Sep 21, 2004 2:33 pm
by Jorg
When returning TRUE from OnInit you tell wx that everything initialized ok and that the program can create it's message loop. That's exacttly what happens. Although no window is present .. check out the Minimal sample in the samples/minimal to see how it is done. If you don't want a frame but only the dialog box, return FALSE (this kills the app) or issue a Close() ..
wxApp::OnInit

bool OnInit()

This must be provided by the application, and will usually create the application's main window, optionally calling wxApp::SetTopWindow.

Notice that if you want to to use the command line processing provided by wxWindows you have to call the base class version in the derived class OnInit().

Return TRUE to continue processing, FALSE to exit the application.
Regards.
- Jorgen

Posted: Wed Sep 22, 2004 7:17 pm
by dessaya
Jorg wrote:When returning TRUE from OnInit you tell wx that everything initialized ok and that the program can create it's message loop. That's exacttly what happens. Although no window is present .. check out the Minimal sample in the samples/minimal to see how it is done. If you don't want a frame but only the dialog box, return FALSE (this kills the app) or issue a Close() ..
I managed to work it out... you were right about the wxMessageBox example, but my application failed because of another mistake.

The problem was something like this:

Code: Select all

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_PAINT(MyFrame::OnPaint)
END_EVENT_TABLE()

(...)

void MyFrame::OnPaint(wxPaintEvent &event)
{
}
The OnPaint function was empty, and I didn't declare a wxPaintDC, and IIRC the documentation says it should be always declared. I removed this function and problem solved :D

Thanks for the help!

Diego Essaya