Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dialog-based app - c++ question

Posted on 1999-07-26
7
Medium Priority
?
189 Views
Last Modified: 2013-11-20
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"

}

0
Comment
Question by:klingej
[X]
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
  • 4
  • 3
7 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 300 total points
ID: 1311487
Pass the pointer of the dialog box as the parameter of Operation function.

obj.Operation(this);

Post a user-defined message to the dialog box.

#define    WM_USER_PROGRESS        (WM_USER + 1)

CObject::Operation(CDialog *pDlg)
{
    // ...
    pDlg->PostMessage(WM_USER_PROGRESS, 1, 0);

    // ...
    pDlg->PostMessage(WM_USER_PROGRESS, 2, 0);

    // ...
    pDlg->PostMessage(WM_USER_PROGRESS, 3, 0);
}

The dialog box is responsible for updating the edit box whenever receiving the user-defined message.

See my article at http://www.codeguru.com/internet/urlfile.shtml for a similiar example. It uses multithread.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1311488
Oops, use SendMessage instead of PostMessage since Operation does not yield control.
0
 

Author Comment

by:klingej
ID: 1311489
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??


0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 23

Expert Comment

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

That's right.
0
 

Author Comment

by:klingej
ID: 1311491
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.  
0
 
LVL 23

Expert Comment

by:chensu
ID: 1311492
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.
0
 

Author Comment

by:klingej
ID: 1311493
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.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

705 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