<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Text von Thread an die View übermitteln]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>Hab leider noch net viel Erfahrung mit MFC und soll nun ein Prog schreiben, das Texte von anderen Programmen empfängt und anzeigt. Empfangen wird der Text mit einer Pipe, die in einem Thread läuft aber wie bekomme ich nun den empfangenen text in der View angezeigt.</p>
<blockquote>
<p>Die Thread Funktion</p>
</blockquote>
<pre><code class="language-cpp">HANDLE ThreadHandle;
//	INT i;
	DWORD ThreadId;

		// Create a thread to serve each pipe instance  
	if ((ThreadHandle = ::CreateThread(NULL, 0, PipeInstanceProc,
			NULL, 0, &amp;ThreadId)) == NULL)
		{
			printf(&quot;CreateThread failed with error %\n&quot;,
				GetLastError());
			return FALSE;
		}
		CloseHandle(ThreadHandle);

	return TRUE;
}
</code></pre>
<blockquote>
<p>Die Pipe Funktion</p>
</blockquote>
<pre><code class="language-cpp">DWORD WINAPI PipeInstanceProc(LPVOID lpParameter)
{
	HANDLE PipeHandle;
	DWORD BytesRead;
	CHAR buffer[256];

	if ((PipeHandle = CreateNamedPipe(&quot;\\\\.\\Pipe\\Jim&quot;,
		PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1,
		0, 0, 1000, NULL)) == INVALID_HANDLE_VALUE)
	{
		printf(&quot;CreateNamedPipe failed with error %d\n&quot;,
			GetLastError());
		return 1;
	}

	printf(&quot;Server is now running\n&quot;);

	while(true) {
		if (ConnectNamedPipe(PipeHandle, NULL) == 0)
		{
			printf(&quot;ConnectNamedPipe failed with error %d\n&quot;,
				GetLastError());
			CloseHandle(PipeHandle);
			return 1;
		}

		if (ReadFile(PipeHandle, buffer, sizeof(buffer),
			&amp;BytesRead,  NULL) &lt;= 0)
		{
			printf(&quot;ReadFile failed with error %d\n&quot;, GetLastError());
			CloseHandle(PipeHandle);
			return 1;
		}

		printf(&quot;%.*s\n&quot;, BytesRead, buffer);

		if (DisconnectNamedPipe(PipeHandle) == 0)
		{
			printf(&quot;DisconnectNamedPipe failed with error %d\n&quot;,
				GetLastError());
			return 1;
		}
	}
	CloseHandle(PipeHandle);
	return 0;
}
</code></pre>
<blockquote>
<p>und die View</p>
</blockquote>
<pre><code class="language-cpp">void CMFCStartUpView::OnDraw(CDC* pDC)
{

	CMFCStartUpDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	CRect rc;
	GetClientRect(&amp;rc);

	CFont Fnt1, Fnt2, *pOldFnt;

	LOGFONT lfnt;
	ZeroMemory(&amp;lfnt, sizeof(LOGFONT));
	strcpy(lfnt.lfFaceName, &quot;Arial&quot;);
	lfnt.lfWeight	= FW_BOLD;
	lfnt.lfHeight	= 20;
	Fnt1.CreateFontIndirect(&amp;lfnt);

	lfnt.lfHeight	= 25;
	lfnt.lfUnderline = TRUE;
	Fnt2.CreateFontIndirect(&amp;lfnt);

	CMFCStartUpView::InitiateTrace();
	CMFCStartUpView::DeInitiateTrace();
	CMFCStartUpView::ReadTrace();

//	m_szBuffer=&quot;Hallo&quot;;
	pOldFnt = (CFont *)pDC-&gt;SelectObject(&amp;Fnt1);

	pDC-&gt;DrawText(m_szBuffer, rc, DT_TOP);
	pDC-&gt;SetTextColor(RGB(0,150,0));
//	pDC-&gt;DrawText(sTxt1, rc, DT_CENTER);

	int dx = (int)0.2*rc.Width();
	int dy = (int)0.45*rc.Height();
	m_LinkRect = CRect(rc.left+dx, rc.top+dy, rc.right-dy, rc.bottom-dy);

	pDC-&gt;SelectObject(pOldFnt);
	UpdateWindow();
}
</code></pre>
<p>Pipe und thread befinden sich in der selben Quellcode-Datei, die View in einer anderen.</p>
<p>Mir wurde bereits gesagt dass das irgendwie mit <em>GetActiveView()-&gt;Postmessage</em> funktionieren soll aber ich hab da bisher nicht so den passenden Ansatz gefunden.</p>
<p>Wäre Super wenn mir da jemand helfen könnte.</p>
<p>mfg</p>
<p>Phoe</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/204922/text-von-thread-an-die-view-übermitteln</link><generator>RSS for Node</generator><lastBuildDate>Sat, 04 Apr 2026 04:47:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/204922.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 08 Feb 2008 11:04:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Text von Thread an die View übermitteln on Fri, 08 Feb 2008 11:04:38 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>Hab leider noch net viel Erfahrung mit MFC und soll nun ein Prog schreiben, das Texte von anderen Programmen empfängt und anzeigt. Empfangen wird der Text mit einer Pipe, die in einem Thread läuft aber wie bekomme ich nun den empfangenen text in der View angezeigt.</p>
<blockquote>
<p>Die Thread Funktion</p>
</blockquote>
<pre><code class="language-cpp">HANDLE ThreadHandle;
//	INT i;
	DWORD ThreadId;

		// Create a thread to serve each pipe instance  
	if ((ThreadHandle = ::CreateThread(NULL, 0, PipeInstanceProc,
			NULL, 0, &amp;ThreadId)) == NULL)
		{
			printf(&quot;CreateThread failed with error %\n&quot;,
				GetLastError());
			return FALSE;
		}
		CloseHandle(ThreadHandle);

	return TRUE;
}
</code></pre>
<blockquote>
<p>Die Pipe Funktion</p>
</blockquote>
<pre><code class="language-cpp">DWORD WINAPI PipeInstanceProc(LPVOID lpParameter)
{
	HANDLE PipeHandle;
	DWORD BytesRead;
	CHAR buffer[256];

	if ((PipeHandle = CreateNamedPipe(&quot;\\\\.\\Pipe\\Jim&quot;,
		PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1,
		0, 0, 1000, NULL)) == INVALID_HANDLE_VALUE)
	{
		printf(&quot;CreateNamedPipe failed with error %d\n&quot;,
			GetLastError());
		return 1;
	}

	printf(&quot;Server is now running\n&quot;);

	while(true) {
		if (ConnectNamedPipe(PipeHandle, NULL) == 0)
		{
			printf(&quot;ConnectNamedPipe failed with error %d\n&quot;,
				GetLastError());
			CloseHandle(PipeHandle);
			return 1;
		}

		if (ReadFile(PipeHandle, buffer, sizeof(buffer),
			&amp;BytesRead,  NULL) &lt;= 0)
		{
			printf(&quot;ReadFile failed with error %d\n&quot;, GetLastError());
			CloseHandle(PipeHandle);
			return 1;
		}

		printf(&quot;%.*s\n&quot;, BytesRead, buffer);

		if (DisconnectNamedPipe(PipeHandle) == 0)
		{
			printf(&quot;DisconnectNamedPipe failed with error %d\n&quot;,
				GetLastError());
			return 1;
		}
	}
	CloseHandle(PipeHandle);
	return 0;
}
</code></pre>
<blockquote>
<p>und die View</p>
</blockquote>
<pre><code class="language-cpp">void CMFCStartUpView::OnDraw(CDC* pDC)
{

	CMFCStartUpDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	CRect rc;
	GetClientRect(&amp;rc);

	CFont Fnt1, Fnt2, *pOldFnt;

	LOGFONT lfnt;
	ZeroMemory(&amp;lfnt, sizeof(LOGFONT));
	strcpy(lfnt.lfFaceName, &quot;Arial&quot;);
	lfnt.lfWeight	= FW_BOLD;
	lfnt.lfHeight	= 20;
	Fnt1.CreateFontIndirect(&amp;lfnt);

	lfnt.lfHeight	= 25;
	lfnt.lfUnderline = TRUE;
	Fnt2.CreateFontIndirect(&amp;lfnt);

	CMFCStartUpView::InitiateTrace();
	CMFCStartUpView::DeInitiateTrace();
	CMFCStartUpView::ReadTrace();

//	m_szBuffer=&quot;Hallo&quot;;
	pOldFnt = (CFont *)pDC-&gt;SelectObject(&amp;Fnt1);

	pDC-&gt;DrawText(m_szBuffer, rc, DT_TOP);
	pDC-&gt;SetTextColor(RGB(0,150,0));
//	pDC-&gt;DrawText(sTxt1, rc, DT_CENTER);

	int dx = (int)0.2*rc.Width();
	int dy = (int)0.45*rc.Height();
	m_LinkRect = CRect(rc.left+dx, rc.top+dy, rc.right-dy, rc.bottom-dy);

	pDC-&gt;SelectObject(pOldFnt);
	UpdateWindow();
}
</code></pre>
<p>Pipe und thread befinden sich in der selben Quellcode-Datei, die View in einer anderen.</p>
<p>Mir wurde bereits gesagt dass das irgendwie mit <em>GetActiveView()-&gt;Postmessage</em> funktionieren soll aber ich hab da bisher nicht so den passenden Ansatz gefunden.</p>
<p>Wäre Super wenn mir da jemand helfen könnte.</p>
<p>mfg</p>
<p>Phoe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1451829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1451829</guid><dc:creator><![CDATA[PhoenixONE]]></dc:creator><pubDate>Fri, 08 Feb 2008 11:04:38 GMT</pubDate></item><item><title><![CDATA[Reply to Text von Thread an die View übermitteln on Fri, 08 Feb 2008 14:42:35 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">GetActiveView()-&gt;SendMessage(WM_APP_ADDTEXT, NULL, reinterpret_cast&lt;LPARAM&gt;( string.GetString() ));
</code></pre>
<p>und dann im view auf die message reagieren mit ON_MESSAGE, etc.<br />
also:</p>
<pre><code class="language-cpp">ON_MESSAGE(WM_APP_ADDTEXT, OnAddText)
//...
LRESULT DeineViewKlasse::OnAddText(WPARAM wParam, LPARAM lParam)
{
	CString message = reinterpret_cast&lt;LPCTSTR&gt;( lParam );

	if(message != _T(&quot;&quot;))
	    //zeig den text an...

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1452018</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452018</guid><dc:creator><![CDATA[Machine]]></dc:creator><pubDate>Fri, 08 Feb 2008 14:42:35 GMT</pubDate></item></channel></rss>