How to know when a Dialog/Frame finish loading
-
The task sounds simple: I have to load a long list of files into a list control box in a dialog. I do it by calling my function FeedFileToListControl() in the OnInitDialog(). The problem is that my function takes a long time to run and the dialog just doesn't show up before the OnInitDialog() returns. I want to have the dialog shows up first, then the Items are added into the list control in the dialog. So, where should I put my FeedFileToListControl() function ?
-
The task sounds simple: I have to load a long list of files into a list control box in a dialog. I do it by calling my function FeedFileToListControl() in the OnInitDialog(). The problem is that my function takes a long time to run and the dialog just doesn't show up before the OnInitDialog() returns. I want to have the dialog shows up first, then the Items are added into the list control in the dialog. So, where should I put my FeedFileToListControl() function ?
In a separate thread. If you don't do that, either your dialog won't be displayed (if you do that in OnInitDialog for example) or it will freeze during the loading (if you manage to call your function after everything has been initialized. Once everything has been loaded, you can send a message to your dialog so that it can fill the list. Don't work with the GUI directly in the separate thread.
Cédric Moonen Software developer
Charting control [v1.2 - Updated] -
The task sounds simple: I have to load a long list of files into a list control box in a dialog. I do it by calling my function FeedFileToListControl() in the OnInitDialog(). The problem is that my function takes a long time to run and the dialog just doesn't show up before the OnInitDialog() returns. I want to have the dialog shows up first, then the Items are added into the list control in the dialog. So, where should I put my FeedFileToListControl() function ?
There are several ways: (1) A separate thread. (2) A one-shot timer: set a timer in the
InitDialog
then fill the listbox the first time the WM_TIMER message occurs. (3) Make a PostMessage of a custom message for the application itself and then perform listbox initialization in the message handler. ... :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
There are several ways: (1) A separate thread. (2) A one-shot timer: set a timer in the
InitDialog
then fill the listbox the first time the WM_TIMER message occurs. (3) Make a PostMessage of a custom message for the application itself and then perform listbox initialization in the message handler. ... :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
It seems that to avoid freezing the dialog, I should use a seperate thread to insert item into the list. This thread should be created and starts after the dialog has showed up. But exactly when to do it ??? I haven't got where should I put my AfxBeginThread(). (I don't want to use a timer here)
-
It seems that to avoid freezing the dialog, I should use a seperate thread to insert item into the list. This thread should be created and starts after the dialog has showed up. But exactly when to do it ??? I haven't got where should I put my AfxBeginThread(). (I don't want to use a timer here)
If you put the initialization code in a separate thread, you can also start it in
InitDialog
method, since it will not freeze the application. However, IMHO you can keep the whole matter simpler using a one-shoot timer or a PostMessage making apparent to the user that you're performing initialization (an hourglass cursor, for instance). :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
The task sounds simple: I have to load a long list of files into a list control box in a dialog. I do it by calling my function FeedFileToListControl() in the OnInitDialog(). The problem is that my function takes a long time to run and the dialog just doesn't show up before the OnInitDialog() returns. I want to have the dialog shows up first, then the Items are added into the list control in the dialog. So, where should I put my FeedFileToListControl() function ?
GameProfessor wrote:
I want to have the dialog shows up first, then the Items are added into the list control in the dialog. So, where should I put my FeedFileToListControl() function ?
thread is only solution, but beware calling UI function from Worker thread bring some drastic result !
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You