⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webserv1.cpp

📁 文件名称:新曦 我的资源 搜索软件 源程序(Borland Delphi 7)说明
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*---------------------------------------------------------------------------

Author:       Fran鏾is PIETTE
Creation:     April 23, 2000
Description:  WebSrv1 show how to use THttpServer component to implement
              a web server.
Version:      1.00 BETA (From Delphi version dated Oct 10, 1999)
EMail:        http://users.swing.be/francois.piette  francois.piette@swing.be
              http://www.rtfm.be/fpiette             francois.piette@rtfm.be
              francois.piette@pophost.eunet.be
Support:      Use the mailing list twsocket@rtfm.be See website for details.
Legal issues: Copyright (C) 1999 by Fran鏾is PIETTE
              Rue de Grady 24, 4053 Embourg, Belgium. Fax: +32-4-365.74.56
              <francois.piette@pophost.eunet.be><francois.piette@swing.be>

              This software is provided 'as-is', without any express or
              implied warranty.  In no event will the author be held liable
              for any  damages arising from the use of this software.

              Permission is granted to anyone to use this software for any
              purpose, including commercial applications, and to alter it
              and redistribute it freely, subject to the following
              restrictions:

              1. The origin of this software must not be misrepresented,
                 you must not claim that you wrote the original software.
                 If you use this software in a product, an acknowledgment
                 in the product documentation would be appreciated but is
                 not required.

              2. Altered source versions must be plainly marked as such, and
                 must not be misrepresented as being the original software.

              3. This notice may not be removed or altered from any source
                 distribution.

              4. You must register this software by sending a picture postcard
                 to the author. Use a nice stamp and mention your name, street
                 address, EMail address and any comment you like to say.

History:


---------------------------------------------------------------------------*/

#if __BORLANDC__ == 0x520     // BCB1 is BC5.20   BCB3 is BC5.30
    #define _WINSOCKAPI_      // Prevent winsock.h from being included
    #define s_addr S_addr
#endif
#include <vcl.h>
#include <vcl\inifiles.hpp>
#pragma hdrstop

#include "WebServ1.h"
#define  CopyRight "WebServ (c) 1999-2000 F. Piette V1.00 BETA "
// IniFile layout for persistent data
#define SectionWindow      "WindowMain"
#define KeyTop             "Top"
#define KeyLeft            "Left"
#define KeyWidth           "Width"
#define KeyHeight          "Height"
#define SectionData        "Data"
#define KeyDocDir          "DocDir"
#define KeyDefaultDoc      "DefaultDoc"
#define KeyPort            "Port"
#define KeyDisplayHeader   "DisplayHeader"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "WSocket"
#pragma link "HttpSrv"
#pragma resource "*.dfm"
TAppBaseForm *AppBaseForm;
//---------------------------------------------------------------------------
__fastcall TAppBaseForm::TAppBaseForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
// We need to override parent class destructor because we have allocated
// memory for our data buffer.
__fastcall TMyHttpConnection::~TMyHttpConnection()
{
    if (FPostedDataBuffer != NULL) {
        free(FPostedDataBuffer);
        FPostedDataBuffer = NULL;
        FPostedDataSize   = 0;
    }
}
//---------------------------------------------------------------------------
void __fastcall TAppBaseForm::FormCreate(TObject *Sender)
{
    // Create IniFileName based on EXE file name
    FIniFileName = LowerCase(ExtractFileName(Application->ExeName));
    FIniFileName = FIniFileName.SubString(1, FIniFileName.Length() - 3) + "ini";
}
//---------------------------------------------------------------------------
void __fastcall TAppBaseForm::FormShow(TObject *Sender)
{
    TIniFile    *IniFile;
    WSAData     wsi;

    if (!FInitialized) {
        FInitialized     = TRUE;
        IniFile          = new TIniFile(FIniFileName);
        Top              = IniFile->ReadInteger(SectionWindow, KeyTop,    Top);
        Left             = IniFile->ReadInteger(SectionWindow, KeyLeft,   Left);
        Width            = IniFile->ReadInteger(SectionWindow, KeyWidth,  Width);
        Height           = IniFile->ReadInteger(SectionWindow, KeyHeight, Height);
        DocDirEdit->Text     = IniFile->ReadString(SectionData, KeyDocDir,
                                                  "c:\WwwRoot");
        DefaultDocEdit->Text = IniFile->ReadString(SectionData, KeyDefaultDoc,
                                                  "index.html");
        PortEdit->Text       = IniFile->ReadString(SectionData, KeyPort,
                                                  "80");
        DisplayHeaderCheckBox->Checked =
                IniFile->ReadInteger(SectionData, KeyDisplayHeader, 0);
        delete IniFile;
        DisplayMemo->Clear();
        // Initialize client count caption
        ClientCountLabel->Caption = "0";
        // Display version info for program and use components
        wsi = WinsockInfo();
        Display(CopyRight);
        Display("Using:");
//        Display("   " + Wsocket::CopyRight);
//        Display("   " + Wsockets::CopyRight);
//        Display("   " + Httpsrv::CopyRight);
        Display("    Winsock:");
        Display(Format("        Version %d.%d",
                       ARRAYOFCONST((wsi.wHighVersion >> 8,
                                     wsi.wHighVersion & 15))));
        Display(Format("        %s", ARRAYOFCONST((&wsi.szDescription[0]))));
        Display(Format("        %s", ARRAYOFCONST((&wsi.szSystemStatus[0]))));
        if (wsi.lpVendorInfo != NULL)
            Display(Format("        %s", ARRAYOFCONST((wsi.lpVendorInfo))));
        // Automatically start server
        StartButtonClick(this);
    }
}
//---------------------------------------------------------------------------
void __fastcall TAppBaseForm::FormClose(TObject *Sender,
      TCloseAction &Action)
{
    TIniFile *IniFile;

    IniFile = new TIniFile(FIniFileName);
    IniFile->WriteInteger(SectionWindow, KeyTop,    Top);
    IniFile->WriteInteger(SectionWindow, KeyLeft,   Left);
    IniFile->WriteInteger(SectionWindow, KeyWidth,  Width);
    IniFile->WriteInteger(SectionWindow, KeyHeight, Height);
    IniFile->WriteString(SectionData,    KeyDocDir,      HttpServer1->DocDir);
    IniFile->WriteString(SectionData,    KeyDefaultDoc,  HttpServer1->DefaultDoc);
    IniFile->WriteString(SectionData,    KeyPort,        HttpServer1->Port);
    IniFile->WriteInteger(SectionData,   KeyDisplayHeader,
                                         DisplayHeaderCheckBox->Checked);
    delete IniFile;
}
//---------------------------------------------------------------------------
// Display a message in our display memo. Delete lines to be sure to not
// overflow the memo which may have a limited capacity.
void __fastcall TAppBaseForm::Display(AnsiString Msg)
{
    int I;

    DisplayMemo->Lines->BeginUpdate();
    if (DisplayMemo->Lines->Count > 200) {
        for (I = 1; I <= 50; I++)
            DisplayMemo->Lines->Delete(0);
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -