Michael Parr
Michael Parr

Reputation: 134

Send unsaved image or image from clipboard to to a program as a parameter

Question may not be well written.

I have an image viewing program and I would like to be able to send an image to another program, like Photoshop.

I can do this if the image has a saved source, but can't figure out a way to send an unsaved image to another program. Currently I am adding the image to the clipboard, and then sending a paste command to the application that loads - which works on the condition that the paste command is executed after the program starts. For MSPaint, a simple thread sleep does fine. But for programs that take an unpredictable and long time to open - like gimp and Photoshop - this doesn't work unless I set a high enough sleep value.

So my question is - can I send an image from the clipboard to a program as a parameter, or is there a way to somehow know if a program has fully loaded? I've thought about first saving the image as a temp image and sending that - but I would rather the program not attempt to save to the temp directory when pressing save.

Upvotes: 0

Views: 151

Answers (1)

Idle_Mind
Idle_Mind

Reputation: 39142

"is there a way to somehow know if a program has fully loaded?"

I think the closest generic answer you'll get is to use Process.WaitForInputIdle():

Use WaitForInputIdle() to force the processing of your application to wait until the message loop has returned to the idle state. When a process with a user interface is executing, its message loop executes every time a Windows message is sent to the process by the operating system. The process then returns to the message loop. A process is said to be in an idle state when it is waiting for messages inside of a message loop. This state is useful, for example, when your application needs to wait for a starting process to finish creating its main window before the application communicates with that window.

So you could do:

    Dim P As Process = Process.Start("someAppHere")
    P.WaitForInputIdle()

Bear in mind, though, that not all applications load the same way so an app might enter an "idle" state before it is fully loaded...it just depends on how it was designed.

Upvotes: 1

Related Questions