GUI Creation

Hey all,

Please let me know how to learn GUI creation using MFC or any other method. I have made a chatting application using sockets on win32 console. I want it on GUI now. Please provide me with any link where I can learn the same.

Thanks in advance,
Abhishek
Win 32 API tutorial:
http://msdn.microsoft.com/en-us/library/bb384843.aspx

MFC tutorials:
http://msdn.microsoft.com/en-us/library/aa270890%28v=vs.60%29.aspx

Qt tutorials
http://www.digitalfanatics.org/projects/qt_tutorial/

wxWidgets tutorials
http://www.wxwidgets.org/docs/tutorials.htm

Which of those is the most appropitiate for your project depends on your project and personal preference.
Thanks for your response. I want to use MFC for GUI creation. I just want to create a edit box, a output box where chat can be seen, and a send button. Please tell me some one knows how to do it.
The first tutorial covers most of that.
Well mate,
I have wressetled with the very same question for last few months. I dont think there is an simple anwer to it. You see you have got to get your head around generic programing and concencepts of callbacks. I got myself a book by Bjarne stroustrup Programming principles and practice using C++ The book is devided in to 4 parts and the second part teaches you about GUI using fltk.
It is probably not the best book in the world, but it certainly thougth me a lot. One of the exersizes is to read data into the inbox and draw a graf... I would suggest that you get a pdf of the book from somewhere see if you like it and the best thing would by to buy it. Also, be prepared to spend some time with it, it isnt going to happen over night.
Good luck mate
I dont think there is an simple anwer to it.

Actually, if he already has written a chat client I'd say that he is capable enough to learn in a short enough amount of time how to create a window and pass some text information to it.

And windows programming hasn't got anything to do with generic programming. In the first place, the Win32 API is written in C.

As words of encouragement to the OP, don't let yourself get confused by the weird syntax of the windows API - then again, if you already used winsock you probably already saw quite a bit of that.
Last edited on
Hey thanks guys for reply.
I am trying my hand with MFC. I am working since morning and its around 7 hours now. LOL
I have prepared a GUI for client. Connection with server is created using GUI. However, I am facing a little issue. Once the server send some thing, it is received in buffer at client. I am putting the data from buffer to output window (which is a EDIT BOX on GUI) of client using SetDlgItemText(). However, as the compiler reach SetDlgItemText() an error is flashed:


DEBUG ASSERTION FAILED!
FILE: winocc.cpp
Line 138



By debugging I came to know that error appears when SetDlgItemText() is called. I went to winocc.cpp at line 138 as well. There also the same function was pointed out.

Part of my code is shown below where error came:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

void Readthread(void *parameter)
{
	
	CGUI_chatDlg c;
	char buff[512];
	
	unsigned int cd=(unsigned int)parameter;
	while(1)
	{
		
		
		if(recv(cd,buff,sizeof(buff),0)!=SOCKET_ERROR)  /*recv returns a positive value*/
		{	
			//cout<<endl<<"From Server:"<<buff<<flush;

			
			c.SetDlgItemText(IDC_EDIT2,buff);
			memset(buff,0,512);
			//cout<<"\n\n"<<flush;
		}
		
	}
}




Part of file winocc.cpp around line 138 is also shown below:

1
2
3
4
5
6
7
8
9
10

void CWnd::SetDlgItemText(int nID, LPCTSTR lpszString)
{
	ASSERT(::IsWindow(m_hWnd));

	if (m_pCtrlCont == NULL)
		::SetDlgItemText(m_hWnd, nID, lpszString);
	else
		m_pCtrlCont->SetDlgItemText(nID, lpszString);
}




Please help me guys. I am out of my mind with this error.

Regards,
Abhishek
Last edited on
Questions:

1) Did you actually create a window for c?
2) Is the data you receive in buf a zero terminated string? You could be missing out the \0 at the end or something, did you already check that?
3) Is readthread an actual thread?
Answers

1. yes
2. I have checked. Its null terminated.
3. Yes its a thread which collects data it receive from server in a buff.
Where do you create c? I mean, you must have done something wrong, and I don't see where in that code your error would be.
ok. Let me tell you brief about how the code is written.

I have created GUI using MFC application wizard.
below is the code for OK button on GUI:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void CGUI_chatDlg::OnOK() 
{
	// TODO: Add extra validation here
	unsigned int connect, disconnect;
	connect=IsDlgButtonChecked(IDC_RADIO1); //to connect to server. It is a radio button to connect to server. On GUI you need to click on this button and click OK.
	disconnect=IsDlgButtonChecked(IDC_RADIO2);
	if(connect==1)
	{	
		client_program(); //Function where whole code to connect to server using winsock2 concepts.
	}

//	CDialog::OnOK();
}




Now code for client_program() is written below the above code:
Not listing the full code.

1
2
3
4
5
6
7
8
9
10
void client_program()
{
// all the code here

//connection to server

	sd=connect(cd,(sockaddr*)&client,client_length);
	_beginthread(Readthread,0,(void*)cd);  //Thread to read data from server.
}



Then read thread is defined below it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

void Readthread(void *parameter)
{
	
	CGUI_chatDlg c;
	char buff[512];
	
	unsigned int cd=(unsigned int)parameter;
	while(1)
	{
		
		
		if(recv(cd,buff,sizeof(buff),0)!=SOCKET_ERROR)  /*recv returns a positive value*/
		{	
			//cout<<endl<<"From Server:"<<buff<<flush;

			
			c.SetDlgItemText(IDC_EDIT2,buff);  // PROBLEM IS INVOKED HERE.
			memset(buff,0,512);
			//cout<<"\n\n"<<flush;
		}
		
	}
}


PROBLEM IS INVOKED at the place pointed in comment in Readthread.

Last edited on
Topic archived. No new replies allowed.