Sei sulla pagina 1di 8

/***************************************************************

* Name: PW4Main.h

* Purpose: Defines Application Frame

* Author: ()

* Created: 2018-09-16

* Copyright: ()

* License:

**************************************************************/

#ifndef PW4MAIN_H

#define PW4MAIN_H

#ifndef WX_PRECOMP

#include <wx/wx.h>

#endif

#include "PW4App.h"

class PW4Frame: public wxFrame

public:

PW4Frame(wxFrame *frame, const wxString& title);

~PW4Frame();

private:

enum
{

idMenuQuit = 1000,

ID_TextBox,

idMenuOpen,

idMenuSave,

idMenuAbout

};

wxTextCtrl *textControl;

wxFileDialog* openDialog;

wxFileDialog* saveDialog;

void OnClose(wxCloseEvent& event);

void OnQuit(wxCommandEvent& event);

void OnAbout(wxCommandEvent& event);

void OnOpen(wxCommandEvent& event);

void OnSave(wxCommandEvent& event);

DECLARE_EVENT_TABLE()

};

#endif // PW4MAIN_H
/***************************************************************

* Name: PW4Main.cpp

* Purpose: Code for Application Frame

* Author: ()

* Created: 2018-09-16

* Copyright: ()

* License:

**************************************************************/

#ifdef WX_PRECOMP

#include "wx_pch.h"

#endif

#ifdef __BORLANDC__

#pragma hdrstop

#endif //__BORLANDC__

#include "PW4Main.h"

//helper functions

enum wxbuildinfoformat {

short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)

{
wxString wxbuild(wxVERSION_STRING);

if (format == long_f )

#if defined(__WXMSW__)

wxbuild << _T("-Windows");

#elif defined(__WXMAC__)

wxbuild << _T("-Mac");

#elif defined(__UNIX__)

wxbuild << _T("-Linux");

#endif

#if wxUSE_UNICODE

wxbuild << _T("-Unicode build");

#else

wxbuild << _T("-ANSI build");

#endif // wxUSE_UNICODE

return wxbuild;

BEGIN_EVENT_TABLE(PW4Frame, wxFrame)

EVT_CLOSE(PW4Frame::OnClose)

EVT_MENU(idMenuQuit, PW4Frame::OnQuit)
EVT_MENU(idMenuAbout, PW4Frame::OnAbout)

EVT_MENU(idMenuOpen, PW4Frame::OnOpen)

END_EVENT_TABLE()

PW4Frame::PW4Frame(wxFrame *frame, const wxString& title)

: wxFrame(frame, -1, title)

#if wxUSE_MENUS

// create a menu bar

wxMenuBar* mbar = new wxMenuBar();

wxMenu* fileMenu = new wxMenu(_T(""));

fileMenu->Append(idMenuOpen, _("&Open\tAlt-F5"), _("Open a file"));

fileMenu->Append(idMenuQuit, _("&Quit\tAlt-F4"), _("Quit the application"));

mbar->Append(fileMenu, _("&File"));

wxMenu* helpMenu = new wxMenu(_T(""));

helpMenu->Append(idMenuAbout, _("&About\tF1"), _("Show info about this application"));

mbar->Append(helpMenu, _("&Help"));

SetMenuBar(mbar);

#endif // wxUSE_MENUS

#if wxUSE_STATUSBAR

// create a status bar with some information about the used wxWidgets version

textControl = new wxTextCtrl(this, ID_TextBox,


wxT(""), wxDefaultPosition, wxDefaultSize,

wxTE_MULTILINE | wxTE_RICH , wxDefaultValidator, wxTextCtrlNameStr);

CreateStatusBar(2);

SetStatusText("Hello its " + wxDateTime::Now().Format("%c using " + wxbuildinfo(short_f)),0);

SetStatusText(wxbuildinfo(short_f), 1);

#endif // wxUSE_STATUSBAR

PW4Frame::~PW4Frame()

void PW4Frame::OnClose(wxCloseEvent &event)

Destroy();

void PW4Frame::OnQuit(wxCommandEvent &event)

Destroy();

void PW4Frame::OnOpen(wxCommandEvent &event)

{
wxFileDialog *openDialog = new wxFileDialog(this, wxT("Choose a file"), wxT(""), wxT(""),

wxT("Text Files (*.txt)|*.txt|C++ Files (*.cpp)|*.cpp|Header Files (*.h)|*.h"),

wxFD_OPEN );

int response = openDialog->ShowModal();

if(response == wxID_OK)

{ //if response ok, then load contents into textControl

this->textControl->LoadFile(openDialog->GetPath());

void PW4Frame::OnAbout(wxCommandEvent &event)

wxString msg = wxbuildinfo(long_f);

wxMessageBox(msg, _("Welcome to..."));

Potrebbero piacerti anche