Article View: borland.public.cppbuilder.nativeapi
Article #9754Re: problems with GetCurrentThreadId(), GetWindowThreadProcessId()...
From: Remy Lebeau (TeamB)
Date: Mon, 14 Jun 2004 05:15
Date: Mon, 14 Jun 2004 05:15
84 lines
3986 bytes
3986 bytes
"Oren Halvani" <NoSpam@fdtd.com> wrote in message
news:40cd0458$1@newsgroups.borland.com...
> 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 !
You should use CreateProcess() instead of ShellExecute() when running
executables directly.
> 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 !
Did you write PCRE.exe yourself? If so, then I suggest you take a
completely different approach. I would suggest either:
1) rather than trying to send the text to the active window of PCRE, you
should use WM_COPYDATA to send the text to PCRE's main window directly, and
then let it decide where to put the received text regardless of the focus.
2) save the text to a temporary file and then simply pass the filename to
PCRE, such as a command line argument. Then PCRE can load the file at its
leisure and you don't have to use window messages at all.
> The RichEdit gets the Focus automaticly in PCRE-> Form->OnShow()
That may not be soon enough. Your main program is trying to send the text
before PCRE has a chance to fully finish its initialization. I suggest you
look at the WaitForInputIdle() function to make sure that PCRE has a chance
to finish its startup routines and is not doing anything else before you
then send it some text.
> Here's is the problem, I'm using the below TextSend( )
> function to send the Textfile to the "PCRE.exe" thread..
Why are you even using a separate executable to begin with? What is PCRE
doing that your main application can't simply do itself directly? Please
explain.
> The Textfile is getting sended into to Button(->Caption)
> that executes "PCRE.exe"
As well it should. See below.
> i've calling TextSEnd ( ) like this...
>
> TextSend("TFormPCRE", "My Textfile !!!!!!!!!!!!!!!!!");
>
> but, my TButton "cmdPCRE" (that executes "PCRE.exe") is
> getting the string
You use "TFormPCRE" to help determine which window to send the text to, but
then you are not actually sending the text to that window at at all.
> DWORD idAttach = GetCurrentThreadId();
> DWORD idAttachTo = GetWindowThreadProcessId(hwnd, NULL);
You are retreiving the thread IDs, but then you are not actually doing
anything with them.
> HWND hwndFocus = GetFocus();
You did not call AttachThreadInput(), so GetFocus() returns the active
window *in the calling process*, which is your main application, and its
active window is the button.
> if(hwndFocus != FALSE)
GetFocus() does not return a boolean, it returns a handle. That comparison
should be using NULL instead of FALSE:
if(hwndFocus != NULL)
> SendMessage(hwndFocus, WM_SETTEXT, 0,
> (LPARAM)(LPCTSTR)SendTxt.c_str());
Since you did not call AttachThreadInput(), you are retreiving the button's
HWND, thus you are sending the text to the button.
Gambit
Technical Details
Message-ID:
<40cd3589@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40cd0458$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,288e4db03c5a16db X-Google-Attributes: gid10cc67,public From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <40cd0458$1@newsgroups.borland.com> Subject: Re: problems with GetCurrentThreadId(), GetWindowThreadProcessId()... Date: Sun, 13 Jun 2004 22:15:53 -0700 Lines: 86 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.169.168.124 Message-ID: <40cd3589@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1087190409 68.169.168.124 (13 Jun 2004 22:20:09 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail