I have a MainForm on which several child forms will be shown or hidden.
I need to run some code when a user switches from one form to another. This code is specific for the form being replaced by another form. I have tryed placing the code in the "Form__WM_DESTROY" function. But the code does not get fired when the form is replaced.
So where should I place this code, to ensure it runs when the form is replaced by another child form?
I think WM_CLOSE is what you are looking for.
Look at the FF's MDI sample project. you will see it in the FRMDOCUMENT_WM_CLOSE.
Edit:
I reread your post again and this may not work because the forms "will be shown or hidden". WM_CLOSE will not be fired since the form will not be closed.
How about Deactivate? I am not sure what this is in PB but in VB6 it is Form_Deactivate.
Or WM_SHOWWINDOW:
http://msdn.microsoft.com/en-us/library/ms632645(VS.85).aspx
In the logic of your program you must be doing something that is causing the child windows to show or hide. That is the best place to run your code from. For example, if you click on a button or choose a menu option then prior to showing/hiding your child forms you should run the code that you need. You could place that code in a separate function that you could call from multiple places if the logic of your program dictates that the child forms will change based on various user actions.
Paul, I understand what your saying. I should be able to do this. The reason I need to do this is that the user can put a record in edit mode which locks the record and a want to prevent the lock from remaining if the user moves to a different form.
I am going to need to do a similar thing to prevent a user from locking a record in edit mode and the forgetting about. Probably will set a timer have it exit the edit mode if no action has been taken in 2 to 3 minutes. Yes, i think this is doable.
Thanks guy's for helping me think this though.
You can use WM_SHOWWINDOW
msdn.microsoft.com/en-us/library/ms632645%28VS.85%29.aspx