如何将一个类文件中的变量反映到另一个类文件中 [英] How to reflect the variable changing in one class file to another class file..

查看:79
本文介绍了如何将一个类文件中的变量反映到另一个类文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写套接字应用程序,其中服务器每两秒发送一次数据。



在客户端,它是一个SDI应用程序,其中收到的数据需要是绘制成图形。



所以我在CSockEt_Client接收数据:: OnReceive()



但怎么能我反思CClientView :: OnDraw(CDC * pDC)

到Plot Graph ..?

在服务器上

Hi Im writing socket appliction,where server is sending data for every two seconds.

At client side it is a SDI application where the data received need to be plotted as graph.

so Im receiving data at CSockEt_Client::OnReceive()

But how can i reflect on CClientView::OnDraw(CDC *pDC)
to Plot Graph..?
At Server

while(1)
		{
			for(int i=0;i<col;i++)
			{
						Sleep(2000);
				
					fdata.w1=a[i][0];
					fdata.w2=a[i][1];
					fdata.w3=a[i][2];
					fdata.w4=a[i][3];
					                                  m_server.m_client.Send(&fdata,sizeof(fdata));

			}





在客户端



At Client side

void CClient_Socket::OnReceive(int nErrorCode) 
{	filedata fdata;
	
		int br=Receive(&fdata,sizeof(fdata));
                w[0]=fdata.w1;
		w[1]=fdata.w2;
		w[2]=fdata.w3;
		w[3]=fdata.w4;
CSocket::OnReceive(nErrorCode);
}







void CClient_graphView::OnDraw(CDC* dc)
{
	CClient_graphDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	m_Graph->DrawGraph(dc);							          							     m_Graph->AddPoint(dc, w[0]);
}





所以我需要以什么方式声明int w [i] ...静态,外部.. 。$



请帮帮我..



提前致谢..



so in what way i need to declare int w[i]... either static,extern...?

please help me out..

Thanks in advance..

推荐答案

CDocument :: UpdateAllViews() [ ^ ]。


在SDI应用程序中,文档类应该包含所有数据,因此图形的点将存储在那里,可能是某种类变量(数组,列表,向量等)。然后在您的绘图代码中使用该数据绘制适合窗口可见部分的图片部分(允许滚动等)。对 CDocument :: UpdateAllViews()的调用可确保在文档内容被修改后重新绘制窗口。
In a SDI application the document class should hold all your data, so the points of the graph will be stored there, probably as some sort of class variable (array, list, vector etc). Then in your drawing code you use that data to draw the part of your picture that fits the visible portion of your window (allowing for scrolling etc.). The call to CDocument::UpdateAllViews() ensures that your window is repainted after the document''s contents have been modified.


这篇关于如何将一个类文件中的变量反映到另一个类文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆