Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open Paint with image 1

Status
Not open for further replies.

BoMi

Programmer
Jul 20, 2006
39
RS
Hi, again, to all!
I have had hard time with my little application development, and, when I finally thought next steps would be easy, I faced a

new problem...
I have an Image component on my form where I load pictures through openpicture dialog, like this:

Code:
public
{ Public declarations }
ImgName:string;

...


procedure TForm1.FileOpenImageExecute(Sender: TObject);
begin
  if (OpenPictureDialog1.Execute) then
begin
    ImgName:=OpenPictureDialog1.FileName;
    Image1.Picture.Create;
    Image1.Picture.LoadFromFile(ImgName);
    StatusBar1.SimpleText:=ImgName;
  end;
end;

Then, I do something with this picture or not, and then I want to make Paint programme open that picture for me on Main menu

item execution or buttonclick. I do that like this:

Code:
procedure TForm1.FileOpenPaintExecute(Sender: TObject);
begin
ShellExecute(Handle,
             'open',
              PChar('mspaint'),
              PChar(ImgName),
              nil,
              SW_MAXIMIZE);
end;

And that's where problems begin. I have been using ShellExecute for some time and I've never had problems before. But, I have

never tried to open Paint with image which is already loaded in my app.

Problems:
-this above doesn't work, usually I get error message e.g. like this:
"C:\Documents and Settings\BoMi\My Documents\My Pictures\sdff.bmp was not found."
Sometimes this message doesn't contain the whole address of a picture, but only a part of it, and sometimes picture extension

given in the message is wrong (like above, when I tried to open sdff.jpeg image from my app in Paint)
-this code above doesn't work even if I change PChar(ImgName) to PChar('C:\Documents and Settings\BoMi\My Documents\My

Pictures\sdff.jpeg') or any else address at all
-in some cases code above works if I change PChar(ImgName) to PChar(ExtractFileName(ImgName)), but only with some pictures

and doesn't with others (I can't see the difference between those pictures)
There's no problem with openning Paint with this:

Code:
ShellExecute(Handle,
             'open',
              PChar('mspaint'),
              nil,
              nil,
              SW_MAXIMIZE);

What I really need is to make Paint open with image which is alredy loaded in my app this way or another, but I still would

like to see explanations/solutions of the mentioned problems.
I use Delphi 6.
Thanks to everyone who wants to help me (and who even read this a mile long question :))
 
I may be mistaken (I don't currently have access to Delphi to check), but as far as I am aware you can open a program with a file loaded with ShellExecute just by passing the filename - i.e. you don't need to specify the program name.



Hope this helps.


[vampire][bat]
 
I've tested this on a different machine:

Code:
ShellExecute(Handle,
             'open',
              PChar('mspaint'),
              PChar('"' + ImgName + '"'),
              nil,
              SW_MAXIMIZE);

You need double quotes [tt]"[/tt] around the filename especially if there are spaces in either the filename or the pathname.

By the way, I seem to have been wrong with my thoughts in the previous post (although I'm sure I have done it that way in the past)


Hope this helps.

[vampire][bat]
 
Hi to you earthandfire and BIG thank you!!!
You helped me a LOT. I had no idea about this.

And, by the way, yes you can launch external program only by passing name of the file you want to open, just like this:
Code:
 ShellExecute(Handle,
             'open',
              PChar(filename),
              nil,
              nil,
              SW_MAXIMIZE);

But, there must exist on your system a registry entry for default application that launches filename's extension. Otherwise, you need to set up that registry entry by yourself, and that can be done from within your application (I'm not sure how but I think it's somewhere in Delphi help file).
Anyway, thank you again for help. You absolutely rule!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top