Solved

Improving performance in a dialog DLL

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

707 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

20 Experts available now in Live!

Get 1:1 Help Now