a87 Subj : Re: want to execute code as soon as application is run To : borland.public.cpp.borlandcpp From : Simon Hearn Date : Wed Jul 20 2005 05:29 am In case you're interested I've solved the problem and I thought I'd post it here (I hate it when you search for a problem on a forum, find that someone else has had the same thing but not bothered to put thier solution down, really annoying!) All I did was to replace the "this.Destroy()" comand I was using to close the window with "PostQuitMessage(WM_QUIT)". Which I'm guessing (I don't have much experience with messages etc) adds a the quit message to the window, so when it's finished doing whatever it is it's doing, it executes the WM_QUIT command and closes with no fuss. Thanks to Jogy for the tip. Simon "Simon Hearn" wrote: > >Thanks for this, I'll give it a go and get back to you soon. > >Simon > > > >"Ed Mulroy" wrote: >>As I remember it, the SetupWindow function runs when the WM_CREATE message >>is received, during the CreateWindow call. That is before the window is >>completely constructed so before it is displayed. >> >>Programs that need to do something immediately following the end of the >>window creation often do it by performing a PostMessage to the same window >>as the last item in WM_CREATE. That makes it the last item in the >>SetupWindow function. >> >>The message used depends upon the application. Many don't use a timer so >>just post a WM_TIMER message and let the code respond to it. Others call >>RegisterWindowMessage and use that value for the message. Still others use >>something like WM_USER+100 for the message. >> >>. Ed >> >> >>> Simon Hearn wrote in message >>> news:42dd3fc2$1@newsgroups.borland.com... >>> >>> 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? >> >> > . 0