Alan Kurlansky wrote:
To get myself starting I would like to write an app that simply receives messsages over a tcp connection and displays them to a scrolling window.
Hi Alan! I suggest an alternative approach without multi threading to get up and running quickly: 1) create a new MFC project and add a CListBox control: Using the CListBox control[^], this comes with a working example dialog project. 2) Add a TCP client socket such as CAsyncSocket to your dialog: Socket Programming with MFC (Part 1)[^], this will also explain which initialisation is needed in your application. 3) Add a button to your dialog so you can connect/disconnect to a server. The client will tell you in its OnReceive()[^] handler when more data is available, you can add this to the listbox with AddString()[^] and scroll listbox with SendMessage(WM_VSCROLL, SB_BOTTOM, NULL). There are many ways to communicate between socket and GUI, for starters you could give the socket object a pointer to your dialog. For example with a method OnReceiveText() that you call from your socket whenever a full text line is available:
// Add text to end of listbox and remove old text
void CMyDlg::OnReceiveText(const char* szText)
{
m_listbox.AddString(szText);
m_output.SendMessage(WM_VSCROLL, SB_BOTTOM, NULL);
while(m_output.GetCount() > 10000) m_output.DeleteString(0);
}
Hope this helps :) /Moak
Webchat in Europe :java: Now with 26% more Twitter