home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / Wintalk / VC / ConnectDialog.cpp next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  5.2 KB  |  169 lines

  1. /*+==========================================================================
  2.   File:      ConnectDialog.cpp
  3.  
  4.   Summary:   WFC Dialog (implementation through the Form class).  This 
  5.              window displays two edit boxes (host and port), and OK and 
  6.              Cancel buttons.  OnCommand is overrided to correctly handle 
  7.              events when the respective buttons are clicked.
  8.  
  9.   Classes:   ConnectDialog
  10.  
  11.   Functions: Dispose, button1_click, ConnectDialog_closing, InitForm
  12.              
  13. ----------------------------------------------------------------------------
  14.   This file is part of the Microsoft NGWS Samples.
  15.  
  16.   Copyright (C) 1998-1999 Microsoft Corporation.  All rights reserved.
  17. ==========================================================================+*/
  18.  
  19. #using <mscorlib.dll>
  20. #using <System.DLL>
  21. #using <System.WinForms.DLL>
  22. #using <System.Drawing.DLL>
  23. #using <Microsoft.Win32.Interop.DLL>
  24.  
  25. using namespace System;
  26. using namespace System::WinForms;
  27. using namespace System::ComponentModel;
  28. using namespace System::Drawing;
  29.  
  30. #define NULL 0
  31.  
  32. #include "ConnectDialog.h"
  33.  
  34. /*****************************************************************************
  35.  Function :    Dispose
  36.  
  37.  Abstract:     Overrides Form.Dispose, cleans up the component list.
  38.             
  39.  Input Parameters: (None)
  40.  
  41.  Returns: void
  42. ******************************************************************************/
  43.     void ConnectDialog::Dispose()
  44.     {
  45.         Form::Dispose();
  46.         components->Dispose();
  47.     }
  48.  
  49. /*****************************************************************************
  50.  Function :    button1_click
  51.  
  52.  Abstract:     Invoked when the "Connect" button is clicked.  Validates input
  53.                and stores the host and port information into member 
  54.                variables.
  55.             
  56.  Input Parameters: source(Object), e(EventArgs)
  57.  
  58.  Returns: Void
  59. ******************************************************************************/
  60.     void ConnectDialog::button1_click(Object *source, EventArgs *e)
  61.     {
  62.         host = edit1->Text->Trim();
  63.         if (host->Equals(S"")) {
  64.             AllowClose = false;
  65.             MessageBox::Show(this,S"Please enter a valid host",S"Wintalk");
  66.             return;
  67.         }
  68.         Console::WriteLine(String::Concat(S"host = ", host));
  69.         try {
  70.             port = Convert::ToInt32(edit2->Text);
  71.         }
  72.         catch (Exception *ex) {
  73.             AllowClose = false;
  74.             MessageBox::Show(this,S"Please enter a valid port number",S"Wintalk");
  75.             return;
  76.         }
  77.         Console::WriteLine(String::Concat(S"port = ", port.ToString()));
  78.     }
  79.  
  80. /*****************************************************************************
  81.  Function:     ConnectDialog_closing
  82.  
  83.  Abstract:     Invoked when the ConnectDialog is closing.  
  84.             
  85.  Input Parameters: source(Object), e(EventArgs)
  86.  
  87.  Returns: Void
  88. ******************************************************************************/
  89.     void ConnectDialog::ConnectDialog_closing(Object *source, CancelEventArgs *e)
  90.     {
  91.         if (!AllowClose) {
  92.             e->Cancel = true;
  93.             AllowClose = true;
  94.         }
  95.     }
  96.     
  97.  
  98.  
  99. /*****************************************************************************
  100.  Function :    InitForm
  101.  
  102.  Abstract:     Creates UI elements (buttons, edit controls, ...) on the 
  103.                ConnectDialog WFC form.
  104.             
  105.  Input Parameters: None
  106.  
  107.  Returns: Void
  108. ******************************************************************************/
  109.     void ConnectDialog::InitForm()
  110.     {
  111.         label1->Location = *new Point(11, 12);
  112.         label1->Size = *new System::Drawing::Size(*new Point(30, 13));
  113.         label1->TabIndex = 4;
  114.         label1->TabStop = false;
  115.         label1->Text = S"Host:";
  116.  
  117.         edit1->Location = *new Point(46, 8);
  118.         edit1->Size = *new System::Drawing::Size(*new Point(245, 20));
  119.         edit1->TabIndex = 0;
  120.         edit1->Text = S"localhost";
  121.  
  122.         label2->Location = *new Point(11, 38);
  123.         label2->Size = *new System::Drawing::Size(*new Point(30, 13));
  124.         label2->TabIndex = 5;
  125.         label2->TabStop = false;
  126.         label2->Text = S"Port:";
  127.  
  128.         edit2->Location = *new Point(46, 34);
  129.         edit2->Size = *new System::Drawing::Size(*new Point(71, 20));
  130.         edit2->TabIndex = 1;
  131.         edit2->Text = S"5000";
  132.  
  133.         button1->Location = *new Point(56, 67);
  134.         button1->Size = *new System::Drawing::Size(*new Point(81, 22));
  135.         button1->TabIndex = 2;
  136.         button1->Text = S"Connect";
  137.         button1->DialogResult = DialogResult::OK;
  138.         button1->AddOnClick(new EventHandler(this, &ConnectDialog::button1_click));
  139.  
  140.         button2->Location = *new Point(164, 67);
  141.         button2->Size = *new System::Drawing::Size(*new Point(81, 22));
  142.         button2->TabIndex = 3;
  143.         button2->Text = S"Cancel";
  144.         button2->DialogResult = DialogResult::Cancel;
  145.  
  146.         this->Text = S"Connect";
  147.         this->AcceptButton = button1;
  148.         this->AutoScaleBaseSize = *new System::Drawing::Size(*new Point(5, 13));
  149.         this->BorderStyle = FormBorderStyle::FixedSingle;
  150.         this->CancelButton = button2;
  151.         this->ClientSize = *new System::Drawing::Size(*new Point(300, 95));
  152.         this->MaximizeBox = false;
  153.         this->MinimizeBox = false;
  154.         this->ShowInTaskbar = false;
  155.         this->StartPosition = FormStartPosition::CenterParent;
  156.         this->AddOnClosing(new CancelEventHandler(this, &ConnectDialog::ConnectDialog_closing));
  157.  
  158.         Control *c[] = new Control*[6];
  159.         c[0] = button2;
  160.         c[1] = button1;
  161.         c[2] = edit2;
  162.         c[3] = label2;
  163.         c[4] = edit1;
  164.         c[5] = label1;
  165.  
  166.         this->Controls->All = c;
  167.     }
  168.  
  169.