wxFrame: Setting the window's position.  [SOLVED]

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.
tuk1
Experienced Solver
Experienced Solver
Posts: 59
Joined: Sun Oct 08, 2017 9:36 am

wxFrame: Setting the window's position.

Postby tuk1 » Sun May 20, 2018 7:44 am

I need the window to appear in the top, left-hand corner of the screen.
I've tried setting the position via the constructor: wxPoint( 0, 0 ) and various other co-ordinates but the window always appears in the same place(middle of the screen) regardless of the co-ordinates used.

Code: Select all

#define SYMBOL_MAIN_FRAME_STYLE wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX
#define SYMBOL_MAIN_FRAME_TITLE _("MAIN_FRAME")
#define SYMBOL_MAIN_FRAME_IDNAME ID_MAIN_FRAME
#define SYMBOL_MAIN_FRAME_SIZE wxSize(400, 300)
#define SYMBOL_MAIN_FRAME_POSITION wxPoint(0, 0)


class MAIN_FRAME: public wxFrame
{   
   
public:
    /// Constructors
    MAIN_FRAME();
    MAIN_FRAME( wxWindow* parent, wxWindowID id = SYMBOL_MAIN_FRAME_IDNAME, const wxString& caption = SYMBOL_MAIN_FRAME_TITLE, const wxPoint& pos = SYMBOL_MAIN_FRAME_POSITION, const wxSize& size = SYMBOL_MAIN_FRAME_SIZE, long style = SYMBOL_MAIN_FRAME_STYLE );

    bool Create( wxWindow* parent, wxWindowID id = SYMBOL_MAIN_FRAME_IDNAME, const wxString& caption = SYMBOL_MAIN_FRAME_TITLE, const wxPoint& pos = SYMBOL_MAIN_FRAME_POSITION, const wxSize& size = SYMBOL_MAIN_FRAME_SIZE, long style = SYMBOL_MAIN_FRAME_STYLE );
......................
......................
wxWidgets(v3.0.3) - Vs2015(v14) - Win7(x64) - DialogBlocks(v5.15.3_Unicode)

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

Re: wxFrame: Setting the window's position.  [SOLVED]

Postby doublemax » Sun May 20, 2018 9:25 am

Hard to tell what's the problem, but you can always call SetSize(...) after showing the frame.
http://docs.wxwidgets.org/trunk/classwx ... d52d67a74e
Use the source, Luke!

tuk1
Experienced Solver
Experienced Solver
Posts: 59
Joined: Sun Oct 08, 2017 9:36 am

Re: wxFrame: Setting the window's position.

Postby tuk1 » Sun May 20, 2018 9:54 am

That does work:

Code: Select all

bool Logger_v1_App::OnInit()
{   
   MAIN_FRAME* mainWindow = new MAIN_FRAME( NULL );
   mainWindow->Show(true);
   
   
   mainWindow->SetSize( 0, 0, 400, 300 );

    return true;
}


Which led to a more targetted dig around...to unearth the culprit:

Code: Select all

bool MAIN_FRAME::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    wxFrame::Create( parent, id, caption, pos, size, style );

    CreateControls();
    if (GetSizer())
    {
        GetSizer()->SetSizeHints(this);
    }

    Centre();  <<<<------------------------ Overrides the constructor position co-ordinates.

    return true;
}



I guess that is one drawback of using WYSIWYG editors for newbies, they might add stuff by default which creates unexpected behaviour.
wxWidgets(v3.0.3) - Vs2015(v14) - Win7(x64) - DialogBlocks(v5.15.3_Unicode)

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

Re: wxFrame: Setting the window's position.

Postby doublemax » Sun May 20, 2018 10:11 am

I guess that is one drawback of using WYSIWYG editors for newbies, they might add stuff by default which creates unexpected behaviour.
There might be a checkbox in the frame properties to switch that off.
Use the source, Luke!


Return to “C++ Development”

Who is online

Users browsing this forum: No registered users and 13 guests