Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Improving performance in a dialog DLL

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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.

790 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