wxApp and the initial window show

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
xargon
Knows some wx things
Knows some wx things
Posts: 25
Joined: Wed Feb 25, 2009 3:00 pm

wxApp and the initial window show

Post by xargon » Thu Jan 14, 2016 4:37 pm

My wxApp application implementation looks as follows:

Code: Select all

// The main application class.
class TestApp : public wxApp
{
public:
    virtual bool OnInit()
    {
        if (!wxApp::OnInit())
            return false;

        AppWindow * app_win = new AppWindow(wxT("App")); // This derives from wxFrame
        new SplashVideo(wxT("/home/xargon/widescreen.avi"),
                        app_win, wxID_ANY); // Modal dialog based class showing a video
        wxYield();
        app_win->Show(true);
        return true;
    }
};

wxIMPLEMENT_APP(TestApp);
This is almost working. However, I notice when I start the app an initial window gets created which quickly disappears and then the splash screen gets shown and then the app_win object gets shown. This initial window on examination is not the AppWindow based object but some bare window created by wxWidgets. However, this makes the application start a bit bad as we have this window showing and disappearing followed by the splash screen. Is there a way to avoid this?

User avatar
doublemax
Moderator
Moderator
Posts: 15263
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxApp and the initial window show

Post by doublemax » Thu Jan 14, 2016 4:54 pm

Why do you create the app_win before the splash window? You can create the dialog with NULL as parent. Also i would create the dialog on the stack and call ShowModal() immediately.

Code: Select all

{
  SplashVideo splash(wxT("/home/xargon/widescreen.avi"));
  splash.ShowModal();
}

AppWindow * app_win = new AppWindow(wxT("App"));
app_win->Show(true);
Use the source, Luke!

xargon
Knows some wx things
Knows some wx things
Posts: 25
Joined: Wed Feb 25, 2009 3:00 pm

Re: wxApp and the initial window show

Post by xargon » Thu Jan 14, 2016 6:01 pm

I tried that as well and it still shows this initial window (which has the name of the compiled executable as the window title for some reason). I did:

Code: Select all


virtual bool OnInit()
 {
        if (!wxApp::OnInit())
            return false;

        SplashVideo video(wxT("/home/xargon/widescreen.avi"),
                          NULL, wxID_ANY);
        video.ShowModal();
        AppWindow * app_win = new AppWindow(wxT("App"));
        app_win->Show(true);
        return true;
 }
The creation of the window before or after does not make a difference. Neither did the stack or heap creation of the dialog. Also removing the first line (calling the parent OnInit()) also has no effect. It seems that the OnInit() creates some initial window. I am on Ubuntu 14.04 with wxWidgets 3.0.2.

Also, if I do not create the AppWindow object at all, this initial window still shows...

User avatar
doublemax
Moderator
Moderator
Posts: 15263
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxApp and the initial window show

Post by doublemax » Thu Jan 14, 2016 6:07 pm

Does this also happen in one of the samples?

What happens if you comment out the splash window? Maybe it's the media player that flashes shortly?
Use the source, Luke!

xargon
Knows some wx things
Knows some wx things
Posts: 25
Joined: Wed Feb 25, 2009 3:00 pm

Re: wxApp and the initial window show

Post by xargon » Thu Jan 14, 2016 6:18 pm

Ok, when I remove the SplashVideo dialog it does not happen.

Then I show the dialog and without the wxMediaCtrl and it does not happen either. So, it seems perhaps the media control is created with some size and then positioned to where the dialog is!

I tried now calling the CenterOnScreen() first but that does not change anything. So, now my SplashVideo constructor looks like:

Code: Select all

SplashVideo::SplashVideo(const wxString & video_path,
                         wxWindow * parent, wxWindowID id, const wxPoint & pos,
                         const wxSize & size, long style)
    :wxDialog(parent, id, wxEmptyString, pos, size,
              style | wxFRAME_TOOL_WINDOW | wxFRAME_NO_TASKBAR)
{
    SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT);
    this->CenterOnScreen();
    media_ctrl = new wxMediaCtrl(this, ID_MEDIA_CTRL, video_path);
    this->Connect(ID_MEDIA_CTRL, wxEVT_MEDIA_LOADED,
                  wxMediaEventHandler(SplashVideo::OnMediaLoaded));

    this->Connect(ID_MEDIA_CTRL, wxEVT_MEDIA_FINISHED,
                  wxMediaEventHandler(SplashVideo::OnMediaFinished));
    media_ctrl->Play();
}

DenDev
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 223
Joined: Mon Jan 19, 2015 1:45 pm

Re: wxApp and the initial window show

Post by DenDev » Thu Jan 14, 2016 6:18 pm

Remove this and try again:

Code: Select all

if (!wxApp::OnInit())
            return false;
I have a bad habbit of not testing the code I post :D

xargon
Knows some wx things
Knows some wx things
Posts: 25
Joined: Wed Feb 25, 2009 3:00 pm

Re: wxApp and the initial window show

Post by xargon » Thu Jan 14, 2016 6:25 pm

DenDev wrote:Remove this and try again:

Code: Select all

if (!wxApp::OnInit())
            return false;
This I tried already and it does not help :(

User avatar
doublemax
Moderator
Moderator
Posts: 15263
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxApp and the initial window show

Post by doublemax » Thu Jan 14, 2016 6:26 pm

I don't work under Linux so i can't test this.

Things you can try:

Does it happen in the mediaplayer sample? If yes, there is probably nothing you can do about it.

Code: Select all

SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT);
remove this

Code: Select all

media_ctrl->Play();
The "officially" correct way is to catch the wxEVT_MEDIA_LOADED event and play the file from there
Use the source, Luke!

xargon
Knows some wx things
Knows some wx things
Posts: 25
Joined: Wed Feb 25, 2009 3:00 pm

Re: wxApp and the initial window show

Post by xargon » Thu Jan 14, 2016 6:30 pm

I did the event handling thing as well and it still happens. I also tried removing the extra style thing and also happens...I will look into the sample now.

DenDev
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 223
Joined: Mon Jan 19, 2015 1:45 pm

Re: wxApp and the initial window show

Post by DenDev » Thu Jan 14, 2016 6:36 pm

Have you tried to do the create and ShowModal the splashwindow as the last line of code in the app_win's constructor? Or have you tried to assign an event handler for wxEVT_SHOW on the app_win and create/ShowModal the splash from there?

AFAIK wxApp requires a valid window handle in order to create a working event loop, and it might be that window which flashes because you "break" the initialization (wxApp::OnInit) with a "hanging" call that prevents the event loop from being entered before a modal state is provoked.
I have a bad habbit of not testing the code I post :D

xargon
Knows some wx things
Knows some wx things
Posts: 25
Joined: Wed Feb 25, 2009 3:00 pm

Re: wxApp and the initial window show

Post by xargon » Thu Jan 14, 2016 6:46 pm

So, I did that as well and it still happens. So the AppWindow constructor looks like:

AppWindow::AppWindow(const wxString &title)
:wxFrame(NULL, wxID_ANY, title, wxDefaultPosition)
{
SplashVideo video(wxT("/home/xargon/widescreen.avi"),
NULL, wxID_ANY);
video.Create();
video.ShowModal();
}

xargon
Knows some wx things
Knows some wx things
Posts: 25
Joined: Wed Feb 25, 2009 3:00 pm

Re: wxApp and the initial window show

Post by xargon » Thu Jan 14, 2016 6:57 pm

Ok, It does not happen on the sample but it also does not happen for me if the constructor for the media control does not load a file. If I load the file in a separate method, it still happens but not everytime :( I will investigate this more tomorrow and update the thread.

Thank you for all your help. Stay awesome!

Post Reply