🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #9752

problems with GetCurrentThreadId(), GetWindowThreadProcessId()...

#9752
From: Oren Halvani
Date: Mon, 14 Jun 2004 01:51
82 lines
3464 bytes
hi dear builders,

i've got a complicated problem...i've integrated into my application
another programm that calls "PCRE.exe" i save it to disk, than i'll
execute it via: ShellExecute( )...works great, "PCRE.exe" executes
prety well !

OK..now i need to send a Textfile from my< main-application
into the "PCRE.exe" programm..to be more specify: Into it's RichEdit->Text !
The RichEdit gets the Focus automaticly in PCRE-> Form->OnShow()

Here's is the problem, I'm using the below TextSend( ) function to send
the Textfile to the "PCRE.exe" thread..

It doesn't get the Textfile into the RichEdit..BUT my main-application does
!
The Textfile is getting sended into to Button(->Caption) that executes
"PCRE.exe"

Whats exactly going on here...?

I've checked for the ClassName of "PCRE.exe" , it was "TFormPCRE"
so i've calling TextSEnd ( ) like this...

    TextSend("TFormPCRE", "My Textfile !!!!!!!!!!!!!!!!!");

but, my TButton "cmdPCRE" (that executes "PCRE.exe") is getting
the string "My Textfile !!!!!!!!!!!!!!!!!" NOT "PCRE.exe"->RichEdit->Text !!

Why ? Hope someone can help....


Oren

/***********************************************************/
void TextSend(AnsiString ClassName, AnsiString SendTxt)
{
  HWND hwndPrev  = GetForegroundWindow();
  HWND hwnd      = FindWindow(ClassName.c_str(), 0);
  SetForegroundWindow(hwnd);

  DWORD idAttach   = GetCurrentThreadId();
  DWORD idAttachTo = GetWindowThreadProcessId(hwnd, NULL);

  HWND hwndFocus = GetFocus();
  if(hwndFocus != FALSE) SendMessage(hwndFocus, WM_SETTEXT, 0,
(LPARAM)(LPCTSTR)SendTxt.c_str());
  SetForegroundWindow(hwndPrev);

  /*if(AttachThreadInput(idAttach, idAttachTo, true) == false)
  {
     ShowMessage("not sucessfull !");
  }
  if(AttachThreadInput(idAttach, idAttachTo, false) == false)
  {
     ShowMessage("sucessfull !");
  }*/
}

void __fastcall TForm1::cmdPCREClick(TObject *Sender)
{
   char TempDir[MAX_PATH +1]; TempDir[MAX_PATH] = '\0';
   GetTempPath(MAX_PATH,TempDir);

   String x = "PCRE.exe", str = TempDir + x;
   SaveResourceToFile(str.c_str(),"PCRE"); // my function that saves the
module to windows temp folder..

   // OK...now execute the module...(PCRE.exe)

   HINSTANCE ReturnCode =
ShellExecute(Handle,NULL,str.c_str(),NULL,NULL,SW_NORMAL);
   if((int)ReturnCode <= 32)
   {
      ShellExecute(Handle,NULL,str.c_str(),NULL,NULL,SW_NORMAL);
   }

   // no problem untill here...

   TextSend("TFormPCRE", "My Textfile !!!!!!!!!!!!!!!!!"); // TFormPCRE is
the ClassName..!
}
Technical Details
Message-ID: <40cd0458$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,288e4db03c5a16db,start
X-Google-Attributes: gid10cc67,public
Reply-To: "Oren Halvani" <NoSpam@fdtd.com>
From: "Oren Halvani" <NoSpam@fdtd.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: problems with GetCurrentThreadId(), GetWindowThreadProcessId()...
Date: Mon, 14 Jun 2004 03:51:24 +0200
Lines: 84
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 217.234.104.3
Message-ID: <40cd0458$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1087177816 217.234.104.3 (13 Jun 2004 18:50:16 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail