Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create object in mainframe

Status
Not open for further replies.

StefanoCarniel

Programmer
Apr 29, 2005
15
IT
I developed an application with a menu that open a dialog box. In this dialog box, the user should set some parameters and then click the usual ok button.
When this button is clicked, the application should return in the mainframe and do the following sequence:

1. Create a string
2. Create a dockable CEdit control on the right to write in the operation (such a log window)
3. Create a progress bar in the status bar and go on with the computation. During the growth of the progress bar, the application should log the operations in the CEdit control.

I manage all this sending a message from the dialog to the mainframe using postmessage and developing the message handler. The problem is that the application create the CEdit control after the computation loop that increase the progress bar and at the end I can see in the CEdit only the last message and not the entire log. I tried with recalclayout, invalidaterect and so on but nothing happened. Could someone help me, please?

Thank you.
 
>I manage all this sending a message from the dialog to the mainframe using postmessage and developing the message handler.

PostMessage means the message will be handeled when the message pump executes. Since you run your stuff all the time in a single thread the pumping of messages will not be done until you're finished.

You can solve this by
1) Pump messages "manually" after each PostMessage
or
2) Do your lengthy work in another thread and post the message from there.

1)
A message pump is something like this
Code:
// Returns false if user has requested to close the app
bool PumpMessages()
{
  MSG msg;    
  while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))      
  {
    if (msg.message == WM_QUIT)
    {
      PostQuitMessage(0);			  
      return FALSE;
    }
    TranslateMessage(&msg);         
    DispatchMessage(&msg);      
  }	
  return TRUE;
}

2) See faq116-5162

/Per
[sub]
www.perfnurt.se[/sub]
 
Ok, I choose a different solution: I create the CEdit in the MainFrame::OnCreate. Now look at what happens.
I created a message WM_SINC sended by a dialog to the main window. The handler CMainFrame::OnSinc looks like this:

CProgressBar bar(....); //Create a progress bar

for (i=0; i< vector.size(); i++)
{
//increase the bar size
bar.StepIt();
//write in the CEdit the element i
m_editwnd.m_wndChild.SetWindowText(vector);
Sleep(100);
}

I would like to see the progress bar increasing while the text in the CEdit change, but I see only the progress bar that grows and the CEdit empty. When the progress bar finished, in the CEdit I see the text of the last element in vector. Should I use a refresh or something like that?
 
Instead of Sleep call a PumpMessages function described above.

/Per
[sub]
www.perfnurt.se[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top