<?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 im Editfeld per Button ändern]]></title><description><![CDATA[<p>Hi @ All</p>
<p>Also ich beschäftige mich zur Zeit mit einem Programm mit dem ich in einer TXT-Datei nach einem bestimmten wort suchen kann, und das ergebnis in einem Editfeld ausgebe. Dafür erzeuge ich im Bereich WM_CREATE ein Editfeld. Davor lese ich die Txt-Datei aus.</p>
<p>Das sieht dann so aus.</p>
<pre><code class="language-cpp">char * buffer = NULL;
			FILE *fz;
			int iFileSize;

			fz = fopen(&quot;text.txt&quot;, &quot;rb&quot;);
			if(fz != NULL)
			{
				fseek(fz, 0, SEEK_END);
				iFileSize = ftell(fz);
				buffer = (char *)malloc(iFileSize);

				fseek(fz, 0, SEEK_SET);
				fread(buffer, 1, iFileSize, fz);
				fclose(fz);
			}

			hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
					&quot;edit&quot;,
					buffer,    // &lt;- das ist der Inhalt der Editfelds
					WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL,
					10, 50, 200, 200,
					hWnd,
					NULL,
					((LPCREATESTRUCT) lParam) -&gt; hInstance,
					NULL);
			free(buffer);
</code></pre>
<p>Nun... Bis dahin auch noch nicht wirklich ein Problem.<br />
Jetzt wird jedoch jedes mal wenn ich das Fenster öffne die Txt ausgelesen und in das Feld eingefügt. Ich möchte jedoch das es erst eingelesen wird wenn ich einen Button drücke.</p>
<p>Doch das kriege ich leider nicht hin.<br />
Wenn ich den Button drücke, versuche ich die Nachricht WM_COMMAND zu bearbeiten.<br />
Auch da kann ich die txt auslesen.<br />
Doch leider kann ich das ausgelesene nich in das Editfeld schreiben welches ich bei WM_CREATE erzeugt habe. Wenn ich das Editfeld in WM_COMMAND Bereich erstellen möchte kriege ich einen Laufzeitfehler präsentiert.</p>
<p>Kann mir da vllt jemand einen wink mit dem Zaunpfahl geben.</p>
<p>Herzlichen dank schon mal<br />
Sqwan...</p>
<p>Hier auch mal der rest des progs..<br />
Falls der Fehler woanders liegt.</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

	static HWND hEdit;
	static HWND hButton;
	static HWND hEdit1;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
    HWND     hWnd;
    MSG      msg;
    WNDCLASS wc;

    const char szAppName[] = &quot;Editcontrol Tutorial&quot;;

    wc.style          = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc    = WndProc;
    wc.cbClsExtra     = 0;
    wc.cbWndExtra     = 0;
    wc.hInstance      = hInstance;
    wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground  = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
    wc.lpszMenuName   = NULL;
    wc.lpszClassName  = szAppName;

    RegisterClass(&amp;wc);

    hWnd = CreateWindow( szAppName,
                         &quot;Editcontrol Tutorial&quot;,
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         NULL,
                         NULL,
                         hInstance,
                         NULL );

    ShowWindow(hWnd, iCmdShow);
    UpdateWindow(hWnd);

    while(GetMessage(&amp;msg, NULL, 0, 0))
    {
        TranslateMessage(&amp;msg);
        DispatchMessage(&amp;msg);
    }

    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
		case WM_CREATE:
		{
			char * buffer = NULL;
			FILE *fz;
			int iFileSize;

			fz = fopen(&quot;text.txt&quot;, &quot;rb&quot;);
			if(fz != NULL)
			{
				fseek(fz, 0, SEEK_END);
				iFileSize = ftell(fz);
				buffer = (char *)malloc(iFileSize);

				fseek(fz, 0, SEEK_SET);
				fread(buffer, 1, iFileSize, fz);
				fclose(fz);
			}

			hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
					&quot;edit&quot;,
					buffer,    // &lt;- das ist der Inhalt der Editfelds
					WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL,
					10, 50, 200, 200,
					hWnd,
					NULL,
					((LPCREATESTRUCT) lParam) -&gt; hInstance,
					NULL);
			free(buffer);
			hButton = CreateWindow(&quot;button&quot;,
                      &quot;Beenden&quot;,
                      WS_CHILD | WS_VISIBLE,
                      110, 10, 100, 20,
                      hWnd,
                      NULL,
                      ((LPCREATESTRUCT) lParam) -&gt; hInstance,
                      NULL);

			hEdit1 = CreateWindowEx(WS_EX_CLIENTEDGE,
					&quot;edit&quot;,
					&quot;&quot;,    // &lt;- das ist der Inhalt der Editfelds
					WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL,
					10, 10, 100, 20,
					hWnd,
					NULL,
					((LPCREATESTRUCT) lParam) -&gt; hInstance,
					NULL);
            return 0;
		}
		case WM_COMMAND:
		{
			return 0;
		}

		case WM_SIZE:
        {
			//MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
            return 0;
        }
		case WM_CLOSE:
        {
			FILE *fz;
            char *buffer = NULL;
            int iLength;

            iLength = GetWindowTextLength(hEdit);

            buffer = (char *)malloc(iLength);

            GetWindowText(hEdit, buffer, iLength);

            fz = fopen(&quot;text.txt&quot;, &quot;wb&quot;);
			fprintf(fz,&quot;%s\n&quot;,buffer);
            fclose(fz);
			free(buffer);
            DestroyWindow(hWnd);
            return 0;
        }
		case WM_DESTROY:
        {
            PostQuitMessage(0);

            return 0;
        }
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/187721/text-im-editfeld-per-button-ändern</link><generator>RSS for Node</generator><lastBuildDate>Sat, 04 Jul 2026 05:25:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/187721.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 23 Jul 2007 12:17:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Text im Editfeld per Button ändern on Mon, 23 Jul 2007 12:17:20 GMT]]></title><description><![CDATA[<p>Hi @ All</p>
<p>Also ich beschäftige mich zur Zeit mit einem Programm mit dem ich in einer TXT-Datei nach einem bestimmten wort suchen kann, und das ergebnis in einem Editfeld ausgebe. Dafür erzeuge ich im Bereich WM_CREATE ein Editfeld. Davor lese ich die Txt-Datei aus.</p>
<p>Das sieht dann so aus.</p>
<pre><code class="language-cpp">char * buffer = NULL;
			FILE *fz;
			int iFileSize;

			fz = fopen(&quot;text.txt&quot;, &quot;rb&quot;);
			if(fz != NULL)
			{
				fseek(fz, 0, SEEK_END);
				iFileSize = ftell(fz);
				buffer = (char *)malloc(iFileSize);

				fseek(fz, 0, SEEK_SET);
				fread(buffer, 1, iFileSize, fz);
				fclose(fz);
			}

			hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
					&quot;edit&quot;,
					buffer,    // &lt;- das ist der Inhalt der Editfelds
					WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL,
					10, 50, 200, 200,
					hWnd,
					NULL,
					((LPCREATESTRUCT) lParam) -&gt; hInstance,
					NULL);
			free(buffer);
</code></pre>
<p>Nun... Bis dahin auch noch nicht wirklich ein Problem.<br />
Jetzt wird jedoch jedes mal wenn ich das Fenster öffne die Txt ausgelesen und in das Feld eingefügt. Ich möchte jedoch das es erst eingelesen wird wenn ich einen Button drücke.</p>
<p>Doch das kriege ich leider nicht hin.<br />
Wenn ich den Button drücke, versuche ich die Nachricht WM_COMMAND zu bearbeiten.<br />
Auch da kann ich die txt auslesen.<br />
Doch leider kann ich das ausgelesene nich in das Editfeld schreiben welches ich bei WM_CREATE erzeugt habe. Wenn ich das Editfeld in WM_COMMAND Bereich erstellen möchte kriege ich einen Laufzeitfehler präsentiert.</p>
<p>Kann mir da vllt jemand einen wink mit dem Zaunpfahl geben.</p>
<p>Herzlichen dank schon mal<br />
Sqwan...</p>
<p>Hier auch mal der rest des progs..<br />
Falls der Fehler woanders liegt.</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

	static HWND hEdit;
	static HWND hButton;
	static HWND hEdit1;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
    HWND     hWnd;
    MSG      msg;
    WNDCLASS wc;

    const char szAppName[] = &quot;Editcontrol Tutorial&quot;;

    wc.style          = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc    = WndProc;
    wc.cbClsExtra     = 0;
    wc.cbWndExtra     = 0;
    wc.hInstance      = hInstance;
    wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground  = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
    wc.lpszMenuName   = NULL;
    wc.lpszClassName  = szAppName;

    RegisterClass(&amp;wc);

    hWnd = CreateWindow( szAppName,
                         &quot;Editcontrol Tutorial&quot;,
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         NULL,
                         NULL,
                         hInstance,
                         NULL );

    ShowWindow(hWnd, iCmdShow);
    UpdateWindow(hWnd);

    while(GetMessage(&amp;msg, NULL, 0, 0))
    {
        TranslateMessage(&amp;msg);
        DispatchMessage(&amp;msg);
    }

    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
		case WM_CREATE:
		{
			char * buffer = NULL;
			FILE *fz;
			int iFileSize;

			fz = fopen(&quot;text.txt&quot;, &quot;rb&quot;);
			if(fz != NULL)
			{
				fseek(fz, 0, SEEK_END);
				iFileSize = ftell(fz);
				buffer = (char *)malloc(iFileSize);

				fseek(fz, 0, SEEK_SET);
				fread(buffer, 1, iFileSize, fz);
				fclose(fz);
			}

			hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
					&quot;edit&quot;,
					buffer,    // &lt;- das ist der Inhalt der Editfelds
					WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL,
					10, 50, 200, 200,
					hWnd,
					NULL,
					((LPCREATESTRUCT) lParam) -&gt; hInstance,
					NULL);
			free(buffer);
			hButton = CreateWindow(&quot;button&quot;,
                      &quot;Beenden&quot;,
                      WS_CHILD | WS_VISIBLE,
                      110, 10, 100, 20,
                      hWnd,
                      NULL,
                      ((LPCREATESTRUCT) lParam) -&gt; hInstance,
                      NULL);

			hEdit1 = CreateWindowEx(WS_EX_CLIENTEDGE,
					&quot;edit&quot;,
					&quot;&quot;,    // &lt;- das ist der Inhalt der Editfelds
					WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL,
					10, 10, 100, 20,
					hWnd,
					NULL,
					((LPCREATESTRUCT) lParam) -&gt; hInstance,
					NULL);
            return 0;
		}
		case WM_COMMAND:
		{
			return 0;
		}

		case WM_SIZE:
        {
			//MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
            return 0;
        }
		case WM_CLOSE:
        {
			FILE *fz;
            char *buffer = NULL;
            int iLength;

            iLength = GetWindowTextLength(hEdit);

            buffer = (char *)malloc(iLength);

            GetWindowText(hEdit, buffer, iLength);

            fz = fopen(&quot;text.txt&quot;, &quot;wb&quot;);
			fprintf(fz,&quot;%s\n&quot;,buffer);
            fclose(fz);
			free(buffer);
            DestroyWindow(hWnd);
            return 0;
        }
		case WM_DESTROY:
        {
            PostQuitMessage(0);

            return 0;
        }
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1330791</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1330791</guid><dc:creator><![CDATA[Sqwan]]></dc:creator><pubDate>Mon, 23 Jul 2007 12:17:20 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Editfeld per Button ändern on Mon, 23 Jul 2007 12:23:05 GMT]]></title><description><![CDATA[<p>Setz den Text per <em>SendMessage</em> in das Feld</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1330796</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1330796</guid><dc:creator><![CDATA[gosha16]]></dc:creator><pubDate>Mon, 23 Jul 2007 12:23:05 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Editfeld per Button ändern on Mon, 23 Jul 2007 12:23:40 GMT]]></title><description><![CDATA[<p>probiers mal mit<br />
&quot;SetWindowText&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1330797</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1330797</guid><dc:creator><![CDATA[EXDW]]></dc:creator><pubDate>Mon, 23 Jul 2007 12:23:40 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Editfeld per Button ändern on Mon, 23 Jul 2007 12:43:17 GMT]]></title><description><![CDATA[<p>Hinweis: Diese (globalen) Variablen:</p>
<pre><code class="language-cpp">static HWND hEdit;
    static HWND hButton;
    static HWND hEdit1;
</code></pre>
<p>sollten lokal in der WndProc definiert werden; globale Variablen sollte man vermeiden, wenn das möglich ist (und hier ist es möglich) <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1330816</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1330816</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Mon, 23 Jul 2007 12:43:17 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Editfeld per Button ändern on Mon, 23 Jul 2007 13:15:24 GMT]]></title><description><![CDATA[<p>Also ich habe mich mal über SetWindowText erkundigt.<br />
Jedoch komme ich zu dem schluss das ich das nicht brauchen kann, da ja nicht angegeben wird von was genau geändert werden soll.</p>
<p>SetWindowText(hWnd, &quot;Die Position des Fensters wurde verändert&quot;);</p>
<p>Das habe ich als bsp gefunden und da kann ich ja nicht angeben das ich das edit feld ändern möchte.</p>
<p>Wenn ich SendMessage(hWnd, WM_CREATE, 0, 0);<br />
benutze kriege ich wieder einen Laufzeitfehler.<br />
Kann es sein das man WM_CREATE nicht machen darf, oder ist da noch was in meinem Code falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1330833</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1330833</guid><dc:creator><![CDATA[Sqwan]]></dc:creator><pubDate>Mon, 23 Jul 2007 13:15:24 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Editfeld per Button ändern on Mon, 23 Jul 2007 13:19:22 GMT]]></title><description><![CDATA[<p>Sqwan schrieb:</p>
<blockquote>
<p>da ja nicht angegeben wird von was genau geändert werden soll.</p>
</blockquote>
<p>Doch?! klar?! Du gibst den Handle des Edit-Felds an (1.Parameter).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1330837</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1330837</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Mon, 23 Jul 2007 13:19:22 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Editfeld per Button ändern on Mon, 23 Jul 2007 14:02:01 GMT]]></title><description><![CDATA[<p>in deinem fall:</p>
<p>SetWindowText(hEdit, &quot;Die Position des Fensters wurde verändert&quot;);</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1330871</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1330871</guid><dc:creator><![CDATA[EXDW]]></dc:creator><pubDate>Mon, 23 Jul 2007 14:02:01 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Editfeld per Button ändern on Mon, 23 Jul 2007 14:28:08 GMT]]></title><description><![CDATA[<p>Thx<br />
Mit SetWindowText(hEdit, buffer); kann ich per Buttonklick die daten die ich brauche nutzen.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/12048">@Codefinder</a><br />
Warum muss</p>
<pre><code class="language-cpp">static HWND hEdit;
    static HWND hButton;
    static HWND hEdit1;
</code></pre>
<p>local dafiniert werden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1330886</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1330886</guid><dc:creator><![CDATA[Sqwan]]></dc:creator><pubDate>Mon, 23 Jul 2007 14:28:08 GMT</pubDate></item></channel></rss>