renaming and moving samples around
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5300 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
2
samples/ipc/.cvsignore
Normal file
2
samples/ipc/.cvsignore
Normal file
@@ -0,0 +1,2 @@
|
||||
Makefile.in
|
||||
|
220
samples/ipc/client.cpp
Normal file
220
samples/ipc/client.cpp
Normal file
@@ -0,0 +1,220 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: client.cpp
|
||||
// Purpose: DDE sample: client
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 25/01/99
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
|
||||
// Settings common to both executables: determines whether
|
||||
// we're using TCP/IP or real DDE.
|
||||
|
||||
#include "ddesetup.h"
|
||||
|
||||
#if defined(__WXGTK__) || defined(__WXMOTIF__)
|
||||
#include "mondrian.xpm"
|
||||
#endif
|
||||
|
||||
#include "client.h"
|
||||
|
||||
MyFrame *frame = NULL;
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
char ipc_buffer[4000];
|
||||
wxListBox *the_list = NULL;
|
||||
|
||||
MyConnection *the_connection = NULL;
|
||||
MyClient *my_client ;
|
||||
|
||||
// The `main program' equivalent, creating the windows and returning the
|
||||
// main frame
|
||||
bool MyApp::OnInit()
|
||||
{
|
||||
// Create the main frame window
|
||||
frame = new MyFrame(NULL, "Client", wxPoint(400, 0), wxSize(400, 300));
|
||||
|
||||
// Give it an icon
|
||||
frame->SetIcon(wxICON(mondrian));
|
||||
|
||||
// Make a menubar
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
|
||||
file_menu->Append(CLIENT_EXECUTE, "Execute");
|
||||
file_menu->Append(CLIENT_REQUEST, "Request");
|
||||
file_menu->Append(CLIENT_POKE, "Poke");
|
||||
file_menu->Append(CLIENT_QUIT, "Quit");
|
||||
|
||||
wxMenuBar *menu_bar = new wxMenuBar;
|
||||
|
||||
menu_bar->Append(file_menu, "File");
|
||||
|
||||
// Associate the menu bar with the frame
|
||||
frame->SetMenuBar(menu_bar);
|
||||
|
||||
// Make a panel
|
||||
frame->panel = new wxPanel(frame, -1, wxPoint(0, 0), wxSize(400, 250));
|
||||
the_list = new wxListBox(frame->panel, CLIENT_LISTBOX, wxPoint(5, 5), wxSize(150, 120));
|
||||
the_list->Append("Apple");
|
||||
the_list->Append("Pear");
|
||||
the_list->Append("Orange");
|
||||
the_list->Append("Banana");
|
||||
the_list->Append("Fruit");
|
||||
|
||||
frame->panel->Fit();
|
||||
frame->Fit();
|
||||
|
||||
wxString server = "4242";
|
||||
|
||||
#if wxUSE_DDE_FOR_SAMPLE
|
||||
wxString hostName = wxGetHostName();
|
||||
#else
|
||||
wxString hostName = "localhost";
|
||||
#endif
|
||||
|
||||
if (argc > 1)
|
||||
server = argv[1];
|
||||
if (argc > 2)
|
||||
hostName = argv[2];
|
||||
|
||||
// Create a new client
|
||||
my_client = new MyClient;
|
||||
the_connection = (MyConnection *)my_client->MakeConnection(hostName, server, "IPC TEST");
|
||||
|
||||
if (!the_connection)
|
||||
{
|
||||
wxMessageBox("Failed to make connection to server", "Client Demo Error");
|
||||
#ifdef __WXMSW__
|
||||
// extern void wxPrintDDEError();
|
||||
// wxPrintDDEError();
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
if (!the_connection->StartAdvise("Item"))
|
||||
wxMessageBox("StartAdvise failed", "Client Demo Error");
|
||||
|
||||
frame->Show(TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int MyApp::OnExit()
|
||||
{
|
||||
if (my_client)
|
||||
delete my_client ;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(CLIENT_QUIT, MyFrame::OnExit)
|
||||
EVT_MENU(CLIENT_EXECUTE, MyFrame::OnExecute)
|
||||
EVT_MENU(CLIENT_POKE, MyFrame::OnPoke)
|
||||
EVT_MENU(CLIENT_REQUEST, MyFrame::OnRequest)
|
||||
EVT_CLOSE(MyFrame::OnCloseWindow)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// Define my frame constructor
|
||||
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size):
|
||||
wxFrame(frame, -1, title, pos, size)
|
||||
{
|
||||
panel = NULL;
|
||||
}
|
||||
|
||||
void MyFrame::OnExecute(wxCommandEvent& event)
|
||||
{
|
||||
if (the_connection)
|
||||
if (!the_connection->Execute("Hello from the client!"))
|
||||
wxMessageBox("Execute failed", "Client Demo Error");
|
||||
}
|
||||
|
||||
void MyFrame::OnPoke(wxCommandEvent& event)
|
||||
{
|
||||
if (the_connection)
|
||||
if (!the_connection->Poke("An item", "Some data to poke at the server!"))
|
||||
wxMessageBox("Poke failed", "Client Demo Error");
|
||||
}
|
||||
|
||||
void MyFrame::OnRequest(wxCommandEvent& event)
|
||||
{
|
||||
if (the_connection)
|
||||
{
|
||||
char *data = the_connection->Request("An item");
|
||||
if (data)
|
||||
wxMessageBox(data, "Client: Request", wxOK);
|
||||
else
|
||||
wxMessageBox("Request failed", "Client Demo Error");
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::OnExit(wxCommandEvent& event)
|
||||
{
|
||||
if (the_connection)
|
||||
the_connection->Disconnect();
|
||||
|
||||
this->Destroy();
|
||||
}
|
||||
|
||||
// Define the behaviour for the frame closing
|
||||
void MyFrame::OnCloseWindow(wxCloseEvent& event)
|
||||
{
|
||||
if (the_connection)
|
||||
{
|
||||
the_connection->Disconnect();
|
||||
}
|
||||
this->Destroy();
|
||||
}
|
||||
|
||||
MyClient::MyClient(void)
|
||||
{
|
||||
}
|
||||
|
||||
wxConnectionBase *MyClient::OnMakeConnection(void)
|
||||
{
|
||||
return new MyConnection;
|
||||
}
|
||||
|
||||
MyConnection::MyConnection(void):wxConnection(ipc_buffer, 3999)
|
||||
{
|
||||
}
|
||||
|
||||
MyConnection::~MyConnection(void)
|
||||
{
|
||||
the_connection = NULL;
|
||||
}
|
||||
|
||||
bool MyConnection::OnAdvise(const wxString& topic, const wxString& item, char *data, int size, wxIPCFormat format)
|
||||
{
|
||||
if (the_list)
|
||||
{
|
||||
int n = the_list->FindString(data);
|
||||
if (n > -1)
|
||||
the_list->SetSelection(n);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool MyConnection::OnDisconnect()
|
||||
{
|
||||
frame->Destroy();
|
||||
|
||||
the_connection = NULL;
|
||||
delete this;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
8
samples/ipc/client.def
Normal file
8
samples/ipc/client.def
Normal file
@@ -0,0 +1,8 @@
|
||||
NAME Client
|
||||
DESCRIPTION 'Client'
|
||||
EXETYPE WINDOWS
|
||||
STUB 'WINSTUB.EXE'
|
||||
CODE PRELOAD MOVEABLE DISCARDABLE
|
||||
DATA PRELOAD MOVEABLE MULTIPLE
|
||||
HEAPSIZE 1024
|
||||
STACKSIZE 8192
|
16
samples/ipc/client.g95
Normal file
16
samples/ipc/client.g95
Normal file
@@ -0,0 +1,16 @@
|
||||
#
|
||||
# File: makefile.g95
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) Julian Smart, 1999
|
||||
#
|
||||
# Makefile for wxWindows sample (Cygwin/Mingw32).
|
||||
|
||||
WXDIR = ../..
|
||||
|
||||
TARGET=client
|
||||
OBJECTS = $(TARGET).o
|
||||
|
||||
include $(WXDIR)/src/makeprog.g95
|
||||
|
55
samples/ipc/client.h
Normal file
55
samples/ipc/client.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: client.h
|
||||
// Purpose: DDE sample: client
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 25/01/99
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Define a new application
|
||||
class MyApp: public wxApp
|
||||
{
|
||||
public:
|
||||
bool OnInit();
|
||||
int OnExit();
|
||||
};
|
||||
|
||||
// Define a new frame
|
||||
class MyFrame: public wxFrame
|
||||
{
|
||||
public:
|
||||
wxPanel *panel;
|
||||
|
||||
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size);
|
||||
void OnCloseWindow(wxCloseEvent& event);
|
||||
void OnExit(wxCommandEvent& event);
|
||||
void OnExecute(wxCommandEvent& event);
|
||||
void OnPoke(wxCommandEvent& event);
|
||||
void OnRequest(wxCommandEvent& event);
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
class MyConnection: public wxConnection
|
||||
{
|
||||
public:
|
||||
MyConnection();
|
||||
~MyConnection();
|
||||
bool OnAdvise(const wxString& topic, const wxString& item, char *data, int size, wxIPCFormat format);
|
||||
bool OnDisconnect();
|
||||
};
|
||||
|
||||
class MyClient: public wxClient
|
||||
{
|
||||
public:
|
||||
MyClient();
|
||||
wxConnectionBase *OnMakeConnection();
|
||||
};
|
||||
|
||||
#define CLIENT_QUIT wxID_EXIT
|
||||
#define CLIENT_EXECUTE 2
|
||||
#define CLIENT_REQUEST 3
|
||||
#define CLIENT_POKE 4
|
||||
#define CLIENT_LISTBOX 200
|
2
samples/ipc/client.rc
Normal file
2
samples/ipc/client.rc
Normal file
@@ -0,0 +1,2 @@
|
||||
mondrian ICON "mondrian.ico"
|
||||
#include "wx/msw/wx.rc"
|
20
samples/ipc/client.vc
Normal file
20
samples/ipc/client.vc
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# File: makefile.vc
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) Julian Smart
|
||||
#
|
||||
# Makefile : Builds sample (VC++, WIN32)
|
||||
# Use FINAL=1 argument to nmake to build final version with no debug info.
|
||||
|
||||
# Set WXDIR for your system
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
PROGRAM=client
|
||||
OBJECTS = $(PROGRAM).obj
|
||||
|
||||
!include $(WXDIR)\src\makeprog.vc
|
||||
|
||||
client.obj: ddesetup.h
|
||||
|
15
samples/ipc/client.wat
Normal file
15
samples/ipc/client.wat
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
# Makefile for WATCOM
|
||||
#
|
||||
# Created by Julian Smart, January 1999
|
||||
#
|
||||
#
|
||||
|
||||
WXDIR = $(%WXWIN)
|
||||
|
||||
PROGRAM = client
|
||||
OBJECTS = $(PROGRAM).obj
|
||||
|
||||
!include $(WXDIR)\src\makeprog.wat
|
||||
|
||||
|
42
samples/ipc/ddesetup.h
Normal file
42
samples/ipc/ddesetup.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: ddesetup.h
|
||||
// Purpose: DDE sample settings
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 25/01/99
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* Adjust this before compiling, to switch between real DDE and TCP/IP
|
||||
* implementations.
|
||||
*/
|
||||
|
||||
// If 1, use real DDE. If 0, use TCP/IP
|
||||
|
||||
#ifdef __WXMSW__
|
||||
#define wxUSE_DDE_FOR_SAMPLE 1
|
||||
#else
|
||||
#define wxUSE_DDE_FOR_SAMPLE 0
|
||||
#endif
|
||||
|
||||
#if wxUSE_DDE_FOR_SAMPLE
|
||||
|
||||
#define wxConnection wxDDEConnection
|
||||
#define wxServer wxDDEServer
|
||||
#define wxClient wxDDEClient
|
||||
|
||||
#include <wx/dde.h>
|
||||
|
||||
#else
|
||||
|
||||
#define wxConnection wxTCPConnection
|
||||
#define wxServer wxTCPServer
|
||||
#define wxClient wxTCPClient
|
||||
|
||||
#include <wx/sckipc.h>
|
||||
|
||||
#endif
|
||||
|
82
samples/ipc/makefile.b32
Normal file
82
samples/ipc/makefile.b32
Normal file
@@ -0,0 +1,82 @@
|
||||
#
|
||||
# File: makefile.b32
|
||||
# Author: Guilhem Lavaux
|
||||
# Created: 1998
|
||||
# Updated:
|
||||
# Copyright: (c) Guilhem Lavaux
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile : Builds 32-bit wxSocket sample under BC++
|
||||
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
ZLIB = $(WXDIR)\lib\zlib.lib
|
||||
|
||||
!include $(WXDIR)\src\makeb32.env
|
||||
|
||||
WXLIBDIR = $(WXDIR)\lib
|
||||
WXINC = $(WXDIR)\include\msw
|
||||
WXLIB = $(WXLIBDIR)\wx32.lib
|
||||
LIBS=$(WXLIB) $(ZLIB) cw32 import32 ole2w32
|
||||
|
||||
!if "$(FINAL)" == "0"
|
||||
LINKFLAGS=/v /Tpe /L$(WXLIBDIR);$(BCCDIR)\lib
|
||||
OPT = -Od
|
||||
DEBUG_FLAGS= -v
|
||||
!else
|
||||
LINKFLAGS=/Tpe /L$(WXLIBDIR);$(BCCDIR)\lib
|
||||
OPT = -Od
|
||||
DEBUG_FLAGS =
|
||||
!endif
|
||||
CPPFLAGS=$(DEBUG_FLAGS) $(OPT) @$(CFG)
|
||||
|
||||
.$(SRCSUFF).obj:
|
||||
bcc32 $(CPPFLAGS) -c {$< }
|
||||
|
||||
.c.obj:
|
||||
bcc32 $(CPPFLAGS) -P- -c {$< }
|
||||
|
||||
CLIENT_TARGET=client
|
||||
SERVER_TARGET=server
|
||||
CLIENT_OBJECTS=client.obj
|
||||
SERVER_OBJECTS=server.obj
|
||||
|
||||
all: $(CLIENT_TARGET).exe $(SERVER_TARGET).exe
|
||||
|
||||
$(CLIENT_TARGET).exe: $(CLIENT_OBJECTS) $(CLIENT_TARGET).res
|
||||
tlink32 $(LINKFLAGS) @&&!
|
||||
c0w32.obj $(CLIENT_OBJECTS)
|
||||
$(CLIENT_TARGET)
|
||||
nul
|
||||
$(LIBS)
|
||||
$(CLIENT_TARGET).def
|
||||
$(CLIENT_TARGET).res
|
||||
!
|
||||
|
||||
client.obj: client.cpp
|
||||
|
||||
$(CLIENT_TARGET).res : $(CLIENT_TARGET).rc $(WXDIR)\include\wx\msw\wx.rc
|
||||
brc32 -r /i$(BCCDIR)\include /i$(WXDIR)\include $(CLIENT_TARGET)
|
||||
|
||||
$(SERVER_TARGET).exe: $(SERVER_OBJECTS) $(SERVER_TARGET).res
|
||||
tlink32 $(LINKFLAGS) @&&!
|
||||
c0w32.obj $(SERVER_OBJECTS)
|
||||
$(SERVER_TARGET)
|
||||
nul
|
||||
$(LIBS)
|
||||
$(SERVER_TARGET).def
|
||||
$(SERVER_TARGET).res
|
||||
!
|
||||
|
||||
server.obj: server.cpp
|
||||
|
||||
$(SERVER_TARGET).res: $(SERVER_TARGET).rc $(WXDIR)\include\wx\msw\wx.rc
|
||||
brc32 -r /i$(BCCDIR)\include /i$(WXDIR)\include $(SERVER_TARGET)
|
||||
|
||||
clean:
|
||||
-erase *.obj
|
||||
-erase *.exe
|
||||
-erase *.res
|
||||
-erase *.map
|
||||
-erase *.rws
|
19
samples/ipc/makefile.dos
Normal file
19
samples/ipc/makefile.dos
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# File: makefile.dos
|
||||
# Author: Julian Smart
|
||||
# Created: 1998
|
||||
# Updated:
|
||||
#
|
||||
# Makefile : Builds 16-bit sample, VC++ 1.5
|
||||
# Use FINAL=1 argument to nmake to build final version with no debugging
|
||||
# info
|
||||
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
TARGET=client
|
||||
OBJECTS = $(TARGET).obj
|
||||
|
||||
# TODO: server
|
||||
|
||||
!include $(WXDIR)\src\makeprog.msc
|
||||
|
19
samples/ipc/makefile.g95
Normal file
19
samples/ipc/makefile.g95
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# File: makefile.g95
|
||||
# Author: Julian Smart
|
||||
# Created: 1993
|
||||
# Updated:
|
||||
# Copyright: (c) 1993, AIAI, University of Edinburgh
|
||||
#
|
||||
# "%W% %G%"
|
||||
#
|
||||
# Makefile for server/client example (UNIX).
|
||||
|
||||
all:
|
||||
make -f client.g95 all
|
||||
make -f server.g95 all
|
||||
|
||||
clean:
|
||||
make -f client.g95 clean
|
||||
make -f server.g95 clean
|
||||
|
20
samples/ipc/makefile.vc
Normal file
20
samples/ipc/makefile.vc
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# File: makefile.vc
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) Julian Smart
|
||||
#
|
||||
# Makefile : Builds sample (VC++, WIN32)
|
||||
# Use FINAL=1 argument to nmake to build final version with no debug info.
|
||||
|
||||
!include $(WXWIN)/src/makevc.env
|
||||
|
||||
all:
|
||||
nmake -f server.vc FINAL=$(FINAL)
|
||||
nmake -f client.vc FINAL=$(FINAL)
|
||||
|
||||
clean:
|
||||
nmake -f server.vc clean
|
||||
nmake -f client.vc clean
|
||||
|
BIN
samples/ipc/mondrian.ico
Normal file
BIN
samples/ipc/mondrian.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 766 B |
44
samples/ipc/mondrian.xpm
Normal file
44
samples/ipc/mondrian.xpm
Normal file
@@ -0,0 +1,44 @@
|
||||
/* XPM */
|
||||
static char *mondrian_xpm[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"32 32 6 1",
|
||||
" c Black",
|
||||
". c Blue",
|
||||
"X c #00bf00",
|
||||
"o c Red",
|
||||
"O c Yellow",
|
||||
"+ c Gray100",
|
||||
/* pixels */
|
||||
" ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" oooooo +++++++++++++++++++++++ ",
|
||||
" ",
|
||||
" ++++++ ++++++++++++++++++ .... ",
|
||||
" ++++++ ++++++++++++++++++ .... ",
|
||||
" ++++++ ++++++++++++++++++ .... ",
|
||||
" ++++++ ++++++++++++++++++ .... ",
|
||||
" ++++++ ++++++++++++++++++ .... ",
|
||||
" ++++++ ++++++++++++++++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++++++++++++++++ ++++ ",
|
||||
" ++++++ ++++ ",
|
||||
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
||||
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
||||
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
||||
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
||||
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
||||
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
|
||||
" "
|
||||
};
|
198
samples/ipc/server.cpp
Normal file
198
samples/ipc/server.cpp
Normal file
@@ -0,0 +1,198 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: server.cpp
|
||||
// Purpose: DDE sample: server
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 25/01/99
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
|
||||
// Settings common to both executables: determines whether
|
||||
// we're using TCP/IP or real DDE.
|
||||
|
||||
#include "ddesetup.h"
|
||||
|
||||
#if defined(__WXGTK__) || defined(__WXMOTIF__)
|
||||
#include "mondrian.xpm"
|
||||
#endif
|
||||
|
||||
#include "server.h"
|
||||
|
||||
MyFrame *frame = NULL;
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
char ipc_buffer[4000];
|
||||
MyConnection *the_connection = NULL;
|
||||
MyServer *my_server ;
|
||||
|
||||
bool MyApp::OnInit()
|
||||
{
|
||||
// Create the main frame window
|
||||
frame = new MyFrame(NULL, "Server", wxDefaultPosition, wxSize(400, 500));
|
||||
|
||||
frame->CreateStatusBar();
|
||||
|
||||
// Give it an icon
|
||||
frame->SetIcon(wxICON(mondrian));
|
||||
|
||||
// Make a menubar
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
|
||||
file_menu->Append(SERVER_QUIT, "&Exit");
|
||||
|
||||
wxMenuBar *menu_bar = new wxMenuBar;
|
||||
|
||||
menu_bar->Append(file_menu, "&File");
|
||||
|
||||
// Associate the menu bar with the frame
|
||||
frame->SetMenuBar(menu_bar);
|
||||
|
||||
// Make a panel
|
||||
frame->panel = new wxPanel(frame, 0, 0, 400, 250);
|
||||
wxListBox *list = new wxListBox(frame->panel, SERVER_LISTBOX,
|
||||
wxPoint(5, 5), wxSize(150, 120));
|
||||
list->Append("Apple");
|
||||
list->Append("Pear");
|
||||
list->Append("Orange");
|
||||
list->Append("Banana");
|
||||
list->Append("Fruit");
|
||||
|
||||
frame->panel->Fit();
|
||||
frame->Fit();
|
||||
|
||||
wxString server_name = "4242";
|
||||
if (argc > 1)
|
||||
server_name = argv[1];
|
||||
|
||||
// Create a new server
|
||||
my_server = new MyServer;
|
||||
my_server->Create(server_name);
|
||||
frame->Show(TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(SERVER_QUIT, MyFrame::OnExit)
|
||||
EVT_CLOSE(MyFrame::OnCloseWindow)
|
||||
EVT_LISTBOX(SERVER_LISTBOX, MyFrame::OnListBoxClick)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// Define my frame constructor
|
||||
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size):
|
||||
wxFrame(frame, -1, title, pos, size)
|
||||
{
|
||||
panel = NULL;
|
||||
}
|
||||
|
||||
void MyFrame::OnExit(wxCommandEvent& event)
|
||||
{
|
||||
if (my_server)
|
||||
delete my_server;
|
||||
this->Destroy();
|
||||
}
|
||||
|
||||
// Set the client process's listbox to this item
|
||||
void MyFrame::OnListBoxClick(wxCommandEvent& event)
|
||||
{
|
||||
wxListBox* listBox = (wxListBox*) panel->FindWindow(SERVER_LISTBOX);
|
||||
if (listBox)
|
||||
{
|
||||
wxString value = listBox->GetStringSelection();
|
||||
if (the_connection)
|
||||
{
|
||||
the_connection->Advise("Item", (char*) (const char*) value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::OnCloseWindow(wxCloseEvent& event)
|
||||
{
|
||||
if (my_server)
|
||||
delete my_server;
|
||||
this->Destroy();
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(IPCDialogBox, wxDialog)
|
||||
EVT_BUTTON(SERVER_QUIT_BUTTON, IPCDialogBox::OnQuit)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
IPCDialogBox::IPCDialogBox(wxFrame *parent, const wxString& title,
|
||||
const wxPoint& pos, const wxSize& size, MyConnection *the_connection):
|
||||
wxDialog(parent, -1, title, pos, size)
|
||||
{
|
||||
connection = the_connection;
|
||||
(void)new wxButton(this, SERVER_QUIT_BUTTON, "Quit this connection", wxPoint(5, 5));
|
||||
Fit();
|
||||
}
|
||||
|
||||
void IPCDialogBox::OnQuit(wxCommandEvent& event)
|
||||
{
|
||||
connection->Disconnect();
|
||||
delete connection;
|
||||
}
|
||||
|
||||
wxConnectionBase *MyServer::OnAcceptConnection(const wxString& topic)
|
||||
{
|
||||
if (strcmp(topic, "STDIO") != 0 && strcmp(topic, "IPC TEST") == 0)
|
||||
return new MyConnection(ipc_buffer, 4000);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MyConnection::MyConnection(char *buf, int size):wxConnection(buf, size)
|
||||
{
|
||||
dialog = new IPCDialogBox(frame, "Connection", wxPoint(100, 100), wxSize(500, 500), this);
|
||||
dialog->Show(TRUE);
|
||||
the_connection = this;
|
||||
}
|
||||
|
||||
MyConnection::~MyConnection(void)
|
||||
{
|
||||
if (the_connection)
|
||||
{
|
||||
dialog->Destroy();
|
||||
the_connection = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool MyConnection::OnExecute(const wxString& topic, char *data, int size, wxIPCFormat format)
|
||||
{
|
||||
char buf[300];
|
||||
sprintf(buf, "Execute command: %s", data);
|
||||
frame->SetStatusText(buf);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool MyConnection::OnPoke(const wxString& topic, const wxString& item, char *data, int size, wxIPCFormat format)
|
||||
{
|
||||
char buf[300];
|
||||
sprintf(buf, "Poke command: %s", data);
|
||||
frame->SetStatusText(buf);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *MyConnection::OnRequest(const wxString& topic, const wxString& item, int *size, wxIPCFormat format)
|
||||
{
|
||||
return "Here, have your data, client!";
|
||||
}
|
||||
|
||||
bool MyConnection::OnStartAdvise(const wxString& topic, const wxString& item)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
8
samples/ipc/server.def
Normal file
8
samples/ipc/server.def
Normal file
@@ -0,0 +1,8 @@
|
||||
NAME Server
|
||||
DESCRIPTION 'Server'
|
||||
EXETYPE WINDOWS
|
||||
STUB 'WINSTUB.EXE'
|
||||
CODE PRELOAD MOVEABLE DISCARDABLE
|
||||
DATA PRELOAD MOVEABLE MULTIPLE
|
||||
HEAPSIZE 4096
|
||||
STACKSIZE 8192
|
16
samples/ipc/server.g95
Normal file
16
samples/ipc/server.g95
Normal file
@@ -0,0 +1,16 @@
|
||||
#
|
||||
# File: makefile.g95
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) Julian Smart, 1999
|
||||
#
|
||||
# Makefile for wxWindows sample (Cygwin/Mingw32).
|
||||
|
||||
WXDIR = ../..
|
||||
|
||||
TARGET=server
|
||||
OBJECTS = $(TARGET).o
|
||||
|
||||
include $(WXDIR)/src/makeprog.g95
|
||||
|
70
samples/ipc/server.h
Normal file
70
samples/ipc/server.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: server.h
|
||||
// Purpose: DDE sample: server
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 25/01/99
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Define a new application
|
||||
class MyApp: public wxApp
|
||||
{
|
||||
public:
|
||||
bool OnInit();
|
||||
};
|
||||
|
||||
DECLARE_APP(MyApp)
|
||||
|
||||
// Define a new frame
|
||||
class MyFrame: public wxFrame
|
||||
{
|
||||
public:
|
||||
wxPanel *panel;
|
||||
|
||||
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size);
|
||||
|
||||
void OnCloseWindow(wxCloseEvent& event);
|
||||
void OnExit(wxCommandEvent& event);
|
||||
void OnListBoxClick(wxCommandEvent& event);
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
class IPCDialogBox;
|
||||
class MyConnection: public wxConnection
|
||||
{
|
||||
public:
|
||||
IPCDialogBox *dialog;
|
||||
|
||||
MyConnection(char *buf, int size);
|
||||
~MyConnection();
|
||||
|
||||
bool OnExecute(const wxString& topic, char *data, int size, wxIPCFormat format);
|
||||
char *OnRequest(const wxString& topic, const wxString& item, int *size, wxIPCFormat format);
|
||||
bool OnPoke(const wxString& topic, const wxString& item, char *data, int size, wxIPCFormat format);
|
||||
bool OnStartAdvise(const wxString& topic, const wxString& item);
|
||||
};
|
||||
|
||||
class MyServer: public wxServer
|
||||
{
|
||||
public:
|
||||
wxConnectionBase *OnAcceptConnection(const wxString& topic);
|
||||
};
|
||||
|
||||
class IPCDialogBox: public wxDialog
|
||||
{
|
||||
public:
|
||||
MyConnection *connection;
|
||||
IPCDialogBox(wxFrame *parent, const wxString& title,
|
||||
const wxPoint& pos, const wxSize& size, MyConnection *the_connection);
|
||||
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
#define SERVER_QUIT wxID_EXIT
|
||||
#define SERVER_LISTBOX 500
|
||||
#define SERVER_QUIT_BUTTON 501
|
3
samples/ipc/server.rc
Normal file
3
samples/ipc/server.rc
Normal file
@@ -0,0 +1,3 @@
|
||||
mondrian ICON "mondrian.ico"
|
||||
#include "wx/msw/wx.rc"
|
||||
|
20
samples/ipc/server.vc
Normal file
20
samples/ipc/server.vc
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# File: makefile.vc
|
||||
# Author: Julian Smart
|
||||
# Created: 1999
|
||||
# Updated:
|
||||
# Copyright: (c) Julian Smart
|
||||
#
|
||||
# Makefile : Builds sample (VC++, WIN32)
|
||||
# Use FINAL=1 argument to nmake to build final version with no debug info.
|
||||
|
||||
# Set WXDIR for your system
|
||||
WXDIR = $(WXWIN)
|
||||
|
||||
PROGRAM=server
|
||||
OBJECTS = $(PROGRAM).obj
|
||||
|
||||
!include $(WXDIR)\src\makeprog.vc
|
||||
|
||||
server.obj: ddesetup.h
|
||||
|
15
samples/ipc/server.wat
Normal file
15
samples/ipc/server.wat
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
# Makefile for WATCOM
|
||||
#
|
||||
# Created by Julian Smart, January 1999
|
||||
#
|
||||
#
|
||||
|
||||
WXDIR = $(%WXWIN)
|
||||
|
||||
PROGRAM = server
|
||||
OBJECTS = $(PROGRAM).obj
|
||||
|
||||
!include $(WXDIR)\src\makeprog.wat
|
||||
|
||||
|
Reference in New Issue
Block a user