]>
git.saurik.com Git - wxWidgets.git/blob - samples/dde/client.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: DDE sample: client
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 // Settings common to both executables: determines whether
24 // we're using TCP/IP or real DDE.
28 #if defined(__WXGTK__) || defined(__WXMOTIF__)
29 #include "mondrian.xpm"
34 MyFrame
*frame
= NULL
;
38 char ipc_buffer
[4000];
39 wxListBox
*the_list
= NULL
;
41 MyConnection
*the_connection
= NULL
;
44 // The `main program' equivalent, creating the windows and returning the
48 // Create the main frame window
49 frame
= new MyFrame(NULL
, "Client", wxPoint(400, 0), wxSize(400, 300));
52 frame
->SetIcon(wxICON(mondrian
));
55 wxMenu
*file_menu
= new wxMenu
;
57 file_menu
->Append(CLIENT_EXECUTE
, "Execute");
58 file_menu
->Append(CLIENT_REQUEST
, "Request");
59 file_menu
->Append(CLIENT_POKE
, "Poke");
60 file_menu
->Append(CLIENT_QUIT
, "Quit");
62 wxMenuBar
*menu_bar
= new wxMenuBar
;
64 menu_bar
->Append(file_menu
, "File");
66 // Associate the menu bar with the frame
67 frame
->SetMenuBar(menu_bar
);
70 frame
->panel
= new wxPanel(frame
, -1, wxPoint(0, 0), wxSize(400, 250));
71 the_list
= new wxListBox(frame
->panel
, CLIENT_LISTBOX
, wxPoint(5, 5), wxSize(150, 120));
72 the_list
->Append("Apple");
73 the_list
->Append("Pear");
74 the_list
->Append("Orange");
75 the_list
->Append("Banana");
76 the_list
->Append("Fruit");
81 wxString server
= "4242";
82 wxString hostName
= wxGetHostName();
89 // Create a new client
90 my_client
= new MyClient
;
91 the_connection
= (MyConnection
*)my_client
->MakeConnection(hostName
, server
, "IPC TEST");
95 wxMessageBox("Failed to make connection to server", "Client Demo Error");
97 // extern void wxPrintDDEError();
102 the_connection
->StartAdvise("Item");
117 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
118 EVT_MENU(CLIENT_QUIT
, MyFrame::OnExit
)
119 EVT_MENU(CLIENT_EXECUTE
, MyFrame::OnExecute
)
120 EVT_MENU(CLIENT_POKE
, MyFrame::OnPoke
)
121 EVT_MENU(CLIENT_REQUEST
, MyFrame::OnRequest
)
122 EVT_CLOSE(MyFrame::OnCloseWindow
)
125 // Define my frame constructor
126 MyFrame::MyFrame(wxFrame
*frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
127 wxFrame(frame
, -1, title
, pos
, size
)
132 void MyFrame::OnExecute(wxCommandEvent
& event
)
135 the_connection
->Execute("Hello from the client!");
138 void MyFrame::OnPoke(wxCommandEvent
& event
)
141 the_connection
->Poke("An item", "Some data to poke at the server!");
144 void MyFrame::OnRequest(wxCommandEvent
& event
)
148 char *data
= the_connection
->Request("An item");
150 wxMessageBox(data
, "Client: Request", wxOK
);
154 void MyFrame::OnExit(wxCommandEvent
& event
)
157 the_connection
->Disconnect();
162 // Define the behaviour for the frame closing
163 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
167 the_connection
->Disconnect();
172 MyClient::MyClient(void)
176 wxConnectionBase
*MyClient::OnMakeConnection(void)
178 return new MyConnection
;
181 MyConnection::MyConnection(void):wxConnection(ipc_buffer
, 3999)
185 MyConnection::~MyConnection(void)
187 the_connection
= NULL
;
190 bool MyConnection::OnAdvise(const wxString
& topic
, const wxString
& item
, char *data
, int size
, wxIPCFormat format
)
194 int n
= the_list
->FindString(data
);
196 the_list
->SetSelection(n
);
201 bool MyConnection::OnDisconnect()
205 the_connection
= NULL
;