🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #15814

Re: Run program against file

#15814
From: cpp3003
Date: Fri, 13 Jun 2003 14:23
117 lines
4483 bytes
Hi,

Thanks for the reply. I used the code below, but, I ran into a problem. I
haven't used api much, so, I am not sure if there is more that I need to add
or if I need to reposition something. But, when I ran the .exe for this
code, it dropped straight through to the 'file selection error 00000001/0',
then, when I click the ok button it gives a box that says 'Selected File',
but no file name appears.

How does the process look when it works correctly? Also, will the process
bring up a window to select a file, and, invoke my program with that file
name as an argument ? I am also looking at a way to open an outfile which
shows a text report after my process completes. Can this be done as an
addition to the code below ?

Thanks


"Ed Mulroy [TeamB]" <ed@mulroyREMOVETHESECHARS.org> wrote in message
news:3ee8fc5c@newsgroups.borland.com...
> Try this:
>
>   ------------------------
>   #include <windows.h>
>
>   WORD WINAPI SelectFile(
>     HWND parent,
>     const char *initial_directory,
>     const char *
>     title,
>     char *full_name)
>     {
>     OPENFILENAME ofn;
>     char         file_name[MAX_PATH + 1];
>
>     ZeroMemory(&ofn, sizeof(ofn));
>     ofn.lStructSize = sizeof(ofn);
>
>     ofn.hwndOwner = parent;
>     ofn.lpstrTitle = title;
>     ofn.nMaxFileTitle = lstrlen(title);
>
>     *full_name = '\0';
>     ofn.lpstrFile = full_name;
>     ofn.nMaxFile = MAX_PATH + 1;
>
>     ofn.lpstrFileTitle = file_name;
>     ofn.nMaxFileTitle = MAX_PATH + 1;
>
>     ofn.lpstrInitialDir = initial_directory;
>
>     ofn.lpstrFilter = "Executable Files\0*.EXE\0\0";
>
>     ofn.Flags = OFN_FILEMUSTEXIST    | OFN_LONGNAMES    |
>                 OFN_NOREADONLYRETURN | OFN_HIDEREADONLY |
>                 OFN_PATHMUSTEXIST    | OFN_EXPLORER;
>
>     SetLastError(0);
>
>     if (!GetOpenFileName(&ofn))
>       {
>       DWORD errnum = CommDlgExtendedError();
>       char  err_buf[512];
>
>       wsprintf(err_buf, "File Selection Error %08X/%u", errnum);
>       MessageBox(parent, err_buf, "", MB_OK);
>       *full_name = '\0';
>       *file_name = '\0';
>       ofn.nFileOffset = (WORD) -1;
>       }
>     else
>       {
>       // create a pointer to the 1st char following the directory
>       lstrcpy(file_name, full_name + ofn.nFileOffset);
>       }
>
>     return ofn.nFileOffset;
>     }
>
>
>   int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
>     {
>     char file_name[MAX_PATH + 1];
>
>     int result = SelectFile(GetDesktopWindow(),
>                  "C:\\Program Files",
>                  "Select EXE File",
>                  file_name);
>
>     if (result != -1)
>       {
>       MessageBox(HWND_DESKTOP, file_name,
>         "Selected File", MB_OK);
>       }
>
>     return 0;
>     }
>   ------------------------
>
> Assuming the file name is temp.cpp a command line to build it could be:
>
>   bcc32 -WR -v temp
>
> .  Ed
>
> > cpp3003 wrote in message
> >  news:3ee8f082$1@newsgroups.borland.com...
> >
> > I wrote a program that needs to accept a file name as an
> > argument. I have 2 ideas for handling this in windows. The
> > first is to have a browse menu appear that will prompt
> > for/select a file name from directory listing. The
> > second is to have an entry in the (right click) context
> > menu, for a selected file, in windows explorer. I do not
> > know how to do either one of these.
>
>
Technical Details
Message-ID: <3ee9dde6$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3ee8f082$1@newsgroups.borland.com> <3ee8fc5c@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,7bb2502e61022b33
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-06-13 07:28:04 PST
Reply-To: "cpp3003" <cpp3003@yahoo.com>
From: "cpp3003" <cpp3003@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3ee8f082$1@newsgroups.borland.com> <3ee8fc5c@newsgroups.borland.com>
Subject: Re: Run program against file
Date: Fri, 13 Jun 2003 10:23:19 -0400
Lines: 119
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 157.232.192.53
Message-ID: <3ee9dde6$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1055514086 157.232.192.53 (13 Jun 2003 07:21:26 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail