0

I'd like to know a way to do the following:

App starts, no forms created. 2nd App instance starts, it detects one instance is already running (this is sorted already)

I want 2nd instance to send the 1st one a message, without using BROADCAST; Id like a way to find a handle to the 1st instance to send it the message directly.

The 1st instance must have a class name to be found with that the 2nd one hasn't yet created, so that it won't send the message to itself.

How would I use FindWindow in this scenario? How do I create a window-less class/object identifiable by FindWindow?

4
  • FindWindow finds a window by either class name or caption, so it can't find anything that is windowless. (That's why the function is called Find**Window**). It also returns a window handle - if it could find something that was windowless, what would it return? Commented Nov 11, 2012 at 3:43
  • Well I can create a "window" with AllocateHWnd, but then I don't know how to find it from the other instance. Commented Nov 11, 2012 at 3:47
  • Well, if you create a window with AllocateHWnd, it's not windowless, is it? And you specifically asked about using FindWindow to find a windowless application. "How di I create a window-less class/object identifiable by FindWindow?" were your exact words. Commented Nov 11, 2012 at 3:55
  • 4
    @KenWhite "windowless" in this context means no TForm instance, it is wrong, because not only TForm is a window. So every "windowless" should be replaced by "formless". There is no need of kicking ... Commented Nov 11, 2012 at 8:37

3 Answers 3

2

You can not find windowless object by means of FindWindow.

But you can create invisible window with AllocateHWnd function - see TTimer source as example. Use SetWindowText to set title for easy searching

Sign up to request clarification or add additional context in comments.

2 Comments

If you create a windows using AllocateHWnd, then it's no longer windowless, and the question asked for windowless specifically.
Some people consider programs without visible windows as windowless, I think
1

You can send messages to the TApplication window if you know the value of its Title property. The sending instance can temporarily set its own Title to a different value so as not to confuse FindWindow(). The receiving instance can use the TApplication.OnMessage event or TApplication.HookMainWindow() method to receive the message.

Comments

1

You could use shared memory to pass data. See this article for details

2 Comments

Don't used shared memory. Send messages.
Using that already for other purposes, but in this case I wanna sort the issue with SendMessage

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.