Advertisement
Guest User

Visual C++

a guest
Jan 16th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.42 KB | None | 0 0
  1. #pragma once
  2. //#pragma comment (lib, "ws2_32.lib")
  3. #include "wcomm.h"
  4. //#include <string>
  5. #include "pthreads/pthread.h"
  6.  
  7. namespace Transfer_pliku_VC {
  8.  
  9.     using namespace std;
  10.     using namespace System;
  11.     using namespace System::ComponentModel;
  12.     using namespace System::Collections;
  13.     using namespace System::Windows::Forms;
  14.     using namespace System::Data;
  15.     using namespace System::Drawing;
  16.     using namespace System::Threading;
  17.  
  18.     /// <summary>
  19.     /// Summary for Form1
  20.     ///
  21.     /// WARNING: If you change the name of this class, you will need to change the
  22.     ///          'Resource File Name' property for the managed resource compiler tool
  23.     ///          associated with all .resx files this class depends on.  Otherwise,
  24.     ///          the designers will not be able to interact properly with localized
  25.     ///          resources associated with this form.
  26.     /// </summary>
  27.     public ref class Form1 : public System::Windows::Forms::Form
  28.     {
  29.     public:
  30.         Form1(void)
  31.         {
  32.             InitializeComponent();
  33.  
  34.             void runserver();
  35.             linkLabel1->Text = "Upuść plik tutaj lub -->";
  36.             linkLabel1->LinkColor = System::Drawing::Color::Black;
  37.  
  38.             //
  39.             //TODO: Add the constructor code here
  40.             //
  41.         }
  42.  
  43.     protected:
  44.         /// <summary>
  45.         /// Clean up any resources being used.
  46.         /// </summary>
  47.         ~Form1()
  48.         {
  49.             if (components)
  50.             {
  51.                 delete components;
  52.             }
  53.         }
  54.  
  55.     protected:
  56.     private: System::Windows::Forms::Button^  button1;
  57.     private: System::Windows::Forms::OpenFileDialog^  openFileDialog1;
  58.     private: System::Windows::Forms::LinkLabel^  linkLabel1;
  59.     private: System::Windows::Forms::Label^  label1;
  60.  
  61.  
  62.     private:
  63.         /// <summary>
  64.         /// Required designer variable.
  65.         /// </summary>
  66.         System::ComponentModel::Container ^components;
  67.  
  68.     private:
  69.         void ThreadTask()
  70.         {
  71.             WComm *w = new WComm();
  72.             w->startServer(27015);
  73.         while (true) {
  74.             // Wait until a client connects
  75.             w->waitForClient();
  76.        
  77.             // Work with client
  78.             while(true)
  79.             {
  80.                 char rec[50] = "";
  81.                 w->recvData(rec,32);w->sendData("OK");
  82.  
  83.                 if(strcmp(rec,"FileSend")==0)
  84.                 {
  85.                     char fname[32] ="";
  86.                     w->fileReceive(fname);
  87.                     printf("File Received.........\n");
  88.                 }
  89.  
  90.                 if(strcmp(rec,"EndConnection")==0)break;
  91.             printf("Connection Ended......\n");
  92.             }
  93.             // Disconnect client
  94.             w->closeConnection();
  95.         }
  96. }
  97.  
  98. #pragma region Windows Form Designer generated code
  99.         /// <summary>
  100.         /// Required method for Designer support - do not modify
  101.         /// the contents of this method with the code editor.
  102.         /// </summary>
  103.         void InitializeComponent(void)
  104.         {
  105.             this->button1 = (gcnew System::Windows::Forms::Button());
  106.             this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
  107.             this->linkLabel1 = (gcnew System::Windows::Forms::LinkLabel());
  108.             this->label1 = (gcnew System::Windows::Forms::Label());
  109.             this->SuspendLayout();
  110.             //
  111.             // button1
  112.             //
  113.             this->button1->Location = System::Drawing::Point(197, 12);
  114.             this->button1->Name = L"button1";
  115.             this->button1->Size = System::Drawing::Size(75, 23);
  116.             this->button1->TabIndex = 1;
  117.             this->button1->Text = L"Wczytaj plik";
  118.             this->button1->UseVisualStyleBackColor = true;
  119.             this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
  120.             //
  121.             // openFileDialog1
  122.             //
  123.             this->openFileDialog1->FileName = L"openFileDialog1";
  124.             //
  125.             // linkLabel1
  126.             //
  127.             this->linkLabel1->AutoSize = true;
  128.             this->linkLabel1->Location = System::Drawing::Point(12, 17);
  129.             this->linkLabel1->Name = L"linkLabel1";
  130.             this->linkLabel1->Size = System::Drawing::Size(55, 13);
  131.             this->linkLabel1->TabIndex = 2;
  132.             this->linkLabel1->TabStop = true;
  133.             this->linkLabel1->Text = L"linkLabel1";
  134.             this->linkLabel1->LinkClicked += gcnew System::Windows::Forms::LinkLabelLinkClickedEventHandler(this, &Form1::linkLabel1_LinkClicked);
  135.             //
  136.             // label1
  137.             //
  138.             this->label1->AutoSize = true;
  139.             this->label1->Location = System::Drawing::Point(13, 237);
  140.             this->label1->Name = L"label1";
  141.             this->label1->Size = System::Drawing::Size(35, 13);
  142.             this->label1->TabIndex = 3;
  143.             this->label1->Text = L"label1";
  144.             this->label1->Visible = false;
  145.             //
  146.             // Form1
  147.             //
  148.             this->AllowDrop = true;
  149.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  150.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  151.             this->ClientSize = System::Drawing::Size(284, 262);
  152.             this->Controls->Add(this->label1);
  153.             this->Controls->Add(this->linkLabel1);
  154.             this->Controls->Add(this->button1);
  155.             this->Name = L"Form1";
  156.             this->Text = L"Form1";
  157.             this->DragDrop += gcnew System::Windows::Forms::DragEventHandler(this, &Form1::Form1_DragDrop);
  158.             this->DragEnter += gcnew System::Windows::Forms::DragEventHandler(this, &Form1::Form1_DragEnter);
  159.             this->ResumeLayout(false);
  160.             this->PerformLayout();
  161.  
  162.         }
  163. #pragma endregion
  164.     private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
  165.                  openFileDialog1->FileName = "";
  166.                  if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
  167.                  {
  168.                      {linkLabel1->Text = System::IO::Path::GetFileName(openFileDialog1->FileName);}
  169.                      label1->Text = openFileDialog1->FileName;
  170.                      //{linkLabel1->Text = System::IO::Path::GetFileName(files[0]);}
  171.                  }
  172.              }
  173.     private: System::Void linkLabel1_LinkClicked(System::Object^  sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^  e) {
  174.                  if (linkLabel1->Text != "Upuść plik tutaj lub -->")
  175.                     //System::Diagnostics::Process::Start(openFileDialog1->FileName);
  176.                     System::Diagnostics::Process::Start(label1->Text);
  177.              }
  178.     private: System::Void Form1_DragEnter(System::Object^  sender, System::Windows::Forms::DragEventArgs^  e) {
  179.                  // make sure they're actually dropping files (not text or anything else)
  180.                  if( e->Data->GetDataPresent(DataFormats::FileDrop, false))
  181.                     // allow them to continue
  182.                     // (without this, the cursor stays a "NO" symbol
  183.                     e->Effect = DragDropEffects::All;
  184.                  else
  185.                     e->Effect = DragDropEffects::Copy;
  186.              }
  187. private: System::Void Form1_DragDrop(System::Object^  sender, System::Windows::Forms::DragEventArgs^  e) {
  188.              array<String^>^files = (array<String^>^)e->Data->GetData( DataFormats::FileDrop );
  189.              //linkLabel1->Text = (System::String ^)e->Data->GetData(DataFormats::FileDrop);
  190.              label1->Text = files[0];
  191.              linkLabel1->Text = System::IO::Path::GetFileName(files[0]);
  192.              linkLabel1->LinkColor = System::Drawing::Color::Blue;
  193.          }
  194. };
  195.  
  196.  
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement