简体   繁体   English

为什么 wxCrafter Hello World 程序不起作用? [C++,wxWidgets]

[英]Why is wxCrafter Hello World program not working? [C++, wxWidgets]

I followed the wxCrafter Hello World tutorial: https://wiki.codelite.org/pmwiki.php/Main/WxCrafterHelloWorld我跟着 wxCrafter Hello World 教程: https ://wiki.codelite.org/pmwiki.php/Main/WxCrafterHelloWorld

Building process shows no errors, however no dialog shows up when I click "Build->Run" in CodeLite 13, for some reason nothing happens :/构建过程没有显示错误,但是当我在 CodeLite 13 中单击“构建->运行”时没有出现对话框,由于某种原因没有任何反应:/

main.cpp:主.cpp:

#include <wx/app.h>
#include <wx/event.h>
#include "MainDialog.h"
#include <wx/image.h>


// Define the MainApp
class MainApp : public wxApp
{
public:
    MainApp() {}
    virtual ~MainApp() {}

    virtual bool OnInit() {
        // Add the common image handlers
        wxImage::AddHandler( new wxPNGHandler );
        wxImage::AddHandler( new wxJPEGHandler );

        MainDialog mainDialog(NULL);
        mainDialog.ShowModal();
        return false;
    }
};

DECLARE_APP(MainApp)
IMPLEMENT_APP(MainApp)

MainDialog.h:主对话框.h:

#ifndef MAINDIALOG_H
#define MAINDIALOG_H
#include "wxcrafter.h"

class MainDialog : public MainDialogBaseClass
{
public:
    MainDialog(wxWindow* parent);
    virtual ~MainDialog();
protected:
    virtual void OnButtonokButtonClicked(wxCommandEvent& event);
};
#endif // MAINDIALOG_H

MainDialog.cpp:主对话框.cpp:

#include "MainDialog.h"
#include <wx/msgdlg.h> 

MainDialog::MainDialog(wxWindow* parent)
    : MainDialogBaseClass(parent)
{
}

MainDialog::~MainDialog()
{
}

void MainDialog::OnButtonokButtonClicked(wxCommandEvent& event)
{
    ::wxMessageBox(_("Hello World"));
}

wxcrafter.h: wxcrafter.h:

//////////////////////////////////////////////////////////////////////
// This file was auto-generated by codelite's wxCrafter Plugin
// wxCrafter project file: wxcrafter.wxcp
// Do not modify this file by hand!
//////////////////////////////////////////////////////////////////////

#ifndef _WORKSPACE_MEDCEN_PLUS_WXCRAFTER_BASE_CLASSES_H
#define _WORKSPACE_MEDCEN_PLUS_WXCRAFTER_BASE_CLASSES_H

#include <wx/artprov.h>
#include <wx/button.h>
#include <wx/dialog.h>
#include <wx/iconbndl.h>
#include <wx/settings.h>
#include <wx/sizer.h>
#include <wx/statline.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/xrc/xh_bmp.h>
#include <wx/xrc/xmlres.h>
#if wxVERSION_NUMBER >= 2900
#include <wx/persist.h>
#include <wx/persist/bookctrl.h>
#include <wx/persist/toplevel.h>
#include <wx/persist/treebook.h>
#endif

#ifdef WXC_FROM_DIP
#undef WXC_FROM_DIP
#endif
#if wxVERSION_NUMBER >= 3100
#define WXC_FROM_DIP(x) wxWindow::FromDIP(x, NULL)
#else
#define WXC_FROM_DIP(x) x
#endif

class MainDialogBaseClass : public wxDialog
{
protected:
    wxStaticText* m_staticText21;
    wxTextCtrl* m_textCtrl23;
    wxStaticLine* m_staticLine15;
    wxButton* m_buttonOK;
    wxButton* m_buttonCancel;

protected:
    virtual void OnButtonokButtonClicked(wxCommandEvent& event)
    {
        event.Skip();
    }

public:
    wxStaticText* GetStaticText21()
    {
        return m_staticText21;
    }
    wxTextCtrl* GetTextCtrl23()
    {
        return m_textCtrl23;
    }
    wxStaticLine* GetStaticLine15()
    {
        return m_staticLine15;
    }
    wxButton* GetButtonOK()
    {
        return m_buttonOK;
    }
    wxButton* GetButtonCancel()
    {
        return m_buttonCancel;
    }
    MainDialogBaseClass(wxWindow* parent,
        wxWindowID id = wxID_ANY,
        const wxString& title = _("My Dialog"),
        const wxPoint& pos = wxDefaultPosition,
        const wxSize& size = wxSize(500, 300),
        long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
    virtual ~MainDialogBaseClass();
};

#endif

wxcrafter.cpp: wxcrafter.cpp:

//////////////////////////////////////////////////////////////////////
// This file was auto-generated by codelite's wxCrafter Plugin
// wxCrafter project file: wxcrafter.wxcp
// Do not modify this file by hand!
//////////////////////////////////////////////////////////////////////

#include "wxcrafter.h"

// Declare the bitmap loading function
extern void wxC9ED9InitBitmapResources();

static bool bBitmapLoaded = false;

MainDialogBaseClass::MainDialogBaseClass(wxWindow* parent,
    wxWindowID id,
    const wxString& title,
    const wxPoint& pos,
    const wxSize& size,
    long style)
    : wxDialog(parent, id, title, pos, size, style)
{
    if(!bBitmapLoaded) {
        // We need to initialise the default bitmap handler
        wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler);
        wxC9ED9InitBitmapResources();
        bBitmapLoaded = true;
    }
    this->SetFocus();

    wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
    this->SetSizer(mainSizer);

    wxBoxSizer* boxSizer19 = new wxBoxSizer(wxHORIZONTAL);

    mainSizer->Add(boxSizer19, 1, wxALL | wxEXPAND, WXC_FROM_DIP(5));

    m_staticText21 = new wxStaticText(
        this, wxID_ANY, _("Static Text Label"), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), 0);

    boxSizer19->Add(m_staticText21, 0, wxALL, WXC_FROM_DIP(5));

    m_textCtrl23 = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), 0);
#if wxVERSION_NUMBER >= 3000
    m_textCtrl23->SetHint(wxT(""));
#endif

    boxSizer19->Add(m_textCtrl23, 0, wxALL, WXC_FROM_DIP(5));

    mainSizer->Add(0, 0, 1, wxALL | wxEXPAND, WXC_FROM_DIP(5));

    m_staticLine15 =
        new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), wxLI_HORIZONTAL);

    mainSizer->Add(m_staticLine15, 0, wxALL | wxEXPAND, WXC_FROM_DIP(5));

    wxBoxSizer* boxSizer12 = new wxBoxSizer(wxHORIZONTAL);

    mainSizer->Add(boxSizer12, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, WXC_FROM_DIP(5));

    m_buttonOK = new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), 0);
    m_buttonOK->SetDefault();

    boxSizer12->Add(m_buttonOK, 0, wxALL, WXC_FROM_DIP(5));

    m_buttonCancel =
        new wxButton(this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), 0);

    boxSizer12->Add(m_buttonCancel, 0, wxALL, WXC_FROM_DIP(5));

    SetName(wxT("MainDialogBaseClass"));
    SetSize(wxDLG_UNIT(this, wxSize(500, 300)));
    if(GetSizer()) {
        GetSizer()->Fit(this);
    }
    if(GetParent()) {
        CentreOnParent(wxBOTH);
    } else {
        CentreOnScreen(wxBOTH);
    }
#if wxVERSION_NUMBER >= 2900
    if(!wxPersistenceManager::Get().Find(this)) {
        wxPersistenceManager::Get().RegisterAndRestore(this);
    } else {
        wxPersistenceManager::Get().Restore(this);
    }
#endif
    // Connect events
    m_buttonOK->Connect(
        wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MainDialogBaseClass::OnButtonokButtonClicked), NULL, this);
}

MainDialogBaseClass::~MainDialogBaseClass()
{
    m_buttonOK->Disconnect(
        wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MainDialogBaseClass::OnButtonokButtonClicked), NULL, this);
}

Something is wrong with either the C::L installation or the wxCrafter plugin. C::L 安装或 wxCrafter 插件有问题。

If you did follow the referenced tutorial, it should create a wxButton object as a member of the dialog and bind the event handler to it.如果您确实遵循了参考教程,它应该创建一个 wxButton 对象作为对话框的成员并将事件处理程序绑定到它。

Can you compile and run the minimal sample from the wxWidgets install?你能编译并运行 wxWidgets 安装中的minimal示例吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM