Solved

Improving performance in a dialog DLL

Posted on 2002-05-19
5
234 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now