🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #4295

Re: Create Several TClientSocket C++ Builder

#4295
From: Hans Galema
Date: Thu, 03 Mar 2005 13:47
67 lines
2742 bytes
Hans Galema wrote:

> But I still advise you to make the startapp. That is definitely
> less work.

As I thougth that that was a good idea I constructed one myself.
Just two TEdit's for application path and number of clients to open.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   AnsiString FileName = Edit1->Text;

   int maxclients = StrToInt ( Edit2->Text );

   int clientnr = -1;
   while ( ++clientnr < maxclients )
     {
     AnsiString UserName = "sipahi" + IntToStr ( clientnr );

     HINSTANCE hinstance = ShellExecute (
         NULL
         ,"open"
         ,FileName.c_str()
         ,UserName.c_str()
         ,NULL
         ,SW_SHOWNORMAL
         );

     if ( (int)hinstance <= 32 )
      break;
     }
}

But then if there are so many clients: how to close them ?

My clients put the filename in their caption besides other things.

To close them:

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  AnsiString FileName = ExtractFileName ( Edit1->Text );

  AnsiString ClientCaption = ChangeFileExt ( FileName, "" );

  HWND hwnddesktop = GetDesktopWindow();
  HWND hwnd = FindWindowEx(hwnddesktop, 0, 0, 0);

  while( hwnd )
   {
    char buffer[128];

    GetWindowText(hwnd, buffer, sizeof(buffer));

    if ( buffer [0] )
      {
      if ( AnsiString ( buffer ).Pos ( ClientCaption ) )
         SendMessage ( hwnd, WM_CLOSE, 0, 0 );

      // that was case sensitive!
      }

    hwnd = FindWindowEx(hwnddesktop, hwnd, 0, 0);
   }
}

Hans.
Technical Details
Message-ID: <422715ca@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!tdsnet-transit!newspeer.tds.net!38.119.100.82.MISMATCH!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <4225d0f1@newsgroups.borland.com> <4225f97d$1@newsgroups.borland.com> <4226d6c7$1@newsgroups.borland.com> <4226e881$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,dd6db4c120873d11
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Thu, 03 Mar 2005 14:47:14 +0100
From: Hans Galema <notused@notused.nl>
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Re: Create Several TClientSocket C++ Builder
References: <4225d0f1@newsgroups.borland.com> <4225f97d$1@newsgroups.borland.com> <4226d6c7$1@newsgroups.borland.com> <4226e881$1@newsgroups.borland.com>
In-Reply-To: <4226e881$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 129.125.201.248
Message-ID: <422715ca@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1109857738 129.125.201.248 (3 Mar 2005 05:48:58 -0800)
Lines: 67
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!tdsnet-transit!newspeer.tds.net!38.119.100.82.MISMATCH!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail