Untitled
unknown
c_cpp
2 years ago
2.1 kB
39
Indexable
// require: libwxgtk3.0-gtk3-dev // compile: g++ ./wxtest.cpp $(wx-config --cppflags) $(wx-config --libs core,base) -o ./wxtestx #include "wx/wxprec.h" #include <wx/graphics.h> #include <wx/wx.h> #include <wx/clipbrd.h> class HelloWorldApp : public wxApp { wxFrame *_frame; public: virtual bool OnInit(); }; DECLARE_APP(HelloWorldApp) IMPLEMENT_APP(HelloWorldApp) /////////////// enum { BUTTON_Hello = wxID_HIGHEST + 1 // declares an id which will be used to call our button }; class MainFrame: public wxFrame // MainFrame is the class for our window, { wxTextCtrl *_text = nullptr; wxButton *_btn = nullptr; public: MainFrame( const wxString &title, const wxPoint &pos, const wxSize &size ) : wxFrame(NULL, wxID_ANY, title, pos, size) { _text = new wxTextCtrl( this, wxID_ANY, "abcdefghijklmnopqrstuvw", wxPoint(0, 0), wxSize(780, 50), wxTE_MULTILINE ); _btn = new wxButton(this, BUTTON_Hello, _T("Hello World"), wxPoint(0, 100), wxSize(780, 50), 0); } void OnButton( wxCommandEvent& event ) { if (wxTheClipboard->Open()) { fprintf(stderr, "!!!! OPEN FOR GET\n"); if (wxTheClipboard->IsSupported( wxDF_TEXT )) { wxTextDataObject data; wxTheClipboard->GetData( data ); const wxString &wx_str = data.GetText(); fprintf(stderr, "!!!! GOT: '%ls'\n", wx_str.wc_str()); } wxTheClipboard->Close(); } if (wxTheClipboard->Open()) { fprintf(stderr, "!!!! OPEN FOR SET\n"); wxTheClipboard->Clear(); wxTheClipboard->SetData(new wxTextDataObject("1234567890")); wxTheClipboard->Flush(); wxTheClipboard->Close(); fprintf(stderr, "!!!! SET DONE\n"); } } wxDECLARE_EVENT_TABLE(); }; wxBEGIN_EVENT_TABLE(MainFrame, wxFrame) EVT_BUTTON ( BUTTON_Hello, MainFrame::OnButton ) // Tell the OS to run MainFrame::OnExit when wxEND_EVENT_TABLE() // This is executed upon startup, like 'main()' in non-wxWidgets programs. bool HelloWorldApp::OnInit() { _frame = new MainFrame(_("Clipboard test"), wxDefaultPosition, wxSize(800, 600)); _frame->Show(true); SetTopWindow(_frame); return true; }
Editor is loading...