Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Improving performance in a dialog DLL

Posted on 2002-05-19
5
Medium Priority
?
243 Views
Last Modified: 2010-08-05
Hi experts!
This is my question: I have a dialog based DLL. in the OnInitDialog function I call another function (LoadControls) that init all the combo box-s in the dialog, using the DB. I have a lot of combo and I need to init all of them from DB tables. hence - the OnInitDialog gets very slow. I would like to remove the call to LoadControls from the OnInitDialod and right after that to call it. That way the dialog is displayed and the user is under the impression that all is OK. mean while - I load (behind the scene) all the data for the combos. I imagine that there is an event I have to catch. which one?
0
Comment
Question by:osnat
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:mblat
ID: 7020155
You can start separate thread in OnInitDilaog and let it handle combo-box loading...

Of cause you need to make sure that user won't start using comboboxes before you load them...
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 150 total points
ID: 7020237
Here is a simple technique:

Add a small button to the dialog.  Set its ID to 'IDC_ContinueSetup'.  Double-click it and let the wizard create an OnContinueSetup() handler.  In that handler do..

void CMyDlg::OnContinueSetup()
{
    CWaitCursor  wait;
    ... do all of the DB init stuf...
}

Now edit the OnInitDialog function and remove all of the Db init stuf.. Add this line at the the very end of OnInitDialog:

    PostMessage( WM_COMMAND, IDC_ContinueSetup, 0 );

Back in the dialog editor, select the button and make it invisible (uncheck its Visible checkbox in its Properties).

What this does is let OnInitDialog finish its cascade of messages (including all screen drawing), then when all is clear, it executes your ContinueInit fn.  This is a useful technique to use whenever there is a lot of initialization to do.

You don't actually need the hidden button.  You can make a custom Message is and custom message handler, etc.. its just that the ClassWizard makes this technique so easy, there is no need to go to the extra work.

-- Dan
0
 

Author Comment

by:osnat
ID: 7020960
I'm sorry but I don't work with the wizard; I edit the code all by my self! I've added the function manually and did all u said. I added a MessageBox in the function OnContinueSetup  but it never pops up. I'm missing something. what is it?
0
 

Author Comment

by:osnat
ID: 7020970
Forget it! I did it - all it needs was the
ON_COMMAND(IDC_ContinueSetup, OnContinueSetup)
Thanks!
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7021101
hi osnat,
Thanks for accepting my comment as an answer.  However, I am curious as to why you gave me a 'B.'  It seems that my comment help you out a lot, but now my overall grade-point-average has declined.  It is discouraging to me.

-- Dan
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question