### Setup(wxWindow *parent) Source: https://docs.wxwidgets.org/3.3/classwx_printer.html Invokes the print setup dialog. ```APIDOC ### Method: Setup #### Signature `virtual bool Setup(wxWindow *parent)` #### Description Invokes the print setup dialog to allow the user to configure printer-specific settings. ``` -------------------------------- ### Install wxWidgets libraries Source: https://docs.wxwidgets.org/3.3/plat_gtk_install.html Execute this command as root to install the library and header files to the system directories. ```bash $ make install ``` -------------------------------- ### wxPrinter::Setup Source: https://docs.wxwidgets.org/3.3/classwx_printer.html The Setup method invokes the print setup dialog, though it is marked as deprecated. ```APIDOC ## virtual bool wxPrinter::Setup(wxWindow * parent) ### Description Invokes the print setup dialog. Note that this method is deprecated and retained only for backward compatibility. ### Parameters - **parent** (wxWindow*) - The parent window for the setup dialog. ### Returns - **bool** - Returns true if the setup was successful. ``` -------------------------------- ### GetAnchor Example Usage Source: https://docs.wxwidgets.org/3.3/classwx_f_s_file.html Examples showing how anchors are parsed from file paths. ```text index.htm#anchor // 'anchor' is anchor index/wx001.htm // NO anchor here! archive/main.zip#zip:index.htm#global // 'global' archive/main.zip#zip:index.htm // NO anchor here! ``` -------------------------------- ### UseScheme() Example Source: https://docs.wxwidgets.org/3.3/classwx_colour_database.html Example of switching the colour database to the traditional scheme during application initialization. ```cpp wxTheColourDatabase->UseScheme(wxColourDatabase::Traditional); ``` -------------------------------- ### Install libwebp using vcpkg Source: https://docs.wxwidgets.org/3.3/page_build_libwebp.html Commands to clone vcpkg, bootstrap the tool, and install libwebp for static x64 Windows builds. ```bash git clone https://github.com/Microsoft/vcpkg.git .\vcpkg\bootstrap-vcpkg.bat .\vcpkg\vcpkg.exe install libwebp:x64-windows-static ``` -------------------------------- ### Basic build and installation commands Source: https://docs.wxwidgets.org/3.3/plat_x11_install.html The standard sequence of commands to configure, build, and install wxWidgets for X11 on Linux. ```bash > ./configure --with-x11 > make > su > make install > ldconfig > exit ``` -------------------------------- ### Initiating a Client Connection Source: https://docs.wxwidgets.org/3.3/overview_ipc.html Demonstrates how to instantiate the custom client, connect to a server, and start an Advise loop. ```cpp wxString server = "4242"; wxString hostName; wxGetHostName(hostName); // Create a new client MyClient *client = new MyClient; connection = (MyConnection *)client->MakeConnection(hostName, server, "IPC TEST"); if (!connection) { wxMessageBox("Failed to make connection to server", "Client Demo Error"); return nullptr; } connection->StartAdvise("Item"); ``` -------------------------------- ### Start(int milli, bool oneShot=false) Source: https://docs.wxwidgets.org/3.3/classwx_timer_runner-members.html Starts the timer associated with the wxTimerRunner. ```APIDOC ## Start(int milli, bool oneShot=false) ### Description Starts the timer associated with this wxTimerRunner instance. ### Parameters - **milli** (int) - Required - The timeout in milliseconds. - **oneShot** (bool) - Optional - Whether the timer should only fire once. ``` -------------------------------- ### Install library to system directories Source: https://docs.wxwidgets.org/3.3/plat_osx_install.html Use sudo to install the library into system directories, requiring administrator privileges. ```bash sudo make install type ``` -------------------------------- ### Install wxWidgets with vcpkg Source: https://docs.wxwidgets.org/3.3/plat_msw_install.html Commands to clone vcpkg, bootstrap the environment, and install wxWidgets for both default and x64-windows targets. ```bash > git clone https://github.com/Microsoft/vcpkg.git > cd vcpkg > bootstrap-vcpkg.bat > vcpkg integrate install > vcpkg install wxwidgets > vcpkg install wxwidgets:x64-windows ``` -------------------------------- ### Build and install wxWidgets with Qt Source: https://docs.wxwidgets.org/3.3/plat_qt_install.html Standard sequence of commands to build and install wxWidgets from the base directory using the Qt port. ```bash > mkdir buildqt > cd buildqt > ../configure --with-qt > make > su > make install > ldconfig ``` -------------------------------- ### Install Library Source: https://docs.wxwidgets.org/3.3/plat_msw_install.html Optionally install the library to a global location, though this is rarely necessary on Windows. ```bash $ make install ``` -------------------------------- ### SetViewer usage examples Source: https://docs.wxwidgets.org/3.3/classwx_help_controller_base.html Examples of setting the help viewer for wxExtHelpController using different browser or help viewer applications. ```cpp m_help.SetViewer("kdehelp"); m_help.SetViewer("gnome-help-browser"); m_help.SetViewer("netscape", wxHELP_NETSCAPE); ``` -------------------------------- ### Install static libraries Source: https://docs.wxwidgets.org/3.3/overview_cmake.html Configures the build for static libraries and installs them to a specified prefix path. ```bash cmake ~/Downloads/wxWidgets_3.1 \ -DCMAKE_INSTALL_PREFIX=~/wx_install \ -DwxBUILD_SHARED=OFF cmake --build . --target install ``` -------------------------------- ### SetItemLabel usage examples Source: https://docs.wxwidgets.org/3.3/classwx_menu_item.html Examples demonstrating how to set labels with accelerators, escaped ampersands, and simple text. ```cpp m_pMyMenuItem->SetItemLabel("My &item\tCTRL+I"); m_pMyMenuItem2->SetItemLabel("Clean && build\tF7"); m_pMyMenuItem3->SetItemLabel("Simple item"); m_pMyMenuItem4->SetItemLabel("Item with &accelerator"); ``` -------------------------------- ### GetLocation Example Usage Source: https://docs.wxwidgets.org/3.3/classwx_f_s_file.html Examples showing various formats of file locations returned by GetLocation. ```text http://www.wxwidgets.org http://www.ms.mff.cuni.cz/~vsla8348/wxhtml/archive.zip#zip:info.txt file:/home/vasek/index.htm relative-file.htm ``` -------------------------------- ### Install wxWidgets System-wide Source: https://docs.wxwidgets.org/3.3/plat_gtk_install.html Install the compiled libraries to the system and update the linker cache. If ldconfig is not found, use /sbin/ldconfig. ```bash $ sudo make install $ sudo ldconfig ``` -------------------------------- ### Install liblzma using vcpkg Source: https://docs.wxwidgets.org/3.3/page_build_liblzma.html Commands to bootstrap vcpkg and install liblzma for both x86 and x64 architectures on Windows. ```bash > git clone https://github.com/Microsoft/vcpkg.git > cd vcpkg > .\bootstrap-vcpkg.bat > .\vcpkg integrate install > .\vcpkg install liblzma > .\vcpkg install liblzma:x64-windows ``` -------------------------------- ### Iterate over an ID range Source: https://docs.wxwidgets.org/3.3/overview_xrcformat.html Example of using [start] and [end] to iterate through an ID range in C++. ```cpp for (int n=XRCID("foo[start]"); n <= XRCID("foo[end]"); ++n) ... ``` -------------------------------- ### Configure with non-default liblzma path Source: https://docs.wxwidgets.org/3.3/page_build_liblzma.html Example of passing CPPFLAGS and LDFLAGS to configure when liblzma is installed in a non-standard location. ```bash $ ../configure --with-liblzma CPPFLAGS=-I/opt/liblzma/include LDFLAGS=-L/opt/liblzma/lib ``` -------------------------------- ### wxPropertyGridManager XRC Example Source: https://docs.wxwidgets.org/3.3/overview_xrcformat.html An example of defining a wxPropertyGridManager with multiple pages and properties in XRC. ```xml Now And Then 2023 "1" "2" "3" "4" "5" 87 4 @stars ``` -------------------------------- ### Using CallForEachChild for recursive window translation Source: https://docs.wxwidgets.org/3.3/classwx_window.html Example of using CallForEachChild to recursively traverse children and update labels starting with 'Hello ' to 'Bonjour '. ```cpp void MyFrame::OnTranslate(wxCommandEvent&) { CallForEachChild([](wxWindow* win) { wxString rest; if ( win->GetLabel().StartsWith("Hello ", &rest) ) win->SetLabel("Bonjour " + rest); }); } ``` -------------------------------- ### Displaying a startup tip Source: https://docs.wxwidgets.org/3.3/overview_tips.html Use wxCreateFileTipProvider to load tips from a file and wxShowTip to display them to the user. ```cpp if ( ...show tips at startup?... ) { wxTipProvider *tipProvider = wxCreateFileTipProvider("tips.txt", 0); wxShowTip(windowParent, tipProvider); delete tipProvider; } ``` -------------------------------- ### Install Required Packages Source: https://docs.wxwidgets.org/3.3/plat_msw_msys2.html Install essential dependencies using pacman in the MSys2 environment. ```bash pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-gcc-libs pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-expat pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-xz pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-zlib ``` -------------------------------- ### Complete Hello World Program Source: https://docs.wxwidgets.org/3.3/overview_helloworld.html A full, copy-pasteable example of a wxWidgets application including the app class, frame class, and event handlers. ```cpp // Start of wxWidgets "Hello World" Program #include class MyApp : public wxApp { public: bool OnInit() override; }; wxIMPLEMENT_APP(MyApp); class MyFrame : public wxFrame { public: MyFrame(); private: void OnHello(wxCommandEvent& event); void OnExit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); }; enum { ID_Hello = 1 }; bool MyApp::OnInit() { MyFrame *frame = new MyFrame(); frame->Show(true); return true; } MyFrame::MyFrame() : wxFrame(nullptr, wxID_ANY, "Hello World") { wxMenu *menuFile = new wxMenu; menuFile->Append(ID_Hello, "&Hello...\tCtrl-H", "Help string shown in status bar for this menu item"); menuFile->AppendSeparator(); menuFile->Append(wxID_EXIT); wxMenu *menuHelp = new wxMenu; menuHelp->Append(wxID_ABOUT); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); menuBar->Append(menuHelp, "&Help"); SetMenuBar( menuBar ); CreateStatusBar(); SetStatusText("Welcome to wxWidgets!"); Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello); Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT); Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT); } void MyFrame::OnExit(wxCommandEvent& event) { Close(true); } void MyFrame::OnAbout(wxCommandEvent& event) { wxMessageBox("This is a wxWidgets Hello World example", "About Hello World", wxOK | wxICON_INFORMATION); } void MyFrame::OnHello(wxCommandEvent& event) { wxLogMessage("Hello world from wxWidgets!"); } ``` -------------------------------- ### Enumerate lines from end to beginning using GetLastLine and GetPrevLine Source: https://docs.wxwidgets.org/3.3/classwx_text_file.html This example demonstrates how to iterate through a file in reverse order by starting with GetLastLine and using GetPrevLine in a loop. ```cpp wxTextFile file; ... for ( str = file.GetLastLine(); file.GetCurrentLine() > 0; str = file.GetPrevLine() ) { // do something with the current line in str } // do something with the first line in str ``` -------------------------------- ### Build and Run Widgets Sample Source: https://docs.wxwidgets.org/3.3/plat_msw_msys2.html Build and execute the widgets static sample. ```bash cd build-${MSYSTEM_CARCH}-msw-static/samples/widgets && make && cd ../../.. cd samples/widgets && ../../build-${MSYSTEM_CARCH}-msw-static/samples/widgets/widgets.exe && cd ../.. ``` -------------------------------- ### Start(long milliseconds=0) Source: https://docs.wxwidgets.org/3.3/classwx_stop_watch-members.html Starts the stopwatch. ```APIDOC ## Start(long milliseconds=0) ### Description Starts the stopwatch, optionally setting an initial time value. ``` -------------------------------- ### wxExtHelpController::Initialize Source: https://docs.wxwidgets.org/3.3/classwx_ext_help_controller.html Initializes the help controller with the directory containing the documentation. ```APIDOC ## bool Initialize(const wxString &dir) ### Description Sets the base directory where the help documentation files are located. This must be called before loading files. ### Parameters - **dir** (wxString) - The path to the documentation directory. ### Returns - **bool** - Returns true if initialization was successful. ``` -------------------------------- ### Build and Run Minimal Sample Source: https://docs.wxwidgets.org/3.3/plat_msw_msys2.html Clean, build, and execute the minimal static sample. ```bash cd build-${MSYSTEM_CARCH}-msw-static/samples/minimal && make clean && cd ../../.. cd build-${MSYSTEM_CARCH}-msw-static/samples/minimal && make && cd ../../.. ./build-${MSYSTEM_CARCH}-msw-static/samples/minimal/minimal.exe ``` -------------------------------- ### Start Source: https://docs.wxwidgets.org/3.3/classwx_timer.html Starts or restarts the timer with a specified interval and mode. ```APIDOC ## virtual bool wxTimer::Start(int milliseconds = -1, bool oneShot = wxTIMER_CONTINUOUS) ### Description (Re)starts the timer. If milliseconds is -1, the previous value is used. If oneShot is false, the timer runs continuously; if true, it runs once. ``` -------------------------------- ### Build wxQT on Ubuntu Source: https://docs.wxwidgets.org/3.3/plat_qt_install.html Commands to create a build directory, configure with Qt support, and compile the library and samples. ```bash mkdir bldqt5 cd bldqt5 ../configure --with-qt --enable-debug make make samples ``` -------------------------------- ### SetStart(long start) Source: https://docs.wxwidgets.org/3.3/classwx_rich_text_range.html Sets the start position of the range. ```APIDOC ### void SetStart(long start) Sets the start position of the range. ``` -------------------------------- ### Build all samples and demos Source: https://docs.wxwidgets.org/3.3/plat_osx_install.html Build the complete suite of samples and demos provided with the library. ```bash cd samples; make;cd .. cd demos; make;cd .. ``` -------------------------------- ### Size and Position Examples Source: https://docs.wxwidgets.org/3.3/overview_xrcformat.html Examples of size and position definitions using pixel values and dialog units. ```text 42,-1 100,100 100,50d ``` -------------------------------- ### Get Source: https://docs.wxwidgets.org/3.3/classwx_xml_resource.html Gets the global resources object or creates one if none exists. ```APIDOC ### static wxXmlResource* Get() Gets the global resources object or creates one if none exists. ``` -------------------------------- ### wxShowTip() Source: https://docs.wxwidgets.org/3.3/group__group__funcmacro__dialog.html Displays a startup tip dialog to the user and returns the state of the 'Show tips at startup' checkbox. ```APIDOC ## wxShowTip() ### Description This function shows a "startup tip" to the user. The return value is the state of the "Show tips at startup" checkbox. ### Signature bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup = true) ### Parameters - **parent** (wxWindow*) - The parent window for the modal dialog. - **tipProvider** (wxTipProvider*) - An object which is used to get the text of the tips. - **showAtStartup** (bool) - Initial value for the "Show tips at startup" checkbox. ### Include #include ``` -------------------------------- ### XRC Sizer Structure Example Source: https://docs.wxwidgets.org/3.3/overview_xrcformat.html An example demonstrating a wxFlexGridSizer containing a button and a nested wxBoxSizer with a checkbox and text control within a wxDialog. ```xml Derived Dialog Example 1 1 0 0 0 0:1 0:1 wxALIGN_CENTRE|wxALL 5 wxALIGN_CENTRE|wxALL 5 wxHORIZONTAL wxALIGN_CENTRE|wxALL 5 wxALIGN_CENTRE|wxALL 5 80,-1 ... ``` -------------------------------- ### Constructing wxContextHelp Source: https://docs.wxwidgets.org/3.3/classwx_context_help.html Example of initializing a context help object for a specific window. ```cpp wxContextHelp contextHelp(myWindow); ``` -------------------------------- ### Building with MinGW Source: https://docs.wxwidgets.org/3.3/plat_msw_gtk.html Environment setup and mingw32-make command to build wxWidgets with GTK+ toolkit version 2. ```batch set CXXFLAGS=%CXXFLAGS% -IC:\gtk\include\gtk-2.0 set CXXFLAGS=%CXXFLAGS% -IC:\gtk\include\glib-2.0 set CXXFLAGS=%CXXFLAGS% -IC:\gtk\include\cairo set CXXFLAGS=%CXXFLAGS% -IC:\gtk\include\pango-1.0 set CXXFLAGS=%CXXFLAGS% -IC:\gtk\include\gdk-pixbuf-2.0 set CXXFLAGS=%CXXFLAGS% -IC:\gtk\include\atk-1.0 set CXXFLAGS=%CXXFLAGS% -IC:\gtk\lib\glib-2.0\include set CXXFLAGS=%CXXFLAGS% -IC:\gtk\lib\gtk-2.0\include set CFLAGS=%CXXFLAGS% set LDFLAGS=%LDFLAGS% -LC:\gtk\lib set PATH=C:\gtk\bin\;%PATH%; mingw32-make -f makefile.gcc "TOOLKIT=GTK" "TOOLKIT_VERSION=2" ``` -------------------------------- ### Verify Build with Minimal Sample Source: https://docs.wxwidgets.org/3.3/plat_gtk_install.html Build the minimal sample application to verify that the library was compiled correctly. ```bash $ cd samples/minimal $ make ``` -------------------------------- ### Example usage of wxDECLARE_ABSTRACT_CLASS Source: https://docs.wxwidgets.org/3.3/group__group__funcmacro__rtti.html Example of using wxDECLARE_ABSTRACT_CLASS inside a class declaration. ```cpp class wxCommand: public wxObject { wxDECLARE_ABSTRACT_CLASS(wxCommand); private: ... public: ... }; ``` -------------------------------- ### SetToolBitmapSize usage example Source: https://docs.wxwidgets.org/3.3/classwx_tool_bar.html Example showing how to force toolbar bitmaps to a specific size using FromDIP before calling Realize. ```cpp toolbar->SetToolBitmapSize(FromDIP(wxSize(32, 32))); toolbar->AddTool(wxID_NEW, "New", wxBitmapBundle::FromXXX(...)); ... toolbar->Realize(); ``` -------------------------------- ### Building with nmake Source: https://docs.wxwidgets.org/3.3/plat_msw_gtk.html Environment setup and nmake command to build wxWidgets with GTK+ toolkit version 2. ```batch set INCLUDE=C:\gtk\lib\glib-2.0\include\;C:\gtk\lib\gtk-2.0\include\;C:\gtk\include\cairo\;C:\gtk\include\pango-1.0\;C:\gtk\include\gtk-2.0\;C:\gtk\include\glib-2.0\;C:\gtk\include\gdk-pixbuf-2.0\;C:\gtk\include\atk-1.0\; set LIB=C:\gtk\lib\; set PATH=C:\gtk\bin\;%PATH%; nmake -f makefile.vc "TOOLKIT=GTK" "TOOLKIT_VERSION=2" ``` -------------------------------- ### Run toolbar static sample Source: https://docs.wxwidgets.org/3.3/plat_msw_msys2_qt.html Execute the toolbar sample. ```bash cd samples/toolbar && ../../build-${MSYSTEM_CARCH}-qt-static/samples/toolbar/toolbar.exe && cd ../.. ``` -------------------------------- ### SetRange(long start, long end) Source: https://docs.wxwidgets.org/3.3/classwx_rich_text_range.html Sets both the start and end positions of the range. ```APIDOC ### void SetRange(long start, long end) Sets the range start and end positions. ``` -------------------------------- ### Run widgets sample Source: https://docs.wxwidgets.org/3.3/plat_msw_msys2_gtk.html Run the widgets sample. ```bash cd samples/widgets && ../../build-${MSYSTEM_CARCH}-gtk3-static/samples/widgets/widgets.exe && cd ../.. ``` -------------------------------- ### Run toolbar sample Source: https://docs.wxwidgets.org/3.3/plat_msw_msys2_gtk.html Run the toolbar sample. ```bash cd samples/toolbar && ../../build-${MSYSTEM_CARCH}-gtk3-static/samples/toolbar/toolbar.exe && cd ../.. ``` -------------------------------- ### SetManagerFlags Example Source: https://docs.wxwidgets.org/3.3/classwx_aui_notebook.html Example of using SetManagerFlags to enable the Venetian blinds effect for the notebook. ```cpp auiNotebook->SetManagerFlags( wxAuiManager::GetManager()->GetFlags() | ~wxAUI_MGR_VENETIAN_BLINDS_HINT ); ``` -------------------------------- ### Constructing and Configuring wxMenuItem Source: https://docs.wxwidgets.org/3.3/classwx_menu_item.html Examples showing how to append stock menu items to a menu, override help strings, and manually create a menu item with a custom bitmap. ```cpp // use all stock properties: helpMenu->Append(wxID_ABOUT); // use the stock label and the stock accelerator but not the stock help string: helpMenu->Append(wxID_ABOUT, "", "My custom help string"); // use all stock properties except for the bitmap: wxMenuItem *mymenu = new wxMenuItem(helpMenu, wxID_ABOUT); mymenu->SetBitmap(wxArtProvider::GetBitmap(wxART_WARNING)); helpMenu->Append(mymenu); ``` -------------------------------- ### Install development packages on Debian-based systems Source: https://docs.wxwidgets.org/3.3/overview_install.html Command to install the necessary development libraries for wxWidgets on Debian or Ubuntu systems. ```bash apt get libwxgtkX.Y-dev ``` -------------------------------- ### Create() Source: https://docs.wxwidgets.org/3.3/classwx_html_help_window.html Initializes the help window after construction. ```APIDOC ## bool Create(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, int style = wxTAB_TRAVERSAL|wxBORDER_NONE, int helpStyle = wxHF_DEFAULT_STYLE) ### Description Creates the help window. Parameters are identical to the constructor. ``` -------------------------------- ### Post-installation build commands Source: https://docs.wxwidgets.org/3.3/plat_x11_install.html Commands to continue building samples or additional components after the initial installation. ```bash > make > su > make install > ldconfig > exit ``` -------------------------------- ### WX_DECLARE_OBJARRAY Macro Example Source: https://docs.wxwidgets.org/3.3/dynarray_8h.html Example usage of the WX_DECLARE_OBJARRAY macro to declare an object array class. ```cpp class MyClass; WX_DECLARE_OBJARRAY(MyClass, wxArrayOfMyClass); // note: not "MyClass *"! ``` -------------------------------- ### BeginContextHelp(wxWindow *window) Source: https://docs.wxwidgets.org/3.3/classwx_context_help-members.html Starts the context-sensitive help mode for the specified window. ```APIDOC ### BeginContextHelp(wxWindow *window) Enters the context-sensitive help mode for the given window. ``` -------------------------------- ### wxToolBar XRC Configuration Example Source: https://docs.wxwidgets.org/3.3/overview_xrcformat.html An example of an XRC-defined wxToolBar containing tools, a separator, a dropdown menu, a stretchable space, and a wxComboBox. ```xml foo.png bar.png view.png Just a combobox in the toolbar ``` -------------------------------- ### Download a file using wxFTP Source: https://docs.wxwidgets.org/3.3/classwx_f_t_p.html This example demonstrates how to connect to an FTP server, navigate to a directory, and download a file into a buffer using an input stream. ```cpp wxFTP ftp; // if you don't use these lines anonymous login will be used ftp.SetUser("user"); ftp.SetPassword("password"); if ( !ftp.Connect("ftp.wxwidgets.org") ) { wxLogError("Couldn't connect"); return; } ftp.ChDir("/pub/2.8.9"); const char *filename = "wxWidgets-2.8.9.tar.bz2"; int size = ftp.GetFileSize(filename); if ( size == -1 ) { wxLogError("Couldn't get the file size for \"%s\"", filename); } wxInputStream *in = ftp.GetInputStream(filename); if ( !in ) { wxLogError("Couldn't get the file"); } else { char *data = new char[size]; if ( !in->Read(data, size) ) { wxLogError("Read error: %d", ftp.GetError()); } else { // file data is in the buffer ... } delete [] data; delete in; } // gracefully close the connection to the server ftp.Close(); ``` -------------------------------- ### SetUmask usage example Source: https://docs.wxwidgets.org/3.3/classwx_file_config.html Example of using SetUmask to create a configuration file that is not readable by other users. ```cpp SetUmask(0077) ``` -------------------------------- ### Display configure help Source: https://docs.wxwidgets.org/3.3/plat_qt_install.html Command to list all available configuration options. ```bash ./configure --help ``` -------------------------------- ### Minimal Makefile Example Source: https://docs.wxwidgets.org/3.3/plat_x11_install.html A sample Makefile for a minimal project using wx-config for build flags. ```makefile CXX = g++ minimal: minimal.o $(CXX) -o minimal minimal.o `wx-config --libs` minimal.o: minimal.cpp $(CXX) `wx-config --cxxflags` -c minimal.cpp -o minimal.o clean: rm -f *.o minimal ``` -------------------------------- ### Install required MSys2 MinGW packages Source: https://docs.wxwidgets.org/3.3/plat_msw_msys2_qt.html Use these commands in the MSys2 MinGW prompt to install the necessary build tools and dependencies for wxQT/Win32. ```bash pacman -S --needed --noconfirm make pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-libjpeg-turbo pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-libpng pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-libtiff pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-gcc pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-pkg-config pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-qt5 ``` -------------------------------- ### Using wxMetafile with wxMetafileDC and Clipboard Source: https://docs.wxwidgets.org/3.3/classwx_metafile.html Example demonstrating how to create a metafile using wxMetafileDC, draw to it, and then pass the resulting metafile to the clipboard using the device context's maximum extent dimensions. ```cpp wxMetafileDC dc; if (dc.IsOk()) { Draw(dc, false); wxMetafile *mf = dc.Close(); if (mf) { bool success = mf->SetClipboard((int)(dc.MaxX() + 10), (int)(dc.MaxY() + 10)); delete mf; } } ``` -------------------------------- ### XRC Show Effect Example Source: https://docs.wxwidgets.org/3.3/overview_xrcformat.html Example of specifying a show effect using the wxShowEffect enumeration. ```xml wxSHOW_EFFECT_EXPAND ``` -------------------------------- ### Implement Application Initialization Source: https://docs.wxwidgets.org/3.3/overview_helloworld.html Implement the OnInit method to create and show the main application window. ```cpp bool MyApp::OnInit() { MyFrame *frame = new MyFrame(); frame->Show(); return true; } ``` -------------------------------- ### Creating and populating a wxPropertyGridManager Source: https://docs.wxwidgets.org/3.3/classwx_property_grid_manager.html Example demonstrating the initialization of a wxPropertyGridManager with specific styles and the addition of properties to multiple pages. ```cpp wxPropertyGridManager* pgMan = new wxPropertyGridManager(this, PGID, wxDefaultPosition, wxDefaultSize, // These and other similar styles are automatically // passed to the embedded wxPropertyGrid. wxPG_BOLD_MODIFIED|wxPG_SPLITTER_AUTO_CENTER| // Include toolbar. wxPG_TOOLBAR | // Include description box. wxPG_DESCRIPTION | // Include compactor. wxPG_COMPACTOR | // Plus defaults. wxPGMAN_DEFAULT_STYLE ); wxPropertyGridPage* page; page = pgMan->AddPage("First Page"); page->Append( new wxPropertyCategory("Category A1") ); page->Append( new wxIntProperty("Number",wxPG_LABEL,1) ); page->Append( new wxColourProperty("Colour",wxPG_LABEL,*wxWHITE) ); page = pgMan->AddPage("Second Page"); page->Append( "Text",wxPG_LABEL,"(no text)" ); page->Append( new wxFontProperty("Font",wxPG_LABEL) ); // Display a header above the grid pgMan->ShowHeader(); ``` -------------------------------- ### ReplaceProperty usage example Source: https://docs.wxwidgets.org/3.3/classwx_property_grid_interface.html Example demonstrating how to replace an existing property named 'Flags' with a new wxFlagsProperty. ```cpp pg->ReplaceProperty("Flags", wxFlagsProperty("Flags", wxPG_LABEL, newItems)) ``` -------------------------------- ### Build and Run Drawing Sample Source: https://docs.wxwidgets.org/3.3/plat_msw_msys2.html Build and execute the drawing static sample. ```bash cd build-${MSYSTEM_CARCH}-msw-static/samples/drawing && make && cd ../../.. cd samples/drawing && ../../build-${MSYSTEM_CARCH}-msw-static/samples/drawing/drawing.exe && cd ../.. ``` -------------------------------- ### SetComponentLevel Example Source: https://docs.wxwidgets.org/3.3/classwx_log.html Example showing how to disable all but error messages from wxWidgets network classes using SetComponentLevel. ```cpp wxLog::SetComponentLevel("wx/net", wxLOG_Error); ``` -------------------------------- ### Build minimal sample Source: https://docs.wxwidgets.org/3.3/plat_msw_msys2_qt.html Compile the minimal sample application. ```bash cd build-${MSYSTEM_CARCH}-qt-static/samples/minimal && make && cd ../../.. ``` -------------------------------- ### Loading XRC Files in MyApp::OnInit Source: https://docs.wxwidgets.org/3.3/overview_xrc.html Demonstrates how to initialize resource handlers and load XRC files from the current directory and a subdirectory. ```cpp #include "wx/xrc/xmlres.h" bool MyApp::OnInit() { ... wxXmlResource::Get()->InitAllHandlers(); wxXmlResource::Get()->Load("resource.xrc"); wxXmlResource::Get()->LoadAllFiles("rc"); ... } ``` -------------------------------- ### CreateEditorCtrl implementation example Source: https://docs.wxwidgets.org/3.3/classwx_data_view_custom_renderer.html An example showing how to return a wxSpinCtrl as an editor control within the CreateEditorCtrl method. ```cpp { long l = value; return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString, labelRect.GetTopLeft(), labelRect.GetSize(), 0, 0, 100, l ); } ``` -------------------------------- ### Build and Run Splash Sample Source: https://docs.wxwidgets.org/3.3/plat_msw_msys2.html Build and execute the splash static sample. ```bash cd build-${MSYSTEM_CARCH}-msw-static/samples/splash && make && cd ../../.. cd samples/splash && ../../build-${MSYSTEM_CARCH}-msw-static/samples/splash/splash.exe && cd ../.. ``` -------------------------------- ### Initialize(const wxString &dir) Source: https://docs.wxwidgets.org/3.3/classwx_ext_help_controller.html Initializes the controller with the directory path where help files are located. ```APIDOC ## Initialize ### Description This must be called to tell the controller where to find the documentation. If a locale is set, it attempts to look in subdirectories matching the locale. ### Signature `virtual bool Initialize(const wxString &dir)` ### Parameters - **dir** (const wxString &) - Directory name where to find the help files. ### Returns - **bool** - true on success. ``` -------------------------------- ### Usage of wxMessageBox Source: https://docs.wxwidgets.org/3.3/group__group__funcmacro__dialog.html Example showing how to display a message box and handle the user's response. ```cpp int answer = wxMessageBox("Quit program?", "Confirm", wxYES_NO | wxCANCEL, main_frame); if (answer == wxYES) main_frame->Close(); ``` -------------------------------- ### Navigating wxConfigBase Paths Source: https://docs.wxwidgets.org/3.3/classwx_config_base.html Demonstrates how to use absolute and relative paths to read and write configuration entries. ```cpp wxConfig *config = new wxConfig("FooBarApp"); // right now the current path is '/' conf->Write("RootEntry", 1); // go to some other place: if the group(s) don't exist, they will be created conf->SetPath("/Group/Subgroup"); // create an entry in subgroup conf->Write("SubgroupEntry", 3); // '..' is understood conf->Write("../GroupEntry", 2); conf->SetPath(".."); wxASSERT( conf->ReadLong("Subgroup/SubgroupEntry", 0) == 3 ); // use absolute path: it is allowed, too wxASSERT( conf->ReadLong("/RootEntry", 0) == 1 ); ``` -------------------------------- ### Create and initialize a wxSplitterWindow Source: https://docs.wxwidgets.org/3.3/overview_splitterwindow.html Demonstrates how to instantiate a splitter window, add two subwindows, and initialize the layout with one window hidden. ```cpp splitter = new wxSplitterWindow(this, -1, wxPoint(0, 0), wxSize(400, 400), wxSP_3D); leftWindow = new MyWindow(splitter); leftWindow->SetScrollbars(20, 20, 50, 50); rightWindow = new MyWindow(splitter); rightWindow->SetScrollbars(20, 20, 50, 50); rightWindow->Show(false); splitter->Initialize(leftWindow); // Set this to prevent unsplitting // splitter->SetMinimumPaneSize(20); ``` -------------------------------- ### XRC Font Property Examples Source: https://docs.wxwidgets.org/3.3/overview_xrcformat.html Examples of defining fonts using elementary properties or by deriving from system fonts. ```xml arial,helvetica 12 ``` ```xml wxSYS_DEFAULT_GUI_FONT bold 1.5 ``` -------------------------------- ### wxHelpController::Initialize Source: https://docs.wxwidgets.org/3.3/classwx_help_controller.html Initializes the help instance with a specific help filename. ```APIDOC ## Initialize ### Description Initializes the help instance with a help filename. ### Parameters - **file** (const wxString &) - Required - The filename of the help file to load. ``` -------------------------------- ### XRC Style Property Examples Source: https://docs.wxwidgets.org/3.3/overview_xrcformat.html Examples of defining window styles and extended styles using OR-combined flags. ```xml ``` ```xml wxDIALOG_EX_CONTEXTHELP ``` -------------------------------- ### Initialize Source: https://docs.wxwidgets.org/3.3/classwx_help_controller_base.html Initializes the help instance with a specific help filename. ```APIDOC ## Initialize(const wxString &file) ### Description Initializes the help instance with a help filename. This must be called directly after the help instance object is created and before any attempts to communicate with the viewer. ### Parameters - **file** (const wxString &) - The help filename to initialize with. ``` -------------------------------- ### SetScrollbar usage example Source: https://docs.wxwidgets.org/3.3/classwx_scroll_bar.html Example of configuring a scrollbar to display 50 lines of text with 16 lines visible at a time. ```cpp scrollbar->SetScrollbar(0, 16, 50, 15); ``` -------------------------------- ### wxShowTip Source: https://docs.wxwidgets.org/3.3/tipdlg_8h.html Displays a startup tip dialog to the user. ```APIDOC ## wxShowTip ### Description This function shows a "startup tip" to the user. ### Parameters - **parent** (wxWindow *) - The parent window for the tip dialog. - **tipProvider** (wxTipProvider *) - The provider instance containing the tips. - **showAtStartup** (bool) - Whether to show the tip at startup (default: true). ``` -------------------------------- ### wxModule::OnInit Source: https://docs.wxwidgets.org/3.3/classwx_module.html Initializes the module. This method must be overridden by the user to perform necessary setup tasks. ```APIDOC ## virtual bool OnInit() ### Description Provide this function with appropriate initialization for your module. ### Returns - **bool** - Returns true if initialization was successful, false otherwise. ``` -------------------------------- ### GetDirList Windows output example Source: https://docs.wxwidgets.org/3.3/classwx_f_t_p.html Example of the directory listing format returned by GetDirList when connected to a Windows peer system. ```text winamp~1 exe 520196 02-25-1999 19:28 winamp204.exe 1 file(s) 520 196 bytes ``` -------------------------------- ### Configure wxQT with Custom Qt Dir on Linux Source: https://docs.wxwidgets.org/3.3/plat_qt_install.html Configure command specifying a custom Qt installation directory for Linux. ```bash ../configure --with-qt --enable-debug QT5_CUSTOM_DIR=~/Qt/5.11.0/gcc_64 ``` -------------------------------- ### GetDirList UNIX output example Source: https://docs.wxwidgets.org/3.3/classwx_f_t_p.html Example of the directory listing format returned by GetDirList when connected to a UNIX peer system. ```text -r--r--r-- 1 guilhem lavaux 12738 Jan 16 20:17 cmndata.cpp -r--r--r-- 1 guilhem lavaux 10866 Jan 24 16:41 config.cpp -rw-rw-rw- 1 guilhem lavaux 29967 Dec 21 19:17 cwlex_yy.c -rw-rw-rw- 1 guilhem lavaux 14342 Jan 22 19:51 cwy_tab.c -r--r--r-- 1 guilhem lavaux 13890 Jan 29 19:18 date.cpp -r--r--r-- 1 guilhem lavaux 3989 Feb 8 19:18 datstrm.cpp ``` -------------------------------- ### wxDir::GetFirst Source: https://docs.wxwidgets.org/3.3/classwx_dir.html Starts the enumeration of files in the directory. ```APIDOC ## bool GetFirst(wxString *filename, const wxString &filespec=wxEmptyString, int flags=wxDIR_DEFAULT) const ### Description Starts enumerating all files matching the filespec and flags. Returns true on success. ### Parameters - **filename** (wxString *) - Required - Pointer to a string to store the found filename. - **filespec** (const wxString &) - Optional - Pattern to match files against. - **flags** (int) - Optional - Flags to control the enumeration (e.g., files, directories). ``` -------------------------------- ### Create and Configure a wxGrid Source: https://docs.wxwidgets.org/3.3/overview_grid.html Demonstrates how to instantiate a wxGrid, define its size, adjust row and column dimensions, and apply various cell formatting and data type settings. ```cpp // Create a wxGrid object grid = new wxGrid( this, -1, wxPoint( 0, 0 ), wxSize( 400, 300 ) ); // Then we call CreateGrid to set the dimensions of the grid // (100 rows and 10 columns in this example) grid->CreateGrid( 100, 10 ); // We can set the sizes of individual rows and columns // in pixels grid->SetRowSize( 0, 60 ); grid->SetColSize( 0, 120 ); // And set grid cell contents as strings grid->SetCellValue( 0, 0, "wxGrid is good" ); // We can specify that some cells are read->only grid->SetCellValue( 0, 3, "This is read->only" ); grid->SetReadOnly( 0, 3 ); // Colours can be specified for grid cell contents grid->SetCellValue(3, 3, "green on grey"); grid->SetCellTextColour(3, 3, *wxGREEN); grid->SetCellBackgroundColour(3, 3, *wxLIGHT_GREY); // We can specify the some cells will store numeric // values rather than strings. Here we set grid column 5 // to hold floating point values displayed with width of 6 // and precision of 2 grid->SetColFormatFloat(5, 6, 2); grid->SetCellValue(0, 6, "3.1415"); ``` -------------------------------- ### Create an embedded HTML help window Source: https://docs.wxwidgets.org/3.3/classwx_html_help_window.html Example showing how to initialize and configure a wxHtmlHelpWindow for embedding within a parent window. ```cpp // m_embeddedHelpWindow is a wxHtmlHelpWindow // m_embeddedHtmlHelp is a wxHtmlHelpController // Create embedded HTML Help window m_embeddedHelpWindow = new wxHtmlHelpWindow; m_embeddedHtmlHelp.UseConfig(config, rootPath); // Set your own config object here m_embeddedHtmlHelp.SetHelpWindow(m_embeddedHelpWindow); m_embeddedHelpWindow->Create(this, wxID_ANY, wxDefaultPosition, GetClientSize(), wxTAB_TRAVERSAL|wxBORDER_NONE, wxHF_DEFAULT_STYLE); m_embeddedHtmlHelp.AddBook(wxFileName("doc.zip")); ``` -------------------------------- ### wxConfigPathChanger path change example Source: https://docs.wxwidgets.org/3.3/classwx_config_path_changer.html Shows an alternative way to initialize the path changer using a directory-style path. ```cpp wxConfigPathChanger(wxConfigBase::Get(), "/MyProgram/"); ``` -------------------------------- ### Start(const wxString &prefix) Source: https://docs.wxwidgets.org/3.3/classwx_text_completer.html Initializes the iteration process for completions matching the provided prefix. ```APIDOC ## virtual bool Start(const wxString &prefix) ### Description Called to start iteration over the completions for the given prefix. ### Parameters - **prefix** (const wxString &) - Required - The prefix string to find completions for. ### Returns - **bool** - Returns true if completions are available, false otherwise. ``` -------------------------------- ### Install MSys2 MinGW build dependencies Source: https://docs.wxwidgets.org/3.3/plat_msw_msys2_gtk.html Run these commands in the MSys2 MinGW prompt to install the required packages for building wxGTK/Win32. ```bash pacman -S --needed --noconfirm make pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-libjpeg-turbo pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-libpng pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-libtiff pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-gcc pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-pkg-config ## gtk3 can take a long time to update/find fonts pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-gtk3 ``` -------------------------------- ### XML Document Structure Example Source: https://docs.wxwidgets.org/3.3/classwx_xml_document.html An example of the XML document structure produced by the library, including a root element and nested library information. ```xml wxWidgets ``` -------------------------------- ### GetProtocol Example Source: https://docs.wxwidgets.org/3.3/classwx_file_system_handler.html Demonstrates extracting the protocol string from a file system location. ```cpp GetProtocol("file:myzipfile.zip#zip:index.htm") == "zip" ``` -------------------------------- ### SetNotify Example Source: https://docs.wxwidgets.org/3.3/classwx_socket_base.html Configures a socket to receive specific events and enables notification. In this example, the user is notified about incoming data and connection loss. ```cpp sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG); sock.Notify(true); ``` -------------------------------- ### Declaring and Using wxList Source: https://docs.wxwidgets.org/3.3/classwx_list_3_01_t_01_4.html Example showing how to declare a list using WX_DECLARE_LIST and WX_DEFINE_LIST, and how to iterate using both STL-style and legacy API syntax. ```cpp // this part might be in a header or source (.cpp) file class MyListElement { ... // whatever }; // this macro declares and partly implements MyList class WX_DECLARE_LIST(MyListElement, MyList); ... // the only requirement for the rest is to be AFTER the full declaration of // MyListElement (for WX_DECLARE_LIST forward declaration is enough), but // usually it will be found in the source file and not in the header #include WX_DEFINE_LIST(MyList); MyList list; MyListElement element; list.Append(&element); // ok list.Append(17); // error: incorrect type // let's iterate over the list in STL syntax MyList::iterator iter; for (iter = list.begin(); iter != list.end(); ++iter) { MyListElement *current = *iter; ...process the current element... } // the same with the legacy API from the old wxList class MyList::compatibility_iterator node = list.GetFirst(); while (node) { MyListElement *current = node->GetData(); ...process the current element... node = node->GetNext(); } ``` -------------------------------- ### Using wxFontDialog to select and apply font and color Source: https://docs.wxwidgets.org/3.3/overview_cmndlg.html This example demonstrates initializing a font dialog with existing data, displaying it, and updating application state with the user's selection. ```cpp wxFontData data; data.SetInitialFont(canvasFont); data.SetColour(canvasTextColour); wxFontDialog dialog(this, &data); if (dialog.ShowModal() == wxID_OK) { wxFontData retData = dialog.GetFontData(); canvasFont = retData.GetChosenFont(); canvasTextColour = retData.GetColour(); myWindow->Refresh(); } ``` -------------------------------- ### Install MinGW build dependencies via pacman Source: https://docs.wxwidgets.org/3.3/plat_msw_msys2.html Run these commands from the MSys2 MinGW prompt to install the required tools and libraries for building wxMSW. ```bash pacman -S --needed --noconfirm make pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-libjpeg-turbo pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-libpng pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-libtiff pacman -S --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-gcc ``` -------------------------------- ### Initialize wxVersionInfo for a library Source: https://docs.wxwidgets.org/3.3/classwx_version_info.html Example showing how to instantiate a wxVersionInfo object to store version details for an external library like Lua. ```cpp wxVersionInfo luaLibInfo{ "Lua", LUA_VERSION_MAJOR_N, LUA_VERSION_MINOR_N, LUA_VERSION_RELEASE_N, 0, wxString{}, LUA_COPYRIGHT }; // GetName(), GetCopyright(), GetNumericVersionString(), etc. can be called // from the luaLibInfo object. ``` -------------------------------- ### Initializing wxMemoryFSHandler Source: https://docs.wxwidgets.org/3.3/overview_fs.html Example of adding the wxMemoryFSHandler to the wxFileSystem during application initialization. ```cpp #include ... bool MyApp::OnInit() { wxFileSystem::AddHandler(new wxMemoryFSHandler); ... } ``` -------------------------------- ### Upload a file using wxFTP Source: https://docs.wxwidgets.org/3.3/classwx_f_t_p.html This example shows how to initialize an output stream to upload data to a file on the FTP server. ```cpp wxOutputStream *out = ftp.GetOutputStream("filename"); if ( out ) { out->Write(...); // your data delete out; } ``` -------------------------------- ### FindItem(long start, const wxString &str, bool partial) Source: https://docs.wxwidgets.org/3.3/classwx_list_ctrl.html Finds an item whose label matches the specified string, starting from the given index. ```APIDOC ### Method long wxListCtrl::FindItem(long start, const wxString &str, bool partial = false) ### Description Find an item whose label matches this string, starting from start or the beginning if start is -1. The string comparison is case insensitive. If partial is true, the method looks for items that begin with str. ### Parameters - **start** (long) - The index to start searching from, or -1 to start from the beginning. - **str** (const wxString &) - The string to search for. - **partial** (bool) - Whether to perform a partial match (default: false). ### Returns - (long) The index of the next matching item, or -1 (wxNOT_FOUND) if no match is found. ``` -------------------------------- ### Build liblzma from source Source: https://docs.wxwidgets.org/3.3/page_build_liblzma.html Standard sequence of commands to build and install liblzma from source code. ```bash $ ./configure $ make $ make install ``` -------------------------------- ### Use wxIMPLEMENT_APP_CONSOLE Source: https://docs.wxwidgets.org/3.3/group__group__funcmacro__rtti.html Example usage of the wxIMPLEMENT_APP_CONSOLE macro for a console application. ```cpp wxIMPLEMENT_APP_CONSOLE(MyApp); ```