Article View: borland.public.cppbuilder.nativeapi
Article #15796Re: Run program against file
From: Ed Mulroy [TeamB]
Date: Thu, 12 Jun 2003 22:18
Date: Thu, 12 Jun 2003 22:18
95 lines
3387 bytes
3387 bytes
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:
<3ee8fc5c@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3ee8f082$1@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-12 15:27:03 PST From: "Ed Mulroy [TeamB]" <ed@mulroyREMOVETHESECHARS.org> Newsgroups: borland.public.cppbuilder.nativeapi References: <3ee8f082$1@newsgroups.borland.com> Subject: Re: Run program against file Date: Thu, 12 Jun 2003 18:18:58 -0400 Lines: 97 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.1106 NNTP-Posting-Host: 206.228.162.54 Message-ID: <3ee8fc5c@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1055456348 206.228.162.54 (12 Jun 2003 15:19:08 -0700) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail