When I run my program, the following error appears in the Log Window.
The call that produces this is Line 118 in MyFrame constructor.In file ./include/wx/msw/private.h at line 339: 'GetWindowRect' failed with error 0x00000578 (Invalid window handle.).
Code: Select all
int fileMenuBarSize_height = menuBar->GetSize().GetHeight();
And, how do I mitigate this problem? Should I call things in a different way? Thank you!
Here is my minimal, one-file example. I hope it is easy to test.
Go to File --> Log Window to see the error I mentioned.
Code: Select all
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#ifndef MAIN_APP_H
#define MAIN_APP_H
// Define a new application
class MyApp : public wxApp
{
public:
MyApp(){};
bool OnInit() wxOVERRIDE;
};
// The main frame class
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title);
void OnQuit(wxCommandEvent& event);
#if wxUSE_LOGWINDOW
void OnLogWindow(wxCommandEvent& event);
#endif // wxUSE_LOGWINDOW
private:
#if wxUSE_LOGWINDOW
wxLogWindow* m_LogWin;
#endif // wxUSE_LOGWINDOW
wxDECLARE_EVENT_TABLE();
};
// IDs for the controls and the menu commands
enum
{
MyFrame_Quit = wxID_EXIT,
MyFrame_About = wxID_ABOUT,
MyFrame_LogW = wxID_HIGHEST + 10,
};
#endif // MAIN_APP_H
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(MyFrame_Quit, MyFrame::OnQuit)
#if wxUSE_LOGWINDOW
EVT_MENU(MyFrame_LogW, MyFrame::OnLogWindow)
#endif // wxUSE_LOGWINDOW
wxEND_EVENT_TABLE()
wxIMPLEMENT_APP(MyApp);
// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
{
if (!wxApp::OnInit())
return false;
// create the main application window
MyFrame* frame = new MyFrame("wxWidgets MyFrame Sample");
// As of October 2015 GTK+ needs the frame to be shown before we call SetCurrent()
frame->Show(true);
return true;
}
const int frame_size = 512;
// frame constructor
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition,
wxSize(frame_size, frame_size))
{
#if wxUSE_MENUS
// create a menu bar
wxMenu *fileMenu = new wxMenu;
#if wxUSE_LOGWINDOW
fileMenu->Append(MyFrame_LogW, "&Log window", "Open the log window");
fileMenu->AppendSeparator();
#endif // wxUSE_LOGWINDOW
fileMenu->Append(MyFrame_Quit, "E&xit\tAlt-X", "Quit this program");
// now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(fileMenu, "&File");
// ... and attach this menu bar to the frame
SetMenuBar(menuBar);
#endif // wxUSE_MENUS
#if wxUSE_LOGWINDOW
//Open a log window, don't show it though
m_LogWin = new wxLogWindow(NULL, "MyFrame log window", false, false);
wxLog::SetActiveTarget(m_LogWin);
#endif // wxUSE_LOGWINDOW
// !!!!!!!!!!!!!!!!!!!!!!!
// !!!
// !!! causing error
// !!! In file ./include/wx/msw/private.h at line 339:
// !!! 'GetWindowRect' failed with error 0x00000578 (Invalid window handle.).
// !!!
// !!!!!!!!!!!!!!!!!!!!!!!!
int fileMenuBarSize_height = menuBar->GetSize().GetHeight();
}
// event handlers
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(true); // true is to force the frame to close
}
#if wxUSE_LOGWINDOW
void MyFrame::OnLogWindow(wxCommandEvent& WXUNUSED(event))
{
if (m_LogWin->GetFrame()->IsIconized())
m_LogWin->GetFrame()->Restore();
if (!m_LogWin->GetFrame()->IsShown())
m_LogWin->Show();
m_LogWin->GetFrame()->SetFocus();
}
#endif // wxUSE_LOGWINDOW