CPB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't close my form... Close() isn't doing it... :(



My guess is that your problem is trying to close before the form is completely
created.  Likely you've placed the code in the OnCreate handler.  You need to let
it finish before closing.  To do this you need to leave some information around
so the handler of a later event can know to close the form:

1) Create a private boolean data member on the TIMP class.  Have the constructor
initialize it to False.

2) In your OnCreate handler, instead of calling Close, set the variable to True.

3) Choose some event such as OnShow.  Create a handler and check your variable.
If true, call close if not call TForm::Show.  If there is not a convenient event
to hang this on, create one by creating a custom message based on WM_USER.  In
this case, forget the private data member.  Instead, write a handler for your
custom message.  Instead of calling Close in your OnCreate handler, post yourself
a message using your custom message id.  Your handler then simply calls Close.
Or you can even post yourself a WM_CLOSE message, then you don't have to do any
code at all.  BE SURE TO POST THE MESSAGE.

So the simplest way is the post of a WM_CLOSE.  Try something like this:

PostMessage(MyForm.hWnd, WM_CLOSE, 0, 0); instead of Close();

So there are three, or at least two and a half ways to handle your problem.

tc

Aurora wrote:

> Hello all.. :)
>
> I am trying to write a POP3 client that sits is called from windows system
> agent every hour.  it is designed to log on to the pop3 server, check for
> mail, and if there is a mail from certain persons, download it and throw
> the attachments in a directory.
>
> Now I want the user to be able to pull up the GUI, so I have an auto-run
> mode (-a switch from cmd line).  At uses the NMPOP3 Dialog for all of
> it's mail stuff...
>
> Here is my FormCreate function/method
>
> /**********************************************************
> void __fastcall TIMP::FormCreate(TObject *Sender)
> {
>     bool AutoOn = false;             // Var for auto-run option
> //    String s2 = _argv[1];            // Get cmd-line arg 1
>     String s2 = "-a";                // Pretend user hit VCheck.exe -a
>     String s1 = "-a";              // Cmd line option being looked for
>
>     if (Contains(s1,s2))             // if s1 is in s2
>     {
>         AutoOn = true;
>     }
>     else {IMP->WindowState = wsNormal;}
>
>     GameList = new GameType [10];
>     Options = new OptionsType;
>
>     if (!AutoOn)
>     {
>         for (int i = 0;i<11;i++)
>             DisplayPlayer(Sender,GamesTab->TabIndex,i);
>     }
>
>     LoadOptions();                   // Loads Options from Disk
>     LoadGames();                     // Loads Game info from disk
>
>     MsgNo = 0;                       // temp count of e-mail msgs
>
>     if (AutoOn)
>     {
>         ConnectToServer();           // connect to POP3 server
>         CheckEmailForTurns();        // Get headers, and check from field for
>                                      //     valid addresses
>         DisconnectFromServer();      // hmmm...
>         ShutDown();                  // clean up loose ends, save configs
>         Close();                     // Thing that doesn't work... :(
>     }
>
> }
> /**********************************************************************
>
> Now the pgm has no probs exitting if I close on a button event, but from
> FormCreate it won't work... I have my theories... I need solutions... :(
>
> Any suggestions?
>
>                                                 TIA,
>                                                 Dave.
> "Aurora - Just a bunch of pretty lights dancing in the night sky."


begin:          vcard
fn:             N. Thomas Creighton
n:              Creighton;N. Thomas
org:            Lone Peak Technology Group
email;internet: tomc@lptg.com
title:          Owner
x-mozilla-cpt:  ;0
x-mozilla-html: TRUE
version:        2.1
end:            vcard


W Komornicki's Home Page | Main Index | Thread Index