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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening Word or PDF documents.

Status
Not open for further replies.

britishdude

Technical User
Aug 21, 2003
6
GB
Hi all

I'll probably get laughed off this forum, but hey here goes.

I'm pretty new to C++ and builder, i've written some small programs, hangman game, resistor colour finder prog, wage calculator prog.......so you get the level that i'm at!!

My question is this i'm trying to write a program that lists all the files in a folder(lists them in a combo box), the files either being Word or PDF docs then clicking on a button opens them (so starts up Word or Acrobat Reader).
what classes or components do i need to do this? Then eventually i'll add a search facility, ie adding part of file names list all posibilities. I feel confident enough to do that! but just dont know how to list files in a combobox or open the relevent doc when found!!

There's going to be 500+ files in the folder all of which are named with 10 - 15 digit numbers (none of the numbers relate to each other) so just going to the folder and finding the file isn't easy.

Am i out of my depth? or could it be done even by a relative newbie like myself. Just a nudge in the general direction would help.
 
If I understand your posting correctly (something I'm notoriously poor at), you want to do two things, 1) list all *.DOC and *.PDF files in a combo box, and 2) be able to open one up when the user selects it.

File Listing
This is a common enough question that I guess someone (me?) ought to write a FAQ for it. You are going to need FindFirst and FindNext or one of their cousins. You will need to iterate through all the files in the select directory(ies) and put the list in the combo box.

Search this forum, there are several good examples on how to do this.

Opening File
To open a file with it's associated program, you have some options. I would recommend CreateProcess. Look at faq101-1954.

James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
You can use the FileListBox, DriveComboBox, and FilterComboBox under the Win 3.1 tab on your Component Palette in Borland. These are fairly simple to use together. This will allow the user to select a file. You may use the "OnDblClick" event in the FileListBox to open the file if you choose. Or you may use a separate button that the user pushes. Either way, the function called should say something like this:

if (FileListBox1->ItemIndex > -1) // something is selected
{
AnsiString Filename = FileListBox1->Items->Strings[FileListBox1->ItemIndex];
AnsiString Directory = FileListBox1->Directory;
AnsiString FullCommandLine = "pdfviewer.exe ";
FullCommandLine += Directory;
FullCommandLine += "\\";
FullCommandLine += Filename;

WinExec(FullCommandLine, SW_SHOW);
}

Good luck,
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top