I was watching a quick basic tutorial about wx-widgets and creationg of simple GUI using C++. I wanted to make my window a fixed size one (impossible to maximize or drag to expand/contract). Currently the code I have on the constructor of my main class is the one below:
main::main() : wxFrame(nullptr, wxID_ANY, "Usage Statistics Viewing Console", wxDefaultPosition, wxSize(1008, 567), wxDEFAULT_FRAME_STYLE)
{
m_btn1 = new wxButton(this, 1, "Connect Database", wxPoint(10, 10), wxSize(150, 50));
m_txt1 = new wxTextCtrl(this, wxID_ANY, " ", wxPoint(10, 70), wxSize(300, 30));
m_list1 = new wxListBox(this, wxID_ANY, wxPoint(10, 110), wxSize(300, 300));
}
I believe I have to make changes to the wxFrame parameters, but I searched on the wx database about the function and to be honest I don't have enough knowledge to understand half of what is there. I suppose I could change the way the window behaves with the "styles" param. but I tried them all and none produce the effect I'm looking for.
If you look at the documentation for wxFrame, under the styles section it states that wxDEFAULT_FRAME_STYLE
is defined as
wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN.
To make it so that the user can not resize the window, you just need to remove the wxRESIZE_BORDER
from this set. Like so:
main::main() : wxFrame(nullptr, wxID_ANY, "Usage Statistics Viewing Console",
wxDefaultPosition, wxSize(1008, 567),
wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxSYSTEM_MENU
| wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
{...
or if your familiar with C's bitwise operations, you can write this more compactly as:
main::main() : wxFrame(nullptr, wxID_ANY, "Usage Statistics Viewing Console",
wxDefaultPosition, wxSize(1008, 567),
wxDEFAULT_FRAME_STYLE & ~wxRESIZE_BORDER)
I'd like to offer 2 other suggestions. First you can improve the appearance of your frames by using a panel as the only direct child of the frame and then having all other controls be children of the panel.
wxPanel* panel = new wxPanel(this, wxID_ANY);
m_btn1 = new wxButton(panel, wxID_ANY, "Connect Database", wxPoint(10, 10), wxSize(150, 50));
m_txt1 = new wxTextCtrl(panel, wxID_ANY, " ", wxPoint(10, 70), wxSize(300, 30));
m_list1 = new wxListBox(panel, wxID_ANY, wxPoint(10, 110), wxSize(300, 300));
Second, at some point you should look into using sizers to manage the size and position of your controls instead of using the size and position parameters in the controls constructor. Sizers can be a little tricky to learn but are a great benefit once you get the hang of them. There are also tools like wxFormbuilder or wxCrafter that can help with laying out your forms using sizers.