Board index » cppbuilder » Main Form hiding

Main Form hiding


2005-10-07 06:00:22 PM
cppbuilder42
How can I make an app that, when it starts, keeps the main form hidden and
shows another form (like a login form)??
 
 

Re:Main Form hiding

Alexandru Dragusanu wrote:
Quote
How can I make an app that, when it starts, keeps the main form hidden and
shows another form (like a login form)??
Change your WinMain to handle the loginform even before
the mainform is created.
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
TLoginForm *LoginForm = new TLoginForm ( Application );
LoginForm->Show();
while ( ! LoginForm->ready ) // public: bool ready;
Application->ProcessMessages();
bool ok = LoginForm->ok; // public: bool ok;
delete LoginForm;
//well you could have used a modal form too I think
if ( ok )
Application->CreateForm(__classid(TMainForm), &MainForm);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}
Hans.
 

Re:Main Form hiding

I had some troubles with this method, but I found in C++'s Help a very easy
way to do this:
1)set MainForm's Visible propriety to false
2)set LoginForm's Visible propriety to true
3)before Application->Run(); write Application->ShowMainForm=false;
The MainForm is now hidden when the app starts. :)
"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
Alexandru Dragusanu wrote:
>How can I make an app that, when it starts, keeps the main form hidden
and
>shows another form (like a login form)??

Change your WinMain to handle the loginform even before
the mainform is created.

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();

TLoginForm *LoginForm = new TLoginForm ( Application );

LoginForm->Show();

while ( ! LoginForm->ready ) // public: bool ready;
Application->ProcessMessages();

bool ok = LoginForm->ok; // public: bool ok;

delete LoginForm;

//well you could have used a modal form too I think

if ( ok )
Application->CreateForm(__classid(TMainForm), &MainForm);

Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}

return 0;
}

Hans.
 

{smallsort}

Re:Main Form hiding

"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
LoginForm->Show();

while ( ! LoginForm->ready ) // public: bool ready;
Application->ProcessMessages();

bool ok = LoginForm->ok; // public: bool ok;
Use ShowModal() instead:
bool ok = (LoginForm->ShowModal() == mrOk);
Since you are deleting the form once it becomes 'ready', then the form can
simply close itself by setting its ModalResult property when needed.
ShowModal() returns the value of the ModalResult property.
Quote
if ( ok )
Application->CreateForm(__classid(TMainForm), &MainForm);

Application->Run();
If ok is false then there is no need to call Run() at all:
if ( ok )
{
Application->CreateForm(__classid(TMainForm), &MainForm);
Application->Run();
}
Gambit