Hi,

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.
Thanks..

Anu

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);
    if(csocket==INVALID_SOCKET)
    {
      MessageBox("Socket error",MB_OK);
      closesocket(s_socket);
    }    
    //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.*/
}

// 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)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);  // send to window proc
}

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

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

@sujayg
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
Thanks 

Try calling UpdateWindow after you call .put_Text("Waiting...")

@nullptr :Thanks a lot..Solved d prob
idc_textbox.put_Text("Waiting..");
UpdateWindow();

and thanks to all of u for ur timely help,

Anu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.