VB6 Cancelling WM_DESTROY in an external application-VBForums
Results 1 to 4 of 4

Thread: VB6 Cancelling WM_DESTROY in an external application

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    8

    VB6 Cancelling WM_DESTROY in an external application

    I have an ActiveX control that runs in another application, doing various functions. I want to stop the application from closing while my ActiveX control is still running.

    Is it possible to hook WM_DESTROY and cancel it?

    TIA,

    rokujou

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,116

    Re: VB6 Cancelling WM_DESTROY in an external application

    That would be an extremely bad idea, for several reasons.

    For one, the application would think that it had already closed, and all of the code in the _Unload event (or at least _QueryUnload) would already have been run, which means the program will probably be unusable from that point, as well as the user probably being confused/annoyed about the program not actually closing.

    Also, if there is a bug somewhere in your code, the program will not be able to close at all - unless Windows terminates it (which would more than likely be an immediate stop, with no events being fired).

    A control is supposed to be a child of a form, not the owner/controller of it. Instead of trying to 'take charge', you should 'give advice', and accept that your 'advice' wont always be taken.


    The best thing to do is to take two steps.. first add an extra property to your control called something like "IsBusy" or "SafeToClose", which the form can check in its _QueryUnload event, and depending on the value of that property cancel the unloading (perhaps after giving the user a choice).

    The next thing is to ensure that your control can exit gracefully if it is forced to close. To do that, add code to the UserControl_Terminate event which tidies up as appropriate.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    8

    Re: VB6 Cancelling WM_DESTROY in an external application

    Thanks for the reply, si_the_geek.

    The problem I have is, the parent unloads when focus is lost - I'm trying to prevent this because my code launches external applications, which forces focus of the external app. The idea is that the user will be able to "lock" the window open until they've finished doing what they're doing.

    I didn't create the parent application, so I can't change the way it works. Thus, my original question still stands - is it possible?

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,116

    Re: VB6 Cancelling WM_DESTROY in an external application

    It is probably possible, but I would definitely avoid it, as it will be unsafe.

    You may not have created the parent application, but as it uses your control, I would assume that you have access to either the code or the person who did create it - and as such could get minor alterations made to it (and the alteration would probably be just one line of code!).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.