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

x
?
Solved

Changing text in a modeless dialog box

Posted on 1999-07-13
10
Medium Priority
?
432 Views
Last Modified: 2013-11-20
I have a dialog box which I open from my main app window while certain processing is going on. The dialog has one edit control. I'd like to change the text in this edit control while I am searching different servers.

I can set the initial text using OnInitDialog (see below) but when I try to use the same method in a function I defined for this Dialog called ChangeText (see below), the text is never updated. It appears that I am missing something that would redraw the dialog box or update the text after I've set it.. What am I missing??

void CProcessingDialog::ChangeText(char *cMsg)
{
      // TODO: Add extra initialization here
      // Get a handle to the CEdit control
      CEdit* pEdit = (CEdit*) (GetDlgItem(IDC_PROCESSING_Txt));

      // Set the text with the text being passed in
      pEdit->SetWindowText(cMsg);

}

BOOL CProcessingDialog::OnInitDialog()
{
      CDialog::OnInitDialog();
      
      // TODO: Add extra initialization here
      // Get a handle to the CEdit control
      CEdit* pEdit = (CEdit*) (GetDlgItem(IDC_PROCESSING_Txt));

      // Set the text with the text being passed in
      pEdit->SetWindowText("This is the initial message...");
      
      return TRUE;  // return TRUE unless you set the focus to a control
                    // EXCEPTION: OCX Property Pages should return FALSE
}
0
Comment
Question by:mosleys
[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
10 Comments
 
LVL 3

Expert Comment

by:VCGuru
ID: 1309830
Just use UpdateData(FALSE); in your ChangeText(char *cMsg) function after pEdit->SetWindowText(cMsg);

0
 

Author Comment

by:mosleys
ID: 1309831
Hi,

I tried this and it didnt change the text. Im able to open my dialog and the initial message from OnInitControl pops up but my calls to the ChangeText function are not updating the text as I process. Here is the whole code from the Dialog class.

Am I missing any event handlers that should be set or properties on my dialog box or edit control??

/////////////////////////////////////////////////////////////////////////////
// CProcessingDialog dialog


CProcessingDialog::CProcessingDialog(CWnd* pParent /*=NULL*/)
      : CDialog(CProcessingDialog::IDD, pParent)
{
      //{{AFX_DATA_INIT(CProcessingDialog)
      //}}AFX_DATA_INIT
      ASSERT(pParent != NULL);

      m_pParent = pParent;
      m_nID = CProcessingDialog::IDD;
}

void CProcessingDialog::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CProcessingDialog)
      //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CProcessingDialog, CDialog)
      //{{AFX_MSG_MAP(CProcessingDialog)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CProcessingDialog::Create()
{
      // TODO: Add your specialized code here and/or call the base class
      return CDialog::Create(m_nID, m_pParent);
}

void CProcessingDialog::ChangeText(char *cMsg)
{
      // TODO: Add extra initialization here
      // Get a handle to the CEdit control
      CEdit* pEdit = (CEdit*) (GetDlgItem(IDC_PROCESSING_Txt));

      // Set the text with the text being passed in
      pEdit->SetWindowText(cMsg);

      UpdateData(FALSE);

}

BOOL CProcessingDialog::OnInitDialog()
{
      CDialog::OnInitDialog();
      
      // TODO: Add extra initialization here
      // Get a handle to the CEdit control
      CEdit* pEdit = (CEdit*) (GetDlgItem(IDC_PROCESSING_Txt));

      // Set the text with the text being passed in
      pEdit->SetWindowText("This is the initial message...");
      
      return TRUE;  // return TRUE unless you set the focus to a control
                    // EXCEPTION: OCX Property Pages should return FALSE
}


0
 
LVL 3

Expert Comment

by:MDarling
ID: 1309832
Bind a member variable to your edit control of type CString, eg. strMsg;

Change your method to this

void CProcessingDialog::ChangeText(char *cMsg)
      {
      strMsg=CString(cMsg);
      UpdateData(FALSE);

      }

Your code should then update fine.

regards,
mike.
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:mosleys
ID: 1309833
Tried MDarlings suggestion but it still does not work.. I need to be able to modify the text in the edit control located in the CPRocessingDialog popup that I create while processing in my main app dialog. Still must be missing something basic as I am a novice VC programmer trying to learn hands on. Any other suggestions??
0
 

Author Comment

by:mosleys
ID: 1309834
I'm able to change the text in the title bar with SetWindowText (see below) but still not able to update the text in the edit control in my dialog box. UpdateData(FALSE) has not worked.. any other suggestions??

void CProcessingDialog::ChangeText(char *cMsg)
{
      // Get a handle to the CEdit control
      CEdit* pEdit = (CEdit*) (GetDlgItem(IDC_PROCESSING_Txt));

      // Set the text with the text being passed in
      SetWindowText(cMsg); // This will set the text of the window title bar
      
      pEdit->SetWindowText(cMsg);
      
      UpdateData(FALSE);

}
0
 
LVL 7

Expert Comment

by:leflon
ID: 1309835
you said you open your dlg from your main app.
how do you do this?
is the dialog present (non modal) while the rest of your app is running?
0
 
LVL 2

Expert Comment

by:SamratAshok
ID: 1309836
you probably also need to create a thread to update the dialog box
because your main thread is busy doing the Processing.

In some cases however, you can try Invalidating the dialog window
which effectively sends WM_PAINT message and it may get repainted.
after a call to UpdateData(FALSE);
0
 

Author Comment

by:mosleys
ID: 1309837
Here is how I create the dialog from my main app.
   // Create a child window dialog to show which MLCS system is currently being searched
   CProcessingDialog*      m_pProcessingDlg = new CProcessingDialog(this);
   m_pProcessingDlg->Create();

   TrimRight(MLCSColor);
   sprintf(cMsg, "Looking for %s on %s...", LoanNumber,    MLCSColor);
   m_pProcessingDlg->ChangeText(cMsg);

I continue on processing in my main app in a loop, changing the text for each server I have to look in until Ive found what Im looking for and then call the following to destroy the window when Im done:
      m_pProcessingDlg->DestroyWindow();
0
 
LVL 30

Accepted Solution

by:
SteveGTR earned 80 total points
ID: 1309838
You have to give Windows a change to process the messages that will cause your dialog to update. This routine does that:

BOOL Pump()
{
  MSG msg;

  // Retrieve and diapatch any waiting messages
  while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
    if (!AfxGetApp()->PumpMessage())
      {
      ::PostQuitMessage(0);
      return FALSE;
      }

  // Simulate the framework's idle processing mechanism
  LONG lIdle = 0L;
  while (AfxGetApp()->OnIdle(lIdle++))
    ;
  return TRUE;
}

When your processing information in your loop and updating the text on the dialog box call Pump() or perform the processing above. This was taken from Jeff Prosise’s column "Wicked Code" in the Microsoft Systems Journal (MSJ) dated 2/97 (Vol 12/No 2). This code can also be found in the help file somewhere.

Good Luck,
Steve

0
 

Author Comment

by:mosleys
ID: 1309839
Steve,

Thanks for your help... That did the trick!!!
Thanks to everyone else for their help too!!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

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