Board index » delphi » Using Windows messages w/ Delphi and an external app

Using Windows messages w/ Delphi and an external app

I'm fairly new to programming with Delphi and Windows, so this may seem
rather obvious (I hope) to someone out there:

I'm trying to use "Windows Messages" to send a message to the CC:Mail
Background program. According to the docs on the Background program, the
message I need to send is "WM_USER+203" and I need to send "4" for the
"wParam" value. So in Delphi, I created this:

ShellExecute(handle, 'open', 'CCBKGRND.EXE', 'C:\CCMOBILE\CCDATA2 "login
name" password', 'C:\ccmobile', SW_SHOWNORMAL);   //this opens the
Background program

PostMessage(handle, WM_USER+203, 4, 0); //This is "supposed" to send the
message to the Background program

Unfortunately, nothing happens when the message gets sent. I've tried
replacing the "handle" value with an integer and even tried using the
"RegisterWindowMessage" function to get a value to substitute for
"handle".

Am I correct in assuming that the "Window Handle" value is the same
value I need as an address to send the message to? If not, how do I
figure out the "address" in order to send the Windows Message to? I.e.,
in the structure for the Shell Execute command the first parameter is
the window "handle"--and so I assume when I launch the Background
program, the window it comes up in is assigned this handle (?). And so,
if I want to send a message to the Background window, I would "address"
it to the same handle address??? Or am I off in the ozone here?

All Delphi Window handling functions seem to work inside of your app and
won't affect windows/dialogs outside of your application: this is
probably my problem????

Any help would be much appreciated!!

-Jeremy

 

Re:Using Windows messages w/ Delphi and an external app


On Wed, 25 Sep 1996 15:11:57 -0700, Jeremy Wells
<n...@oneworld.owt.com> you smacked the keyboard repeatedly to write:

[Snip]

Quote
>ShellExecute(handle, 'open', 'CCBKGRND.EXE', 'C:\CCMOBILE\CCDATA2 "login
>name" password', 'C:\ccmobile', SW_SHOWNORMAL);   //this opens the
>Background program

>PostMessage(handle, WM_USER+203, 4, 0); //This is "supposed" to send the
>message to the Background program

I'm going to assume that this is being done in one of your forms
methods like:

procedure TForm1.FormShow(bla bla bla);
begin
end;

If so, your reference to HANDLE in the post message is actually the
handle of your form.  So what you are doing is sending the message to
yourself and not CC Mail.  ShellExecute returns the handle to the
application that is executed.  This is the handle you should be using.

For Example:

ProgramHandle := ShellExecute(handle, 'open', 'CCBKGRND.EXE',
'C:\CCMOBILE\CCDATA2 'loginname" password', 'C:\ccmobile',
SW_SHOWNORMAL);   //this opens the Background program

if ProgramHandle > 32 then
        PostMessage(ProgramHandle, WM_USER+203, 4, 0)
else
        ShowMessage('Error!');

Quote

>Unfortunately, nothing happens when the message gets sent. I've tried
>replacing the "handle" value with an integer and even tried using the
>"RegisterWindowMessage" function to get a value to substitute for
>"handle".

If you want to see if its already running (and not start a second
copy) you can use the FindWindow function.

Quote
>Am I correct in assuming that the "Window Handle" value is the same
>value I need as an address to send the message to? If not, how do I
>figure out the "address" in order to send the Windows Message to? I.e.,

Not in the sense of a Memory Address.  The reason you use handles is
so that Windows can move your program or data around in memory without
your program knowing about it.

Brien King
bk...@primenet.com

Re:Using Windows messages w/ Delphi and an external app


Brien,

Thanks for the info!

Actually, in doing some research, the "ShellExecute" command returns the
application instance handle and not the window handle--so the example
you gave wouldn't work. I was able to get the sendmessage function to
work (finally), by launching the Background program and then using the
WinSight utility to see what window handle was actually assigned. When I
manually plugged this value in (using an input box) I was able to get
the sendmessage function to work.

But the problem is now trying to find a way to query for the window
handle that is assigned to the Background program. When I use the
"FindWindow" function:

WindowHandle := FindWindow('RoutWndClass', 'Lotus cc:Mail Background');

I always get "0" returned *if* I execute the Background program
beforehand with ShellExecute or CreateProcess. However, if I launch the
Background program manually, the FindWindow function returns a valid
window handle. This doesn't quite make sense to me. Anyone have any
ideas what's happening here??

You would think that there would be a way to execute a program from
within Delphi and have a window handle returned so that you don't have
to search for it later...but I haven't found anything like that.

-Jeremy

Re:Using Windows messages w/ Delphi and an external app


Problem solved! The FindWindow command was failing because it was being
executed before the window I was looking for had fully come up...obvious
solutions sometimes seem the most elusive...

-Jeremy

Re:Using Windows messages w/ Delphi and an external app


Quote
Jeremy Wells <n...@oneworld.owt.com> wrote:
>I'm fairly new to programming with Delphi and Windows, so this may seem
>rather obvious (I hope) to someone out there:

>I'm trying to use "Windows Messages" to send a message to the CC:Mail
>Background program. According to the docs on the Background program, the
>message I need to send is "WM_USER+203" and I need to send "4" for the
>"wParam" value. So in Delphi, I created this:

>ShellExecute(handle, 'open', 'CCBKGRND.EXE', 'C:\CCMOBILE\CCDATA2 "login
>name" password', 'C:\ccmobile', SW_SHOWNORMAL);   //this opens the
>Background program

>PostMessage(handle, WM_USER+203, 4, 0); //This is "supposed" to send the
>message to the Background program

>Unfortunately, nothing happens when the message gets sent. I've tried
>replacing the "handle" value with an integer and even tried using the
>"RegisterWindowMessage" function to get a value to substitute for
>"handle".

   The reason of this is simply: you post the message to your
application, not to the background program!!!

   What you need to do is to get the handle of the window of your
background program and post message using this handle

   ShellExecute(handle, 'open', 'CCBKGRND.EXE',
        'C:\CCMOBILE\CCDATA2 "loginname" password', 'C:\ccmobile',
         SW_SHOWNORMAL);  

   wBackgroundWindowHandle := GetActiveWindow;

   PostMessage(wBackgroundWindowHandle, WM_USER+203, 4, 0);

   Normally, this code will send the WM_USER+203 message to the correct
application.

   Let me know if it work.

- Show quoted text -

Quote
>Am I correct in assuming that the "Window Handle" value is the same
>value I need as an address to send the message to? If not, how do I
>figure out the "address" in order to send the Windows Message to? I.e.,
>in the structure for the Shell Execute command the first parameter is
>the window "handle"--and so I assume when I launch the Background
>program, the window it comes up in is assigned this handle (?). And so,
>if I want to send a message to the Background window, I would "address"
>it to the same handle address??? Or am I off in the ozone here?

>All Delphi Window handling functions seem to work inside of your app and
>won't affect windows/dialogs outside of your application: this is
>probably my problem????

>Any help would be much appreciated!!

>-Jeremy

--

          ___                                              ___
          L_|_                                            _|_J
         ( -O>                                            <O- )
      ___//\J  __________________________________________  L/\\___
     //-,\    |                                          |    /,-\\
    || / \\___L   AVONTURE Christophe (c) AVC Software   J___// \ ||
  _ ''/\/ '---J    Christophe.Avont...@is.belgacom.be    L---' \/\'' _
 / \ //\\.    |__________________________________________|    .//\\ / \
|_/\'/  ||                                                    ||  \'/\_|
     '   ||_         "Make sure that, always!, you            _||   '
         |__)       reply to my private mail adress"         (__|

Delphi Super Page: http://sunsite.icm.edu.pl/archive/delphi/delphi
Delphi Super Site: http://sunsite.icm.edu.pl/~robert/delphi
Delphi Others:     http://www.coast.net/~jkeller
                   http://www.pobox.com/~bstowers/delphi

 "Postings are personnal, and don't reflect Belgacom's opinion"

Other Threads