Article View: borland.public.cppbuilder.nativeapi
Article #9928CommandLine Parameter to own Application...
From: Oren Halvani
Date: Mon, 07 Jun 2004 16:56
Date: Mon, 07 Jun 2004 16:56
82 lines
3065 bytes
3065 bytes
hi dear builders,
i would like to implement a function that let's me add file-parameter
for my application like:
MyApp.exe Logfile.log // load "Logfile.log" into MyApp's
RichEdit->Text...
for handling this i've putted the following in my project...my problem
is..it doesn't
work! I try to call:
MyApp.exe Logfile.log
but the RichEdit->Text is still empty..what's going wrong...?
Oren
here's the code...
/*****************************************// in unit...
void __fastcall TMyApp::WmCopyData(TWMCopyData& Message)
{
String S = (char*)Message.CopyDataStruct->lpData;
S = S + '\0';
RichEdit1->Lines->LoadFromFile(S);
}
/*****************************************// in header...
private:
void __fastcall WmCopyData(TWMCopyData& Message);
public:
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_COPYDATA, TWMCopyData, WmCopyData);
END_MESSAGE_MAP(TForm)
/*****************************************// in Winmain( )
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR cmdLine, int)
{
try
{
HANDLE hMutex = OpenMutex(MUTEX_ALL_ACCESS, 0, "MyApp"); // Try to
open the mutex.
if(!hMutex) hMutex = CreateMutex(0, 0, "MyApp"); // If hMutex is 0
then the mutex doesn't exist. Create it.
else
{
HWND hWnd = FindWindow(0, "MyApp"); // This is a second instance.
Bring the original instance to the top.
SetForegroundWindow(hWnd);
// Command line is not empty. Send the command line in a
WM_COPYDATA message.
if(strlen(cmdLine) != 0)
{
COPYDATASTRUCT cds;
cds.cbData = strlen(cmdLine) + 1;
cds.lpData = cmdLine;
SendMessage(hWnd, WM_COPYDATA, 0, (LPARAM)&cds);
}
return 0;
}
Application->Initialize();
Application->CreateForm(__classid(TMyApp), &MyApp);
Application->Run();
ReleaseMutex(hMutex);
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}
Technical Details
Message-ID:
<40c49e06@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,e90b072bab983bf1,start X-Google-Attributes: gid10cc67,public Reply-To: "Oren Halvani" <NoSpam@fdtd.com> From: "Oren Halvani" <NoSpam@fdtd.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: CommandLine Parameter to own Application... Date: Mon, 7 Jun 2004 18:56:22 +0200 Lines: 84 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 217.234.102.183 Message-ID: <40c49e06@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1086627334 217.234.102.183 (7 Jun 2004 09:55:34 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail