views:

364

answers:

1

Hello. I have this WxWidgets test source code that compiles, and when run, it shows a simple frame:

/*
 * hworld.cpp
 * Hello world sample by Robert Roebling
 */

#include "wx-2.8/wx/wx.h"

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

class MyFrame: public wxFrame
{
public:

     MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);

    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);

    DECLARE_EVENT_TABLE()
};

enum
{
    ID_Quit = 1,
    ID_About,
};

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(ID_Quit, MyFrame::OnQuit)
    EVT_MENU(ID_About, MyFrame::OnAbout)
END_EVENT_TABLE()

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame( _T("Hello World"), wxPoint(50,50), wxSize(450,340) );
    frame->Show(TRUE);
    SetTopWindow(frame);
    return TRUE;
}

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
    wxMenu *menuFile = new wxMenu;

    menuFile->Append( ID_About, _T("&About...") );
    menuFile->AppendSeparator();
    menuFile->Append( ID_Quit, _T("E&xit") );

    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append( menuFile, _T("&File") );

    SetMenuBar( menuBar );

    CreateStatusBar();
    SetStatusText( _T("Welcome to wxWindows!") );
}

void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
    Close(TRUE);
}

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
    wxMessageBox(_T("This is a wxWindows Hello world sample"),
        _T("About Hello World"), wxOK | wxICON_INFORMATION, this);
}

Created with this simple SCons script:

env = Environment()
env.ParseConfig('wx-config --cxxflags --libs')

env.Program(target='wxTest/wxTest.exe',source=['src/Wxwidgets.cpp'])

The problem: it wont focus when I run it. The only thing I can focus is the red, yellow and green buttons in the upper left corner. I use Eclipse as my IDE and run scons as an external tool when I build it.

Is there someone out there that know what Im doing wrong? How can I get the frame to focus?

Hope there is someone out the who can help me.

+1  A: 

I assume you start the raw executable that is created? This does not work on Mac OS X, see My app can't be brought to the front!

You will have to create an application bundle for your app to work properly on Mac OS X. I don't know anything about SCons, but maybe the wiki does help?

mghie
Aaah I didnt know that I needed a bundle. Maybe I just have to dive into how making that for my program :) thanks for the link!!
mslot