#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "HelloWorldApp.h"
#include <tcl.h>
#include "wx/clipbrd.h"
enum
{
ID_Quit = wxID_EXIT,
ID_About = wxID_ABOUT,
ID_Write = 100,
ID_Text = 101
};
/* 程序从这里开始执行,类似非wxWindows程序中的main() */
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title);
void OnWriteClipboardContents(wxCommandEvent&event);
private:
wxTextCtrl *m_textctrl;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_BUTTON(ID_Write, MyFrame::OnWriteClipboardContents)
END_EVENT_TABLE()
IMPLEMENT_APP(HelloWorldApp)
bool HelloWorldApp::OnInit()
{
if ( !wxApp::OnInit() )
return false;
MyFrame *frame = new MyFrame(L"wxClipboard sample");
frame->Show(true);
return true;
}
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{
// set the frame icon
SetIcon(wxICON(sample));
wxPanel *panel = new wxPanel( this, -1 );
wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
main_sizer->Add( new wxButton( panel, ID_Write, L"Get clipboard text" ), 0, wxALL, 5 );
m_textctrl = new wxTextCtrl( panel, ID_Text, L"", wxDefaultPosition,wxDefaultSize, wxTE_MULTILINE );
main_sizer->Add( m_textctrl, 1, wxGROW );
panel->SetSizer( main_sizer );
}
void MyFrame::OnWriteClipboardContents(wxCommandEvent& WXUNUSED(event))
{
if (wxTheClipboard->Open())
{
if (wxTheClipboard->IsSupported( wxDF_UNICODETEXT ))
{
wxTextDataObject data;
wxTheClipboard->GetData( data );
m_textctrl->Clear();
m_textctrl->SetValue( data.GetText() );
}
wxTheClipboard->Close();
}
}
wxWidgets之clipboard参照于sample.
最新推荐文章于 2023-06-10 15:55:45 发布