0

I have searched StackOverlow and googled myself silly, but can't find a solution to this problem.

What I wish to do is be able to preview the contents of a file. I can do this at present for a BMP, JPEG etc. but I'd like to be able to do it for any file that has a default program association. The most likely example is a PDF file, but any file is theoretically possible in this application.

What I had in mind was to:-

  1. Open the file (with ShellExecuteEx?)
  2. Wait for the open to complete
  3. Copy the contents of the first window displayed by the opening program
  4. Save the window to a TBitMap
  5. Close the file/program/window
  6. Display the captured BMP in a TImage as my preview.

I reckon that I can do steps 1 and 6, but the bits in the middle have me beaten :-(

I'm working with Delphi-7

Cheers

Jeff

RRUZ
  • 134,889
  • 20
  • 356
  • 483
Jeff Cook
  • 67
  • 1
  • 5
  • 1
    This is a very broad question, and you're asking several different things that would require quite a bit of code to accomplish. Perhaps you should break this down into the individual steps (or at least reasonable sub-groups of the steps) and post those as separate questions. This is kind of like saying "I'd like an application that does these things. Can you write it for me here?". SO is really for short, specific questions that can be answered in a reasonable amount of space. The [FAQ](http://stackoverflow.com/faq) has some tips on writing questions here that might help. :-) – Ken White Jan 30 '13 at 23:04
  • Hmmm... I thought that I had broken it down into 6 steps and since they all relate to one another I didn't see the point in writing a question about each one that could give me answers that don't fit together. I'm not asking someone to write an application - the preview screen would be just on in 100's of screens of an app that has been continuous developement for 14 years - getting kinda boring ;-) In my ignorance, I didn't realise that the question was a broad one ;-) Thanks anyway for your attention & thanks to all contributors - I have gleaned many useful code snippets from the site:-) – Jeff Cook Jan 31 '13 at 02:31
  • There are other steps omitted from your list, like getting from the process handle ('HANDLE') you get back from `ShellExecuteEx` to a window handle (`HWND`), getting the size of that window in order to create the bitmap, getting the window content into the bitmap, properly closing the other process, etc. I didn't say you asked us to write an app for you; I said the question was broad enough to be almost the same thing. :-) All we'd need to add is a main form with a button and an edit control for a filename, and we'd be there. – Ken White Jan 31 '13 at 02:39
  • "There are other steps omitted from your list ..." sort of exposes my ignorance ;-) I guess I would have asked about those if I had known about them. It's a bit of a vicious circle, I don't know what I don't know. :-( – Jeff Cook Jan 31 '13 at 02:45
  • You might start at [Torry's Delphi Pages](http://torry.net/pages.php?id=108) with some of the stuff marked `FWS` (free with source). There are at least a couple of items there that would show the screen capture part, and then you can move on to the other steps. :-) – Ken White Jan 31 '13 at 02:52

1 Answers1

4

You can try the Windows Preview Handlers, you can Host a existing Preview Handler in your app and also create your own.

Check these resources.

Hosting Preview Handlers

Creating Preview Handlers with Delphi

Community
  • 1
  • 1
RRUZ
  • 134,889
  • 20
  • 356
  • 483