In Dialog based MFC code (VC++ 2012), I have two command buttons and 1 Text Box
1. Enquire
2. Start

Once the user chooses ENQUIRE Button, I display msg in TextBox "Press START for the ....."
In the Start Button code, I do the socket opening,accept functions etc
while the Server is waiting for the client to get connected, I want continous "Waiting..." message to be dsiplayed
in the TextBox.
How to get this displayed? Below is section of code where i want the msg to be displayed.


So when before accept(), i want the WAITING Msg text to be displayed.


void CAbtDlg::OnBnClickedStart()
  myport = 200;
  SOCKADDR_in socketaddress;  
  socketaddress.sin_family = PF_INET;
  socketaddress.sin_prt = htons((u_short)myport);
  socketaddress.sin_addr.s_addr = INADDR_ANY;  
  idc_txtbox.put_Text("Waiting.....");// I tied this too didnt work
  SetDlgItemTextA("Waiting...");//This too fails  
  csocket = accept(s_socket,NULL,NULL);
      MessageBox("Socket error",MB_OK);
    //do the other functions
    /*I read the data from text file and then put the data in variabale "UserIdent"
    once the whole file is read, i display the actual data in the text box   */
    idc_txtbox.put_Text(UserIdent); // This works.. 
    /*so i between when the file is fetched for reading, the textbox is blank (i want to notify the end user with a wait message). This is my requirement.*/

Edited by anukavi

4 Years
Discussion Span
Last Post by anukavi

// I tied this too didnt work

I think the problem is that MFC doesn't have a chance to process the message(s) until after that function returns. You need to add your own message pump after that line (see this article for full explanation).

MSG msg;
 while (GetMessage(&msg, NULL, 0, 0)) {
    DispatchMessage(&msg);  // send to window proc

Edited by Ancient Dragon


1) SetDlgItemTextA("Waiting...");//This too fails

You have to specify the window handle , which is not mentioned.

2) If you are using MFC, then there are two ways to do this

a) use GetDlgitem and typecast the returned pointer to CEdit ; then use the pointer
b) Declare a variable for the edit control and then do settext

Votes + Comments
thanks sujay.. and will try this and let u know.thanks once again
good point :)
@ancient dragon
i tried using MessageLoop but then MFC exe goes in infinite loop.
can u post me with an example

i used CWnd::SetDlgItemTextA(IDC_TEXTBOX7,"Waiting"); //This never gets displayed
"2) If you are using MFC, then there are two ways to do this"
I choose b) but still prob exists.

I am using Multibyte char set,VC++ compiler
When i use SetDlgItemTextA(IDC_COMMANDBUTTON7,"Waiting") , the value in the command button which is "Enquire" is replaced with "Waiting"
but the same fails when i do for TEXT BOX.
Quite desperate to fix this bug. 

**My code**

When i click ENQUIRE Button,this is my code
void CAbtDlg::OnBnClickedEnquire()
   idc_textbox.put_Text("Press START");
//and the code for START is already pasted.
**So far i am able to display "PRESS START" in the text box
but the same sytax does not work in START() function just before accept() function.
Pls help

@nullptr :Thanks a lot..Solved d prob

and thanks to all of u for ur timely help,


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.