1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: client.h 3 // Purpose: DDE sample: client 4 // Author: Julian Smart 5 // Modified by: 6 // Created: 25/01/99 7 // Copyright: (c) Julian Smart 8 // Licence: wxWindows licence 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #include "connection.h" 12 13 #define ID_START 10000 14 #define ID_DISCONNECT 10001 15 #define ID_STARTADVISE 10002 16 #define ID_LOG 10003 17 #define ID_SERVERNAME 10004 18 #define ID_STOPADVISE 10005 19 #define ID_POKE 10006 20 #define ID_REQUEST 10007 21 #define ID_EXECUTE 10008 22 #define ID_TOPIC 10009 23 #define ID_HOSTNAME 10010 24 25 // Define a new application 26 class MyClient; 27 class MyFrame; 28 29 class MyApp: public wxApp 30 { 31 public: 32 virtual bool OnInit() wxOVERRIDE; 33 virtual int OnExit() wxOVERRIDE; GetFrame()34 MyFrame *GetFrame() { return m_frame; } 35 36 protected: 37 MyFrame *m_frame; 38 }; 39 40 // Define a new frame 41 class MyFrame: public wxFrame 42 { 43 public: 44 MyFrame(wxFrame *frame, const wxString& title); 45 46 void OnExit(wxCommandEvent& event); 47 void OnClose(wxCloseEvent& event); 48 void EnableControls(); 49 void Disconnect(); 50 51 protected: GetStart()52 wxButton* GetStart() { return (wxButton*) FindWindow( ID_START ); } GetServername()53 wxChoice* GetServername() { return (wxChoice*) FindWindow( ID_SERVERNAME ); } GetHostname()54 wxChoice* GetHostname() { return (wxChoice*) FindWindow( ID_HOSTNAME ); } GetTopic()55 wxChoice* GetTopic() { return (wxChoice*) FindWindow( ID_TOPIC ); } GetDisconnect()56 wxButton* GetDisconnect() { return (wxButton*) FindWindow( ID_DISCONNECT ); } GetStartAdvise()57 wxButton* GetStartAdvise() { return (wxButton*) FindWindow( ID_STARTADVISE ); } GetStopAdvise()58 wxButton* GetStopAdvise() { return (wxButton*) FindWindow( ID_STOPADVISE ); } GetRequest()59 wxButton* GetRequest() { return (wxButton*) FindWindow( ID_REQUEST ); } GetPoke()60 wxButton* GetPoke() { return (wxButton*) FindWindow( ID_POKE ); } GetExecute()61 wxButton* GetExecute() { return (wxButton*) FindWindow( ID_EXECUTE ); } GetLog()62 wxTextCtrl* GetLog() { return (wxTextCtrl*) FindWindow( ID_LOG ); } 63 64 MyClient *m_client; 65 66 void OnStart( wxCommandEvent &event ); 67 void OnServername( wxCommandEvent &event ); 68 void OnHostname( wxCommandEvent &event ); 69 void OnTopic( wxCommandEvent &event ); 70 void OnDisconnect( wxCommandEvent &event ); 71 void OnStartAdvise( wxCommandEvent &event ); 72 void OnStopAdvise( wxCommandEvent &event ); 73 void OnExecute(wxCommandEvent& event); 74 void OnPoke(wxCommandEvent& event); 75 void OnRequest(wxCommandEvent& event); 76 77 protected: 78 wxDECLARE_EVENT_TABLE(); 79 }; 80 81 class MyConnection : public MyConnectionBase 82 { 83 public: 84 virtual bool DoExecute(const void *data, size_t size, wxIPCFormat format) wxOVERRIDE; 85 virtual const void *Request(const wxString& item, size_t *size = NULL, wxIPCFormat format = wxIPC_TEXT) wxOVERRIDE; 86 virtual bool DoPoke(const wxString& item, const void* data, size_t size, wxIPCFormat format) wxOVERRIDE; 87 virtual bool OnAdvise(const wxString& topic, const wxString& item, const void *data, size_t size, wxIPCFormat format) wxOVERRIDE; 88 virtual bool OnDisconnect() wxOVERRIDE; 89 }; 90 91 class MyClient: public wxClient 92 { 93 public: 94 MyClient(); 95 ~MyClient(); 96 bool Connect(const wxString& sHost, const wxString& sService, const wxString& sTopic); 97 void Disconnect(); 98 wxConnectionBase *OnMakeConnection() wxOVERRIDE; IsConnected()99 bool IsConnected() { return m_connection != NULL; } GetConnection()100 MyConnection *GetConnection() { return m_connection; } 101 102 protected: 103 MyConnection *m_connection; 104 }; 105