Situation: I have a FormMain on which child forms are "shown" or "hidden" (SHOW/HIDE) . Some of these child forms have a lot of controls (some as many as sixty). Most of these controls have code embedded in their functions. These child forms get shown or hidden frequently.
Problem: The forms take a noticable amount of time to be shown (SHOW). I would like to improve the speed that these forms are displayed. Is there a way I might be able to improve the speed of the display of the child forms?
Clarification: Paul, is it true that when a form is displayed all the functions of the controls on that form are fired during the create process of displaying the child form ? And if so, does this occur every time a child form is displayed (Hide/Show)?
If so, would this idea be of help in speeding up the display of the child form:
Set the child form's WS_Disable to disable the form before usiing the show command and reset the forms WS_Disable to enable after child form is displayed. Does WS_Disable disable all controls on the form? Would this prevent the form's controls functions from being fired during the create process of the form?
Quote from: Marty Francom on March 30, 2010, 09:39:10 PM
Clarification: Paul, is it true that when a form is displayed all the functions of the controls on that form are fired during the create process of displaying the child form ? And if so, does this occur every time a child form is displayed (Hide/Show)?
No, that's not entirely true. Only some functions fire during the time that the Form is first created - not every time the Form is shown or hidden. The only type of functions that fire are notification messages such as notifying that text has changed in a control or a node has changed in a treeview.
You must be doing something else that is time intensive during the show/hide. Are you accessing a database each time the form is shown?
Yes, I found the code that is causing the hesitation in the display of the child form. I call a function right after calling the function that changes the child form from one to another. If I comment out that function the hesitation disappears. My puzzelment is that this function is called AFTER the function that changes the child forms.
Is there a place I can place on the child form that I can put some code that I need to run once every time the child form is "Shown" (SHOW) ?
I thought that the Form_Create function would work but that function is not called during a "SHOW".
Also, how do I set the WS_Disable for the form (programatically) ? I want to be able disable and enable a form at will.
You can use either the API-Function EnableWindow or FireFly's wrapper
FF_Control_Enable
FF_Control_Disable
(See F8)
If you want certain code to execute every time when you show the form then put this code into a sub or function. You can call it then everytime you make the form visible. From the parent form you call it then like this:
FF_Control_Enable hwndMyForm
Call MyFunctionAtShow (... or whatever you call that sub or function that executes your code)
Marty,
You can detect if a form has just been "Shown" by looking for the WM_SHOWWINDOW message in the forms CUSTOM routine.Function ChildForm_CUSTOM ( _
hWndForm As Dword, _ ' handle of Form
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
If wMsg=%WM_SHOWWINDOW Then 'Windows notification of ShowWindow message
If wParam=%True Then MsgBox "Showing" 'True=SW_Show and False=SW_Hide
End If
End Function
David
David, Thanks for the tip. That's what I needed.
Rolf, Oh, duhhh Of coarse.. I was thinking the FF_Control_Enable / FF_Control_Disable where only for controls on the form. I did think to try using it to disable/enable the Form itself. I will give it a go. I want to be able to disable the Navigation Form when a user is Editing a record on the Record Display Form. I don't want the user moving away from the Record Display Form while they are in "edit" mode for editing a record.
David,
I tryed your suggestion but the it never fires when the child form is displayed. I use this statement to display the child form:
SetWindowPos gChildForm, %HWND_TOP, nMenuWidth, 0, rc.nRight-nMenuWidth, rc.nBottom, %SWP_SHOWWINDOW
Do I need to modify your suggestion to be able to detect when the ChildForm is displayed?
Marty,
I have never used SetWindowPos to show a form. I'm not sure if that sends any message to the window or not. If it does, it's seems evident that it's not the message I told you to look for. I have included a sample project to show you how I do it.
I am not entirely sure why you are setting the window position, because I normally want to see it where I left it. If you have a reason to move it, you could just leave off the SWP_SHOWWINDOW flag, and then show it after setting the position as I am in my demo. Check out the demo and let me know.
David
Thanks David. I will give that a try.
David, I ran the sample program. This message gets fired before the form is actually on screen. I need away to tell when the form has been displayed (if that's possible). The message needs to fire AFTER the form is actually visible.
Just to help my understanding, why does it need to be visible already?
I have some setup/init code that needs to be run just after the form is displayed. I have tryed running it at various locations but if the form has not completed being displayed I get a lot of hesitation in the display of the form. Fields flashing and the like.
I was hoping to find a sure way to run some code right after the form is visable in hopes that this would avoid the hesitation and flashing fields that had been happening with previous methods I have tryed.
I posted a sample application that used PostMessage in the create event instead. Postmessage adds the message to the message queue, but does not get processed until the function currently completes (i.e. the create event). This will allow the create event to finish, meaning the form displayed. The message posted to the message queue will be processed.
http://www.planetsquires.com/protect/forum/index.php?topic=2267.msg17741#msg17741
Marty,
I modified my demo using the Postmessage idea that Brian suggested. I post the message during the SW_SHOWWINDOW message instead of the WM_CREATE message in Brian's example because it only fires once.
David
Marty, did you ever get this working as you needed?