Link to home
Start Free TrialLog in
Avatar of klingej
klingej

asked on

dialog-based app - c++ question

I have a dialog based application with an edit box that basically serves as output messages to the user.

This CDialog object has a separate object :
class CDialog {

CObject object;

}

And the object has some operation.  This operation has several parts to it.  Is it possible for the object to "tell" the class it belongs to to update the edit box to display to the user which part of the operation it is currently doing??  something like this?

CObject::Operation
{
  //do first thing
  // tell CDialog to update edit box to say "doing first   //     thing"

  //do second thing
  // tell CDialog to update edit box to say "doing second           //     thing"

  //do third thing
  // tell CDialog to update edit box to say "doing third         //     thing"

}

ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops, use SendMessage instead of PostMessage since Operation does not yield control.
Avatar of klingej
klingej

ASKER

Is there anything special you have to do to create a user-defined message other than this:
#define    WM_USER_PROGRESS        (WM_USER + 1)


Do you just create a function called OnProgress()  and manually put it in the message map??


>Do you just create a function called OnProgress()  and manually put it in the message map??

That's right.
Avatar of klingej

ASKER

At first, this looked like it was working well, but then I discovered that if I ran the operation more than once withing one instance of the application, it has memory leaks..  since this is something the user might possible be doing, I can't have this!!

Any idea why this might be happening?  I am passing a structure (with a string member for the new message) to the SendMessage() function through LPARAM like your example from codeguru.com.  So I change the value of this string and then call SendMessage().

In your suggested answer, what's the significance of the different numbers used for WPARAM and LPARAM??  Does this have anything to do with it.  
1. What does the operation do? You'd better show the code.

2. Why do you think it has memory leaks?

3. The different numbers used for WPARAM and LPARAM in the suggested answer are just one of the methods. With this method, the dialog box is responsible for loading the strings from the resource according to different numbers. You don't have to pass the strings.
Avatar of klingej

ASKER

I found the memory leaks and it didn't have anything to do with the messaging (which is normally how it works :)

Thanks for the help.