15周 项目三 wxWidgets 梦佳词典

15周 项目三 wxWidgets 梦佳词典_第1张图片shi


dict.cpp

/***************************************************************
 * Name:      G3App.cpp
 * Purpose:   Code for Application Class
 * Author:    zmj ()
 * Created:   2014-06-03
 * Copyright: zmj ()
 * License:
 **************************************************************/

#include "wx_pch.h"
//(*AppHeaders
#include "G3Main.h"
#include <wx/image.h>
//*)

#include "G3App.h"
#include "dictFrame.h"

IMPLEMENT_APP(G3App)

bool G3App::OnInit()
{
    dictFrame *mydict = new dictFrame(NULL);
    mydict->Show(true);

    return true;
}

dicFrame.cpp


#include "wx_pch.h"
#include "dictFrame.h"

#ifndef WX_PRECOMP
	//(*InternalHeadersPCH(dictFrame)
	#include <wx/intl.h>
	#include <wx/string.h>
	//*)
#endif
//(*InternalHeaders(dictFrame)
//*)

//(*IdInit(dictFrame)
const long dictFrame::ID_BUTTON1 = wxNewId();
const long dictFrame::ID_STATICTEXT1 = wxNewId();
const long dictFrame::ID_STATICTEXT2 = wxNewId();
const long dictFrame::ID_TEXTCTRL1 = wxNewId();
const long dictFrame::ID_TEXTCTRL2 = wxNewId();
const long dictFrame::ID_BUTTON2 = wxNewId();
//*)

BEGIN_EVENT_TABLE(dictFrame,wxFrame)
	//(*EventTable(dictFrame)
	//*)
END_EVENT_TABLE()

dictFrame::dictFrame(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size):dict()
{
	//(*Initialize(dictFrame)
	Create(parent, id, _("language"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
	SetClientSize(wxSize(589,253));
	Move(wxDefaultPosition);
	Button1 = new wxButton(this, ID_BUTTON1, _("Go"), wxPoint(448,72), wxSize(112,120), 0, wxDefaultValidator, _T("ID_BUTTON1"));
	StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("English"), wxPoint(120,80), wxSize(64,24), 0, _T("ID_STATICTEXT1"));
	StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("Chinese"), wxPoint(128,136), wxSize(40,40), 0, _T("ID_STATICTEXT2"));
	TextCtrl1 = new wxTextCtrl(this, ID_TEXTCTRL1, wxEmptyString, wxPoint(184,72), wxSize(224,40), 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
	TextCtrl2 = new wxTextCtrl(this, ID_TEXTCTRL2, wxEmptyString, wxPoint(184,120), wxSize(224,72), 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
	Button2 = new wxButton(this, ID_BUTTON2, _("quit"), wxPoint(24,216), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));

	Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&dictFrame::OnButton1Click);
	Connect(ID_TEXTCTRL1,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&dictFrame::OnTextCtrl1Text);
	Connect(ID_TEXTCTRL2,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&dictFrame::OnTextCtrl2Text);
	Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&dictFrame::OnButton2Click);
	Connect(wxID_ANY,wxEVT_CLOSE_WINDOW,(wxObjectEventFunction)&dictFrame::OnClose);
	//*)
	TextCtrl1->SetFocus ();
}

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


void dictFrame::OnButton1Click(wxCommandEvent& event)
{
    //函数由增加事件处理生成,但函数体要自己实现
    string s=string(TextCtrl1->GetLineText(0));   //获得文本框中文字
    wxString ws = dict.searchWord(s);             //查字典
    TextCtrl2->SetLabelText(ws);                  //在另一个文本框中显示查询结果
}

void dictFrame::OnTextCtrl2Text(wxCommandEvent& event)
{

}

void dictFrame::OnTextCtrl1Text(wxCommandEvent& event)
{

}

void dictFrame::OnClose(wxCloseEvent& event)
{

}

void dictFrame::OnButton2Click(wxCommandEvent& event)
{
    exit(1);
    //close(true);
}

G3APP.cpp

/***************************************************************
 * Name:      G3App.cpp
 * Purpose:   Code for Application Class
 * Author:    zmj ()
 * Created:   2014-06-03
 * Copyright: zmj ()
 * License:
 **************************************************************/

#include "wx_pch.h"
//(*AppHeaders
#include "G3Main.h"
#include <wx/image.h>
//*)

#include "G3App.h"
#include "dictFrame.h"

IMPLEMENT_APP(G3App)

bool G3App::OnInit()
{
    dictFrame *mydict = new dictFrame(NULL);
    mydict->Show(true);

    return true;
}

dict.h

#ifndef DICT_H_INCLUDED
#define DICT_H_INCLUDED
using namespace std;
//定义词条类
class Word
{
public:
    void set(string e, string c, string wc);
    int compare(string);  //英语部分与给定字符串比较,等于返回,大于返回,小于返回-1
    string getChinese();
    string getWord_class();
private:
    string english;
    string chinese;
    string word_class;
};

//定义字典类
class Dictionary
{
public:
    Dictionary();
    string searchWord(string k);
private:
    int BinSeareh(int low, int high, string k);
    int wordsNum;
    Word words[8000]; //用于保存词库
};



#endif // DICT_H_INCLUDED

dictFrame.h

#ifndef DICTFRAME_H
#define DICTFRAME_H

#ifndef WX_PRECOMP
	//(*HeadersPCH(dictFrame)
	#include <wx/stattext.h>
	#include <wx/textctrl.h>
	#include <wx/button.h>
	#include <wx/frame.h>
	//*)
#endif
//(*Headers(dictFrame)
//*)
#include "dict.h"
class dictFrame: public wxFrame
{
	public:

		dictFrame(wxWindow* parent,wxWindowID id=wxID_ANY,const wxPoint& pos=wxDefaultPosition,const wxSize& size=wxDefaultSize);
		virtual ~dictFrame();

		//(*Declarations(dictFrame)
		wxStaticText* StaticText2;
		wxButton* Button1;
		wxStaticText* StaticText1;
		wxButton* Button2;
		wxTextCtrl* TextCtrl2;
		wxTextCtrl* TextCtrl1;
		//*)

	protected:

		//(*Identifiers(dictFrame)
		static const long ID_BUTTON1;
		static const long ID_STATICTEXT1;
		static const long ID_STATICTEXT2;
		static const long ID_TEXTCTRL1;
		static const long ID_TEXTCTRL2;
		static const long ID_BUTTON2;
		//*)

	private:
	    Dictionary dict;

		//(*Handlers(dictFrame)
		void OnButton1Click(wxCommandEvent& event);
		void OnTextCtrl2Text(wxCommandEvent& event);
		void OnTextCtrl1Text(wxCommandEvent& event);
		void OnClose(wxCloseEvent& event);
		void OnButton2Click(wxCommandEvent& event);
		//*)

		DECLARE_EVENT_TABLE()
};

#endif

G3APP.h

/***************************************************************
 * Name:      G3App.h
 * Purpose:   Defines Application Class
 * Author:    zmj ()
 * Created:   2014-06-03
 * Copyright: zmj ()
 * License:
 **************************************************************/

#ifndef G3APP_H
#define G3APP_H

#include <wx/app.h>

class G3App : public wxApp
{
    public:
        virtual bool OnInit();
};

#endif // G3APP_H

G3Main.h

/***************************************************************
 * Name:      G3Main.h
 * Purpose:   Defines Application Frame
 * Author:    zmj ()
 * Created:   2014-06-03
 * Copyright: zmj ()
 * License:
 **************************************************************/

#ifndef G3MAIN_H
#define G3MAIN_H

//(*Headers(G3Dialog)
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/statline.h>
#include <wx/button.h>
#include <wx/dialog.h>
//*)

class G3Dialog: public wxDialog
{
    public:

        G3Dialog(wxWindow* parent,wxWindowID id = -1);
        virtual ~G3Dialog();

    private:

        //(*Handlers(G3Dialog)
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        //*)

        //(*Identifiers(G3Dialog)
        static const long ID_STATICTEXT1;
        static const long ID_BUTTON1;
        static const long ID_STATICLINE1;
        static const long ID_BUTTON2;
        //*)

        //(*Declarations(G3Dialog)
        wxButton* Button1;
        wxStaticText* StaticText1;
        wxBoxSizer* BoxSizer2;
        wxButton* Button2;
        wxStaticLine* StaticLine1;
        wxBoxSizer* BoxSizer1;
        //*)

        DECLARE_EVENT_TABLE()
};

#endif // G3MAIN_H

wx_pch.h

/***************************************************************
 * Name:      wx_pch.h
 * Purpose:   Header to create Pre-Compiled Header (PCH)
 * Author:    zmj ()
 * Created:   2014-06-03
 * Copyright: zmj ()
 * License:   
 **************************************************************/

#ifndef WX_PCH_H_INCLUDED
#define WX_PCH_H_INCLUDED

// basic wxWidgets headers
#include <wx/wxprec.h>

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#ifdef WX_PRECOMP
    // put here all your rarely-changing header files
#endif // WX_PRECOMP

#endif // WX_PCH_H_INCLUDED


15周 项目三 wxWidgets 梦佳词典_第2张图片


15周 项目三 wxWidgets 梦佳词典_第3张图片

感悟

贺老师,程序退出不了,所以我又加了一个quit键,可是close(true)函数没用,我改成了exit(0).。。。。

汉语还是会乱码。。。不过总算能用了。。

你可能感兴趣的:(15周 项目三 wxWidgets 梦佳词典)