Board index » cppbuilder » Changing MainForm

Changing MainForm


2005-05-16 03:22:40 AM
cppbuilder28
My database application first loads a login screen to get the
Username/Password, if valid it then creates the main worker GUI form,
and hides the logon form.
However, as the workerform is not the main form, when minimised it
doesn't go to the taskbar, but to small header in lower left corner of
screen.
Is there any way of changing this behavior? I would like to be able to
say something like....
Application->MainForm = WorkerForm;
but ->MainForm is readonly.
Many Thanks.
 
 

Re:Changing MainForm

Quote
My database application first loads a login screen to get the
Username/Password, if valid it then creates the main worker GUI form, and
hides the logon form.
Ok!
Quote
However, as the workerform is not the main form [...]
Whay not? It should be! And the logon dialog should be some
other, non-main form. Such forms *can be* shown before
main form!
Try something like:
#include "LoginForm.h"
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
TLoginForm *Login = new TLoginForm(Application);
bool bIsLoggedIn = ( Login->ShowModal() == mrOk );
delete Login;
if( bIsLoggedIn )
{
Application->CreateForm(__clas­sid(TMainForm), &MainForm);
Application->Run();
}
}
catch(Exception &E)
{
Application->ShowException(&E)?
}
return 0;
}
--
Best regards,
Vladimir Stefanovic
"William Bates" < XXXX@XXXXX.COM >wrote in message
 

Re:Changing MainForm

Vladimir Stefanovic wrote:
Quote
Whay not? It should be! And the logon dialog should be some
other, non-main form. Such forms *can be* shown before
main form!
I thank you for your suggestion ... it is similar to what I have been
using for splash screens, but this doesn't do what I want.
To further explain, the Logon form could be called from the Worker form
at a later time if the user wants to change their logon identity. At
this time I will delete all forms, except the logon form, get new logon
details and reinstantiate the Worker form.
What I want to be able to do is to specify the main form at each of
these times. All I really want is the minimise behaviour to go to
taskbar, rather than to the bottom left of the screen.
I hope this clarifies the situation.
 

{smallsort}

Re:Changing MainForm

William Bates < XXXX@XXXXX.COM >wrote:
Quote

[...] All I really want is the minimise behaviour to go to
taskbar, rather than to the bottom left of the screen.
Override the form's CreateParams method to apply the
WS_EX_APPWINDOW flag to the form's ExStyle:
void __fastcall TForm1::CreateParams(TCreateParams &Params)
{
TForm::CreateParams( Params );
Params.ExStyle |= WS_EX_APPWINDOW;
Params.WndParent = GetDesktopWindow();
}
I think that a better solution is to post a custom message to
the main form from within the main form's constructor. That
way, as soon as the form is initialized and running, the
message gets processed and causes a modal login form to be
displayed. If the login is unsuccessful, it terminates the
application.
~ JD
 

Re:Changing MainForm

JD wrote:
Quote

I think that a better solution is to post a custom message to
the main form from within the main form's constructor. That
way, as soon as the form is initialized and running, the
message gets processed and causes a modal login form to be
displayed. If the login is unsuccessful, it terminates the
application.

~ JD
I also use a login form that is launched both at program launch and
(possibly) also later on during program execution. For the automatic
launch, I use a "one-shot" style flag that triggers the first time
FormPaint is called for my main form. Your solution to post the
message from the constructor may work equally well (I don't remember if
I ever tried it from that point).