添加wxDialog后出错

时间:2016-11-16 11:54:16

标签: c++ dialog wxwidgets

我在code :: blocks中有一个wxWidgets项目,gcc已经正常工作了。现在我想添加一个从菜单中打开的对话框,但现在我的编译器会抛出有关CreateDialog进程的错误。奇怪的是,我的项目中已经有两个很好的工作对话......

这些是错误:

||=== Build: Debug in WindowsDgpsGUI (compiler: GNU GCC Compiler) ===|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h||In function 'HWND__* CreateDialog(HINSTANCE, LPCTSTR, HWND, DLGPROC)':|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h|38|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HWND__* CreateDialogParamW(HINSTANCE, LPCWSTR, HWND, DLGPROC, LPARAM)'|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h||In function 'HFONT__* CreateFont(int, int, int, int, int, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, LPCTSTR)':|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h|69|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '14' to 'HFONT__* CreateFontW(int, int, int, int, int, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, LPCWSTR)'|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h||In function 'HWND__* CreateWindow(LPCTSTR, LPCTSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID)':|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h|94|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HWND__* CreateWindowExW(DWORD, LPCWSTR, LPCWSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID)'|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h||In function 'HMENU__* LoadMenu(HINSTANCE, LPCTSTR)':|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h|111|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HMENU__* LoadMenuW(HINSTANCE, LPCWSTR)'|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h||In function 'HWND__* FindText(LPFINDREPLACE)':|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h|126|error: cannot convert 'LPFINDREPLACE {aka FINDREPLACEA*}' to 'LPFINDREPLACEW {aka FINDREPLACEW*}' for argument '1' to 'HWND__* FindTextW(LPFINDREPLACEW)'|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h||In function 'HICON__* LoadIcon(HINSTANCE, LPCTSTR)':|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h|311|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HICON__* LoadIconW(HINSTANCE, LPCWSTR)'|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h||In function 'HBITMAP__* LoadBitmap(HINSTANCE, LPCTSTR)':|
C:\wxWidgets-3.0.2\include\wx\msw\winundef.h|324|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HBITMAP__* LoadBitmapW(HINSTANCE, LPCWSTR)'|
D:\WindowsDgpsGui\RecordDialog.cpp||In member function 'void RecordDialog::OnButtonTrackNumberClick(wxCommandEvent&)':|
D:\WindowsDgpsGui\RecordDialog.cpp|142|warning: unused variable 'numberOfTracks' [-Wunused-variable]|
||=== Build failed: 7 error(s), 1 warning(s) (0 minute(s), 1 second(s)) ===|

这是我在main.cpp中打开对话框的方式:

void WindowsDgpsGUIFrame::onRecordClick(wxCommandEvent& event)
{ 
    RecordDialog* recordDialog = new RecordDialog(NULL);
    recordDialog->SetGnssPort(m_usedVariables.gnssPort);
    recordDialog->ShowModal();
    recordDialog->Destroy();
}

RecordDialog.h

#ifndef RECORDDIALOG_H
#define RECORDDIALOG_H

#include "Serial.h"
#include <wx/string.h>
#include <wx/textfile.h>

//(*Headers(RecordDialog)
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/panel.h>
#include <wx/choice.h>
#include <wx/button.h>
#include <wx/dialog.h>
//*)

class RecordDialog: public wxDialog
{
    public:

        RecordDialog(wxWindow* parent,wxWindowID id=wxID_ANY,const wxPoint& pos=wxDefaultPosition,const wxSize& size=wxDefaultSize);
        virtual ~RecordDialog();
        void SetGnssPort(wxString gnssPort);

        //(*Declarations(RecordDialog)
        wxButton* ButtonStartRecording;
        wxTextCtrl* TextCtrlNumber;
        wxStaticText* StaticTrackNumberText;
        wxStaticText* StaticStatusText;
        wxButton* ButtonFileName;
        wxPanel* Panel1;
        wxStaticText* StaticText1;
        wxTextCtrl* TextCtrlFileName;
        wxChoice* ChoiceTrack;
        wxButton* ButtonTrackNumber;
        wxStaticText* StaticTextFileName;
        //*)

    protected:

        //(*Identifiers(RecordDialog)
        static const long ID_STATICTEXT2;
        static const long ID_TEXTCTRL1;
        static const long ID_BUTTON2;
        static const long ID_STATICTEXT3;
        static const long ID_TEXTCTRL2;
        static const long ID_BUTTON3;
        static const long ID_STATICTEXT4;
        static const long ID_CHOICE1;
        static const long ID_STATICTEXT1;
        static const long ID_BUTTON1;
        static const long ID_PANEL1;
        //*)
        static const int STANDARD_BAUDRATE;

    private:



        //(*Handlers(RecordDialog)
        void OnButtonStartRecordingClick(wxCommandEvent& event);
        void OnTextCtrl1Text(wxCommandEvent& event);
        void OnButtonFileNameClick(wxCommandEvent& event);
        void OnButtonTrackNumberClick(wxCommandEvent& event);
        //*)

        DECLARE_EVENT_TABLE()
};

#endif

RecordDialog.cpp

#include "RecordDialog.h"
#include "Serial.h"

#include <wx/textfile.h>
#include <wx/valtext.h>
//(*InternalHeaders(RecordDialog)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//(*IdInit(RecordDialog)
const long RecordDialog::ID_STATICTEXT2 = wxNewId();
const long RecordDialog::ID_TEXTCTRL1 = wxNewId();
const long RecordDialog::ID_BUTTON2 = wxNewId();
const long RecordDialog::ID_STATICTEXT3 = wxNewId();
const long RecordDialog::ID_TEXTCTRL2 = wxNewId();
const long RecordDialog::ID_BUTTON3 = wxNewId();
const long RecordDialog::ID_STATICTEXT4 = wxNewId();
const long RecordDialog::ID_CHOICE1 = wxNewId();
const long RecordDialog::ID_STATICTEXT1 = wxNewId();
const long RecordDialog::ID_BUTTON1 = wxNewId();
const long RecordDialog::ID_PANEL1 = wxNewId();
//*)

const int RecordDialog::STANDARD_BAUDRATE = 9600;

BEGIN_EVENT_TABLE(RecordDialog,wxDialog)
    //(*EventTable(RecordDialog)
    //*)
END_EVENT_TABLE()

RecordDialog::RecordDialog(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
    //(*Initialize(RecordDialog)
    wxBoxSizer* BoxSizer4;
    wxBoxSizer* BoxSizer6;
    wxBoxSizer* BoxSizer5;
    wxBoxSizer* BoxSizer2;
    wxBoxSizer* BoxSizer1;
    wxBoxSizer* BoxSizer3;

    Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
    Panel1 = new wxPanel(this, ID_PANEL1, wxPoint(208,288), wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
    BoxSizer1 = new wxBoxSizer(wxVERTICAL);
    BoxSizer4 = new wxBoxSizer(wxVERTICAL);
    StaticTextFileName = new wxStaticText(Panel1, ID_STATICTEXT2, _("Name the place file you want to create."), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
    BoxSizer4->Add(StaticTextFileName, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    TextCtrlFileName = new wxTextCtrl(Panel1, ID_TEXTCTRL1, _("File name"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
    BoxSizer4->Add(TextCtrlFileName, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    ButtonFileName = new wxButton(Panel1, ID_BUTTON2, _("Set File Name"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
    BoxSizer4->Add(ButtonFileName, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer1->Add(BoxSizer4, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer5 = new wxBoxSizer(wxVERTICAL);
    StaticTrackNumberText = new wxStaticText(Panel1, ID_STATICTEXT3, _("How many tracks are there\?"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
    BoxSizer5->Add(StaticTrackNumberText, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    TextCtrlNumber = new wxTextCtrl(Panel1, ID_TEXTCTRL2, _("Number of Tracks"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
    BoxSizer5->Add(TextCtrlNumber, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    ButtonTrackNumber = new wxButton(Panel1, ID_BUTTON3, _("Set Number of Tracks"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
    BoxSizer5->Add(ButtonTrackNumber, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer1->Add(BoxSizer5, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer6 = new wxBoxSizer(wxVERTICAL);
    StaticText1 = new wxStaticText(Panel1, ID_STATICTEXT4, _("Select which track you wnat to record."), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
    BoxSizer6->Add(StaticText1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    ChoiceTrack = new wxChoice(Panel1, ID_CHOICE1, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE1"));
    ChoiceTrack->Disable();
    BoxSizer6->Add(ChoiceTrack, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer1->Add(BoxSizer6, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer2 = new wxBoxSizer(wxVERTICAL);
    StaticStatusText = new wxStaticText(Panel1, ID_STATICTEXT1, _("Label"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
    BoxSizer2->Add(StaticStatusText, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer1->Add(BoxSizer2, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
    ButtonStartRecording = new wxButton(Panel1, ID_BUTTON1, _("Start Recording"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
    ButtonStartRecording->Disable();
    BoxSizer3->Add(ButtonStartRecording, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer1->Add(BoxSizer3, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Panel1->SetSizer(BoxSizer1);
    BoxSizer1->Fit(Panel1);
    BoxSizer1->SetSizeHints(Panel1);

    Connect(ID_TEXTCTRL1,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&RecordDialog::OnTextCtrl1Text);
    Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&RecordDialog::OnButtonFileNameClick);
    Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&RecordDialog::OnButtonTrackNumberClick);
    Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&RecordDialog::OnButtonStartRecordingClick);
    //*)

    TextCtrlNumber->SetValidator(wxTextValidator(wxFILTER_DIGITS));

}

RecordDialog::~RecordDialog()
{
    //(*Destroy(RecordDialog)
    //*)
}


void RecordDialog::OnButtonStartRecordingClick(wxCommandEvent& event)
{
    ;
}


void RecordDialog::SetGnssPort(wxString gnssPort)
{
    ;

}

void RecordDialog::OnTextCtrl1Text(wxCommandEvent& event)
{
}

void RecordDialog::OnButtonFileNameClick(wxCommandEvent& event)
{
  ;
}

void RecordDialog::OnButtonTrackNumberClick(wxCommandEvent& event)
{
  ;
}

有谁知道出了什么问题?

2 个答案:

答案 0 :(得分:0)

您不能使用与其他源文件相同的选项编译此源文件,即必须在wxUSE_UNICODEUNICODE_UNICODE定义之间存在不匹配。检查它们是否都具有一致的值,甚至根本没有定义,因为如果不覆盖它们,默认情况下应该编译好。

答案 1 :(得分:0)

貌似这是Code :: blocks的错误。重新启动后,一切正常。