Subj : Re: want to execute code as soon as application is run To : borland.public.cpp.borlandcpp From : Jogy Date : Wed Jul 20 2005 03:13 pm Simon Hearn wrote: > Hi, > > I'm trying to execute a piece of code that displays a dialog box with two buttons, on of which is cancel - exits the program. I need this code to execute as soon as the application in run and the window is displayed. > > At the moment the code is in the SetupWindow() function, which works ok. But it's actually run before the window is fully created. So when I hit cancel, the application quits, but I get an error (an exception from the TXWindow function) saying the window was not created properly (because I destroyed it before it was fully created). > > So, I either need to stop this error message appearing thus achieving a quiet exit. Or I need to place the code after the window is fully created. > > I don't know how to do either of these so can anyone help me out? > > Thanks > > Simon Hello, First of all, are you displaying your message box before or after calling the parent TWindow::SetupWindow() in your SetupWindow() function? After calling TWindow::SetupWindow() the window should be fully created and you can post a WM_QUIT message (using the API function PostQuitMessage()) if you want to exit. If you want the message box to be shown along with the main window of the application, you can do it in the first WM_SHOWWINDOW message. If you do not care if the main window is displayed, then you can try something else: In the OWLMain() function, call ::MessageBox(NULL, "Run the application?", "Question", MB_OKCANCEL) and if the user chooses to cancel, exit without even creating TApplicaton, main windows, etc. Jogy .