home *** CD-ROM | disk | FTP | other *** search
- /*+==========================================================================
- File: SendEdit.cpp
-
- Summary: Extends the default functionality of the DataEdit control
- by forwarding characters typed by the user to a Socket.
-
- Classes: SendEdit
-
- Functions: SetClientConnection, WndProc, OnChar
-
- ----------------------------------------------------------------------------
- This file is part of the Microsoft NGWS Samples.
-
- Copyright (C) 1998-1999 Microsoft Corporation. All rights reserved.
- ==========================================================================+*/
-
- #using <mscorlib.dll>
- #using <System.DLL>
- #using <System.WinForms.DLL>
- #using <System.Net.DLL>
- #using <System.Drawing.DLL>
- #using <Microsoft.Win32.Interop.DLL>
-
- using namespace System;
- using namespace System::Core;
- using namespace System::WinForms;
- using namespace System::Net;
- using namespace System::Net::Sockets;
- using namespace Microsoft::Win32::Interop;
-
- #define NULL 0
-
- #include "SendEdit.h"
-
- /*****************************************************************************
- Constructor : SendEdit
-
- Abstract: Constructs an instance of SendEdit.
-
- Input Parameters: (none)
-
- ******************************************************************************/
- SendEdit::SendEdit() : ClientConnection(NULL)
- {
- Console::WriteLine("SendEdit Box created");
- }
-
- /*****************************************************************************
- Function: SetClientConnection
-
- Abstract: Sets the socket used for sending keystroke information to.
-
- Input Parameters: s(Socket)
-
- Returns: void
- ******************************************************************************/
- void SendEdit::SetClientConnection(Socket *s)
- {
- ClientConnection = s;
- }
-
- /*****************************************************************************
- Function: WndProc
-
- Abstract: Override of the WndProc for this Edit control. Used to
- process the WM_CHAR event.
-
- Input Parameters: m(Message)
-
- Returns: void
- ******************************************************************************/
- void SendEdit::WndProc(Message *m)
- {
- switch (m->msg) {
- case Microsoft::Win32::Interop::win::WM_CHAR:
- if (OnChar(m->wParam,m->lParam&0xFFFF,(m->lParam>>16)&0xFFFF))
- return;
- }
- DataEdit::WndProc(m);
- }
-
- /*****************************************************************************
- Function: OnChar
-
- Abstract: Called by the WndProc whenever a character is typed. The
- character is sent to the Socket hosted by this control.
-
- Input Parameters: nChar(int), nRepCnt(int), nFlags(int)
-
- Returns: bool
- ******************************************************************************/
- bool SendEdit::OnChar(int nChar, int nRepCnt, int nFlags)
- {
- try {
- if (ClientConnection == NULL) {
- MessageBox::Show(String::Concat(S"No connection present. Please click ",
- S"\"Connect\" button to make a connection"),S"WinTalk");
- return false;
- }
-
- wchar_t c = (wchar_t)nChar;
- Char b[] = new Char[1];
- b[0] = (Char)nChar;
- Console::WriteLine(b);
-
- // create a String for appending to edit control
- String *str = NULL;
- if (c >= L' ' || c == L'\t') {
- wchar_t *wt = new wchar_t[1];
- wt[0] = c;
- str = new String(wt);
- } else if (c == L'\r') {
- str = S"\r\n";
- } else if (c != L'\b') { // throw out control characters
- return false;
- }
-
- for (int i = 0; i < nRepCnt; i++) {
- ClientConnection->Send(b, b->Length, 0);
- if (c == L'\b') {
- TruncateOneCharFromEnd();
- } else {
- Append(str);
- }
- }
- }
- catch (Exception *e) {}
-
- return false; // we want the default handler to be called
- }
-
-