<?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[Editbox-Anfängerproblem]]></title><description><![CDATA[<p>hallo,</p>
<p>ich möchte ein kleines Programm schreiben mit dem ich einen Text in eine Editbox schreibe und mit einem click auf einen Button diesen Text mit TextOut() irgendwo im Fenster ausgebe und die Editbox wieder glöscht wird.</p>
<p>Mittlerweile habe ich auch herausgefunden das man mit CreateWindowEx arbeiten muss.</p>
<p>Aber irgendwie klappt das bei mir nicht so wie ich es will...</p>
<p>ich poste hier mal den relevanten Quellcode:</p>
<pre><code>LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 HDC hdc;
 PAINTSTRUCT ps;
 static HWND hwndButton1, hwndEdit2;
 char *buffer = NULL;
 int iLength;

 switch (message)
 {

  case WM_CREATE :

      hwndButton1 = CreateWindow ( &quot;button&quot;, &quot;Knopf 1&quot;,
                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                   150, 20, 100, 40, hwnd, (HMENU)1,
                                   (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

      hwndEdit2   = 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,
                                   200, 200, 200, 200,
                                   hwnd,
                                   (HMENU)2,
                                   ((LPCREATESTRUCT) lParam) -&gt; hInstance,
                                   NULL);
  return 0;

  case WM_COMMAND:
      switch(LOWORD(wParam))
      {
		case 1:

		    iLength = GetWindowTextLength(hwndEdit2);
		    buffer = malloc(iLength);    // &lt;----------Fehler hier !
                    GetWindowText(hwndEdit2, buffer, iLength+1);

		    SetWindowText(hwndEdit2,&quot;&quot;);

		    SendMessage(hwndEdit2, EM_SETREADONLY, TRUE, 0);
      break;
      case 2:
           SendMessage(hwndEdit2, EM_SETREADONLY, FALSE, 0);
      break;
      }
  return 0;

  case WM_PAINT:
      hdc = BeginPaint (hwnd, &amp;ps);
      SetTextColor(hdc, RGB(255,0,0) );
      SetBkColor(hdc, RGB(255,255,0) );
      TextOut (hdc, 20, 20, &quot;Ich bin ein Fenster.&quot;, 20);
      TextOut (hdc, 100, 700, buffer, 20);
      EndPaint (hwnd, &amp;ps);
  return 0;
  case WM_DESTROY:
      PostQuitMessage (0);
  return 0;
 }
</code></pre>
<p>Bekomme halt eine Fehlermeldung und hab keine ahnung wie ich die weg bekomme:</p>
<p>d:\C-Programme\test\main.cpp(88) : error C2440: '=': 'void *' kann nicht in 'char *' konvertiert werden</p>
<p>Wäre toll wenn sich jemand einem anfänger annehmen könnte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /></p>
<p>Danke schonmal im voraus</p>
<p>mfg Rille</p>
<p>//Sorry hab noch ein paar kleine Fehler entdeckt, klappt aber immernoch nicht so wie ich es mir wünsche....</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/154314/editbox-anfängerproblem</link><generator>RSS for Node</generator><lastBuildDate>Thu, 23 Jul 2026 11:38:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/154314.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 26 Jul 2006 09:24:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 09:32:28 GMT]]></title><description><![CDATA[<p>hallo,</p>
<p>ich möchte ein kleines Programm schreiben mit dem ich einen Text in eine Editbox schreibe und mit einem click auf einen Button diesen Text mit TextOut() irgendwo im Fenster ausgebe und die Editbox wieder glöscht wird.</p>
<p>Mittlerweile habe ich auch herausgefunden das man mit CreateWindowEx arbeiten muss.</p>
<p>Aber irgendwie klappt das bei mir nicht so wie ich es will...</p>
<p>ich poste hier mal den relevanten Quellcode:</p>
<pre><code>LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 HDC hdc;
 PAINTSTRUCT ps;
 static HWND hwndButton1, hwndEdit2;
 char *buffer = NULL;
 int iLength;

 switch (message)
 {

  case WM_CREATE :

      hwndButton1 = CreateWindow ( &quot;button&quot;, &quot;Knopf 1&quot;,
                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                   150, 20, 100, 40, hwnd, (HMENU)1,
                                   (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

      hwndEdit2   = 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,
                                   200, 200, 200, 200,
                                   hwnd,
                                   (HMENU)2,
                                   ((LPCREATESTRUCT) lParam) -&gt; hInstance,
                                   NULL);
  return 0;

  case WM_COMMAND:
      switch(LOWORD(wParam))
      {
		case 1:

		    iLength = GetWindowTextLength(hwndEdit2);
		    buffer = malloc(iLength);    // &lt;----------Fehler hier !
                    GetWindowText(hwndEdit2, buffer, iLength+1);

		    SetWindowText(hwndEdit2,&quot;&quot;);

		    SendMessage(hwndEdit2, EM_SETREADONLY, TRUE, 0);
      break;
      case 2:
           SendMessage(hwndEdit2, EM_SETREADONLY, FALSE, 0);
      break;
      }
  return 0;

  case WM_PAINT:
      hdc = BeginPaint (hwnd, &amp;ps);
      SetTextColor(hdc, RGB(255,0,0) );
      SetBkColor(hdc, RGB(255,255,0) );
      TextOut (hdc, 20, 20, &quot;Ich bin ein Fenster.&quot;, 20);
      TextOut (hdc, 100, 700, buffer, 20);
      EndPaint (hwnd, &amp;ps);
  return 0;
  case WM_DESTROY:
      PostQuitMessage (0);
  return 0;
 }
</code></pre>
<p>Bekomme halt eine Fehlermeldung und hab keine ahnung wie ich die weg bekomme:</p>
<p>d:\C-Programme\test\main.cpp(88) : error C2440: '=': 'void *' kann nicht in 'char *' konvertiert werden</p>
<p>Wäre toll wenn sich jemand einem anfänger annehmen könnte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /></p>
<p>Danke schonmal im voraus</p>
<p>mfg Rille</p>
<p>//Sorry hab noch ein paar kleine Fehler entdeckt, klappt aber immernoch nicht so wie ich es mir wünsche....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104393</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104393</guid><dc:creator><![CDATA[Rille]]></dc:creator><pubDate>Wed, 26 Jul 2006 09:32:28 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 09:45:07 GMT]]></title><description><![CDATA[<p>ich würde in deinem fall nicht mit dynamischer speicherverwaltung arbeiten, da du bei jedem btn klick den speicher testen müsstest, entsprechend freigeben und neu allokieren. stelle einfach einen ausreichend grossen buffer zu verfügung und gut ist.</p>
<pre><code class="language-cpp">static char buffer[512] = {0};
// ...
case 1:
  GetWindowText(hwndEdit2, &amp;buffer, sizeof(buffer));
// ...
</code></pre>
<p>zum zeitpunkt von WM_CREATE steht bestimmt noch nix in buffer somit ist es sinnlos.</p>
<pre><code class="language-cpp">hwndEdit2   = 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,
                                   200, 200, 200, 200,
                                   hwnd,
                                   (HMENU)2,
                                   ((LPCREATESTRUCT) lParam) -&gt; hInstance,
                                   NULL);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1104413</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104413</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Wed, 26 Jul 2006 09:45:07 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 09:53:33 GMT]]></title><description><![CDATA[<p>danke für deine hilfe miller_m,</p>
<p>blöd nur dass ich immernoch Fehlermeldungen bekomme:</p>
<p>d:\C-Programme\test\main.cpp(81) : error C2664: 'GetWindowTextA': Konvertierung des Parameters 2 von 'char (*__w64 )[512]' in 'LPSTR' nicht möglich</p>
<p>wie gesagt , ich bin anfänger und vielleicht noch etwas schwer von begriff also habt nochsicht mit mir...</p>
<p>danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104421</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104421</guid><dc:creator><![CDATA[Rille]]></dc:creator><pubDate>Wed, 26 Jul 2006 09:53:33 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 10:01:01 GMT]]></title><description><![CDATA[<p>getwindowtext erwartet als zweiten parameter einen zeiger auf char array.<br />
[cpp]GetWindowText(hwndEdit2, **&amp;**buffer, sizeof(buffer));[/cpp]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104429</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104429</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Wed, 26 Jul 2006 10:01:01 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 10:15:35 GMT]]></title><description><![CDATA[<p>okay,</p>
<p>dass hab ich verstanden und hatte ich auch schon geändert, aber das ändert nix am Fehler.</p>
<p>Hier nochmal der gesamte Quellcode:</p>
<pre><code>#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

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

int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPrI, PSTR szCmdLine, int iCmdShow)
{
 char szName[] = &quot;Fensterklasse&quot;;
 HBRUSH MyBrush = CreateSolidBrush( RGB( 0, 150, 255 ) );
 WNDCLASS wc;

 wc.style         = CS_HREDRAW | CS_VREDRAW;
 wc.lpfnWndProc   = WndProc;
 wc.cbClsExtra    = 0;
 wc.cbWndExtra    = 0;
 wc.hInstance     = hI;
 wc.hIcon         = LoadIcon (NULL, IDI_WINLOGO);
 wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
 wc.hbrBackground = MyBrush;
 wc.lpszMenuName  = NULL;
 wc.lpszClassName = szName;

 RegisterClass (&amp;wc);

 HWND hwnd = CreateWindow (szName, &quot;Interaktives Fenster&quot;, WS_OVERLAPPEDWINDOW,
                            100, 100, 800,600, NULL, NULL, hI, NULL);
 ShowWindow   (hwnd, iCmdShow);
 UpdateWindow (hwnd);

//-----------------------------------------------------------------------------------

  MSG msg;

  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)
{
 HDC hdc;
 PAINTSTRUCT ps;
 static HWND hwndButton1, hwndEdit2;
 static char buffer[512] = {0};
 int iLength;

 switch (message)
 {

  case WM_CREATE :

      hwndButton1 = CreateWindow ( &quot;button&quot;, &quot;Knopf 1&quot;,
                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                   150, 20, 100, 40, hwnd, (HMENU)1,
                                   (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

   hwndEdit2   = 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,
                                   200, 200, 200, 200,
                                   hwnd,
                                   (HMENU)2,
                                   (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),
                                   NULL);     
  return 0;

  case WM_COMMAND:
      switch(LOWORD(wParam))
      {
		case 1:
			GetWindowText(hwndEdit2, &amp;buffer, sizeof(buffer)); //&lt;----immernoch hier der Fehler 
		    SetWindowText(hwndEdit2,&quot;&quot;);

			SendMessage(hwndEdit2, EM_SETREADONLY, TRUE, 0);
      break;
      case 2:
           SendMessage(hwndEdit2, EM_SETREADONLY, FALSE, 0);
      break;
      }
  return 0;

  case WM_PAINT:
      hdc = BeginPaint (hwnd, &amp;ps);
      SetTextColor(hdc, RGB(255,0,0) );
      SetBkColor(hdc, RGB(255,255,0) );
      TextOut (hdc, 20, 20, &quot;Ich bin ein Fenster.&quot;, 20);
	  TextOut (hdc, 100, 700, buffer, sizeof(buffer));
      EndPaint (hwnd, &amp;ps);
  return 0;
  case WM_DESTROY:
      PostQuitMessage (0);
  return 0;
 }
 free(buffer);
 return DefWindowProc (hwnd, message, wParam, lParam);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1104439</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104439</guid><dc:creator><![CDATA[Rille]]></dc:creator><pubDate>Wed, 26 Jul 2006 10:15:35 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 10:40:02 GMT]]></title><description><![CDATA[<p>sorry fehler von mir</p>
<pre><code class="language-cpp">GetWindowText(hEdit2, &amp;buffer[0], sizeof(buffer));
</code></pre>
<pre><code class="language-cpp">TextOut (hdc, 20, 40, buffer, strlen(buffer));
</code></pre>
<p>sollte die länge des strings angeben nicht die grösse</p>
<p>und das free(buffer); kannst du dir jetzt schenken</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104458</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104458</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Wed, 26 Jul 2006 10:40:02 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 11:25:42 GMT]]></title><description><![CDATA[<p>Hoi,</p>
<p>miller_m schrieb:</p>
<blockquote>
<p>sorry fehler von mir</p>
<pre><code class="language-cpp">GetWindowText(hEdit2, &amp;buffer[0], sizeof(buffer));
</code></pre>
</blockquote>
<p>lol, Warum nicht einfach:</p>
<pre><code class="language-cpp">GetWindowText(hEdit2, buffer, sizeof(buffer));
</code></pre>
<p>Denn: Da buffer ein statisches Array ist, impliziert 'buffer' ja ein Zeiger auf den ersten 'Platz' im Array.</p>
<p>Dann vllt noch dazu:</p>
<p>Rille schrieb:</p>
<blockquote>
<pre><code class="language-cpp">buffer = malloc(iLength);    // &lt;----------Fehler hier !
</code></pre>
<p>Compiler schrieb:</p>
<blockquote>
<p>d:\C-Programme\test\main.cpp(88) : error C2440: '=': 'void *' kann nicht in 'char *' konvertiert werden</p>
</blockquote>
</blockquote>
<p>Naja der Return Wert von malloc() ist void*, da du aber ein Char-Array reservierst, musst du den Rückgabewerte infach casten, also so:</p>
<pre><code class="language-cpp">buffer = (char*)malloc(iLength + 1);
</code></pre>
<p>Ich würde dir aber empfehlen es so zu machen:</p>
<pre><code class="language-cpp">buffer = new char[iLength + 1];
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/26a0.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--warning"
      title=":warning:"
      alt="⚠"
    /><br />
PS: Du musst iLength + 1 allokieren für die Null-Terminierung des C-Strings, die wird meines Wissen bei GetWindowTextLength nicht berücksichtigt.<br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/27a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--right_arrow"
      title=":arrow_right:"
      alt="➡"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /><br />
Du kannst das mit der dynamischen Speicherreservierung schon so machen, musst aber deinen Code n bissl umbauen:</p>
<pre><code class="language-cpp">LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 HDC hdc;
 PAINTSTRUCT ps;
 static HWND hwndButton1, hwndEdit2;
 char* buffer = NULL;
 int iLength;

 switch (message)
 {

  case WM_CREATE :

      hwndButton1 = CreateWindow ( &quot;button&quot;, &quot;Knopf 1&quot;,
                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                   150, 20, 100, 40, hwnd, (HMENU)1,
                                   (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

      hwndEdit2   = CreateWindowEx(WS_EX_CLIENTEDGE,
                                   &quot;edit&quot;,
                                   NULL,    // &lt;- das ist der Inhalt der Editfelds
                                   WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE |
                                              ES_AUTOVSCROLL,
                                   200, 200, 200, 200,
                                   hwnd,
                                   (HMENU)2,
                                   ((LPCREATESTRUCT) lParam) -&gt; hInstance,
                                   NULL);
  return 0;

  case WM_COMMAND:
      switch(LOWORD(wParam))
      {
          case 1:
             iLength = GetWindowTextLength(hwndEdit2);
             if(buffer != NULL)
             {
                free(buffer);
                buffer = NULL;
             }
             buffer = (char*)malloc(iLength + 1);
             GetWindowText(hwndEdit2, buffer, iLength + 1);
             SetWindowText(hwndEdit2, &quot;&quot;);
             SendMessage(hwndEdit2, EM_SETREADONLY, TRUE, 0);
             break;
          case 2:
             SendMessage(hwndEdit2, EM_SETREADONLY, FALSE, 0);
             break;
      }
      return 0;

  case WM_PAINT:
      hdc = BeginPaint (hwnd, &amp;ps);
      SetTextColor(hdc, RGB(255,0,0) );
      SetBkColor(hdc, RGB(255,255,0) );
      TextOut (hdc, 20, 20, &quot;Ich bin ein Fenster.&quot;, 20);
      TextOut (hdc, 100, 700, buffer, 20); /* wieso 20 ??? */
      EndPaint (hwnd, &amp;ps);
  return 0;
  case WM_DESTROY:
      PostQuitMessage (0);
  return 0;
 }
</code></pre>
<p>PS: Hoffe das war hilfreich <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/1104494</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104494</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Wed, 26 Jul 2006 11:25:42 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 16:27:49 GMT]]></title><description><![CDATA[<p>danke erstmal für eure hilfe,</p>
<p>Winapi is echt ne harte nuss <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> . Hab heut auch schon ein der Bücherei meines Vertrauens den Petzold bestellt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> .</p>
<p>eine sache gibts aber noch <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>der Quelltext funktioniert bei mir nicht:</p>
<pre><code>LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 HDC hdc;
 PAINTSTRUCT ps;
 static HWND hwndButton1, hwndEdit2;
 char* buffer = NULL;
 int iLength;

 switch (message)
 {

  case WM_CREATE :

      hwndButton1 = CreateWindow ( &quot;button&quot;, &quot;Knopf 1&quot;,
                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                   150, 20, 100, 40, hwnd, (HMENU)1,
                                   (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

      hwndEdit2   = CreateWindowEx(WS_EX_CLIENTEDGE,
                                   &quot;edit&quot;,
                                   NULL,    // &lt;- das ist der Inhalt der Editfelds
                                   WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE |
                                              ES_AUTOVSCROLL,
                                   200, 200, 200, 200,
                                   hwnd,
                                   (HMENU)2,
                                   ((LPCREATESTRUCT) lParam) -&gt; hInstance,
                                   NULL);
  return 0;

  case WM_COMMAND:
      switch(LOWORD(wParam))
      {
          case 1:
             iLength = GetWindowTextLength(hwndEdit2);
             if(buffer != NULL)
             {
                free(buffer);
                buffer = NULL;
             }
             buffer = (char*)malloc(iLength + 1);
             GetWindowText(hwndEdit2, buffer, iLength + 1);
             SetWindowText(hwndEdit2, &quot;&quot;);
             SendMessage(hwndEdit2, EM_SETREADONLY, TRUE, 0);
             break;
          case 2:
             SendMessage(hwndEdit2, EM_SETREADONLY, FALSE, 0);
             break;
      }
      return 0;

  case WM_PAINT:
      hdc = BeginPaint (hwnd, &amp;ps);
      SetTextColor(hdc, RGB(255,0,0) );
      SetBkColor(hdc, RGB(255,255,0) );
      TextOut (hdc, 20, 20, &quot;Ich bin ein Fenster.&quot;, 20);
      TextOut (hdc, 100, 100, buffer, sizeof(buffer)); 
      EndPaint (hwnd, &amp;ps);
  return 0;
  case WM_DESTROY:
      PostQuitMessage (0);
  return 0;
 }
 free(buffer);
 return DefWindowProc (hwnd, message, wParam, lParam);
}
</code></pre>
<p>Das Programm läuft schon und es gibt auch keine Fehlermeldung, aber er zeigt halt auch den Inhalt vom buffer an der stelle (100, 100) an.<br />
Bin ich einfach nur zu blöd? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Bestimmt wieder so ne kleinigkeit aber wäre toll wenn mir nochmal einer auf die sprünge helfen könnte :-).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104769</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104769</guid><dc:creator><![CDATA[Rille]]></dc:creator><pubDate>Wed, 26 Jul 2006 16:27:49 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 16:40:14 GMT]]></title><description><![CDATA[<blockquote>
<p>Das Programm <strong>läuft schon</strong> und es gibt auch <strong>keine Fehlermeldung</strong>, aber er <strong>zeigt</strong> halt auch <strong>den Inhalt vom buffer an der stelle (100, 100) an</strong>.</p>
</blockquote>
<p>Ahja <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> , wo ist dann dein Problem ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>TextOut (hdc, 100, 100, buffer, sizeof(buffer));</p>
<p>-&gt;&gt;</p>
<p>TextOut (hdc, 100, 100, buffer, strlen(buffer));</p>
<p>PS. Wenns auch nit geht mach einfach mal ne Testausgabe via MessageBox direkt nach dem Auslesen Editfeldes...ein genereller Tipp <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/1104780</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104780</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Wed, 26 Jul 2006 16:40:14 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 16:50:21 GMT]]></title><description><![CDATA[<p>ja cool mit der messagebox gehts <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<p>aber ich raff einfach nicht warum das mit TextOut nicht funktioniert. könntest du mir das erklären?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104788</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104788</guid><dc:creator><![CDATA[Rille]]></dc:creator><pubDate>Wed, 26 Jul 2006 16:50:21 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 16:59:25 GMT]]></title><description><![CDATA[<p>Du musst buffer als static deklarieren:</p>
<pre><code class="language-cpp">static char* buffer = NULL;
</code></pre>
<p>Damit der Wert erhalten bleibt, wenn deine WndProc verlassen wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104795</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104795</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Wed, 26 Jul 2006 16:59:25 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 17:17:30 GMT]]></title><description><![CDATA[<p>ich geb langsam auf,</p>
<p>Is mir auch langsam peinlich wie ich mich anstell.<br />
Danke für deine unglaubliche Geduld Codefinder. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>ich versuchs jetzt mal mit 2 Editboxen *lach*.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104799</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104799</guid><dc:creator><![CDATA[Rille]]></dc:creator><pubDate>Wed, 26 Jul 2006 17:17:30 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 17:24:16 GMT]]></title><description><![CDATA[<p>Hm ja, das ist kein Problem...hats denn jetzt funktioniert ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104802</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104802</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Wed, 26 Jul 2006 17:24:16 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 17:29:19 GMT]]></title><description><![CDATA[<p>ne hat es leider nicht,</p>
<p>es ist auch bestimmt nur ne kleinigkeit aber es klappt halt einfach nicht.</p>
<p>mit strlen(buffer) gehts auch nicht, da geht er gleich in debugger.</p>
<p>Das Programm startet ja aber er zeigt mir einfach die textout-zeile an.</p>
<p>dem pointer buffer hab ich zwar auch static spendiert aber es leider ohne erfolg...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104806</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104806</guid><dc:creator><![CDATA[Rille]]></dc:creator><pubDate>Wed, 26 Jul 2006 17:29:19 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 17:33:59 GMT]]></title><description><![CDATA[<p>Schick mal Code...: <a href="mailto:cpp-coding@arcor.de" rel="nofollow">cpp-coding@arcor.de</a></p>
<p>Das machts langsam interessant <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104811</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104811</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Wed, 26 Jul 2006 17:33:59 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 17:48:34 GMT]]></title><description><![CDATA[<p>hab dir den quellcode geschickt.</p>
<p>hab das ganze auch nochmal mit 2 Editboxen gemacht und es hat optimal geklappt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104824</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104824</guid><dc:creator><![CDATA[Rille]]></dc:creator><pubDate>Wed, 26 Jul 2006 17:48:34 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Wed, 26 Jul 2006 18:27:22 GMT]]></title><description><![CDATA[<p>lol, ok hab deine(n) Fehler:</p>
<p>1. wenn du vor dein MsgSwitch schreibst static char'* buffer = NULL; bringt das static auch nix...da es bei jedem eintreten der WndProc immer auf NULL gesetzt wird!...das macht man unter WM_CREATE.</p>
<p>2. wenn man auf den Button klickt musst du dein Fenster auch noch invalidieren mit:<br />
InvalidateRect(hwnd, NULL, FALSE); damit es nach der Neuinitialisierung des Textes auch geupdatet wird <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>
<p>Dann ist noch eine Überprüfung zwingend notwendig:</p>
<pre><code class="language-cpp">if(buffer)
   TextOut (hdc, 10, 10, buffer, strlen(buffer));
</code></pre>
<p>Damit wir strlen(...) nit außer Bahn werfen...:</p>
<p>Hier für alle nochmal der Code...:</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);

int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPrI, PSTR szCmdLine, int iCmdShow)
{
char szName[] = &quot;Fensterklasse&quot;;
HBRUSH MyBrush = CreateSolidBrush( RGB( 0, 150, 255 ) );
WNDCLASS wc;

wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hI;
wc.hIcon = LoadIcon (NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = MyBrush;
wc.lpszMenuName = NULL;
wc.lpszClassName = szName;

RegisterClass (&amp;wc);

HWND hwnd = CreateWindow (szName, &quot;Interaktives Fenster&quot;, WS_OVERLAPPEDWINDOW,
100, 100, 800,600, NULL, NULL, hI, NULL);
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);

//-----------------------------------------------------------------------------------

	MSG msg;

	while (GetMessage (&amp;msg, NULL, 0, 0))
	{
		TranslateMessage (&amp;msg);
		DispatchMessage (&amp;msg);
	}
	DeleteObject(MyBrush); // Objekt freigeben!!
	return msg.wParam;
}

//-----------------------------------------------------------------------------------

LRESULT CALLBACK WndProc (HWND hwnd, UINT uiMessage, WPARAM wParam, LPARAM lParam)
{
	static	HWND	hwndButton1,
					hwndEdit2;
	static	PTCHAR	pszBuffer; // TCHAR wg. UNICODE Kompatibilität

	switch(uiMessage)
	{
		case WM_CREATE :
			pszBuffer = NULL;
			hwndButton1 = CreateWindow ( &quot;button&quot;, &quot;Knopf 1&quot;,
							WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							150, 20, 100, 40, hwnd, (HMENU)1,
							(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

			hwndEdit2 = CreateWindowEx(WS_EX_CLIENTEDGE, &quot;edit&quot;, NULL,
							WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE |
							ES_AUTOVSCROLL,
							200, 200, 200, 200,
							hwnd,
							(HMENU)2,
							((LPCREATESTRUCT) lParam) -&gt; hInstance,
							NULL);
			return 0;

		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case 1:
					if(pszBuffer != NULL)
					{
						delete [] pszBuffer;
						pszBuffer = NULL;
					}
					int iLength;
					iLength = GetWindowTextLength(hwndEdit2);
					pszBuffer = new TCHAR[iLength + 1];
					GetWindowText(hwndEdit2, pszBuffer, iLength + 1);
					SetWindowText(hwndEdit2, NULL);
					SendMessage(hwndEdit2, EM_SETREADONLY, TRUE, 0);
					InvalidateRect(hwnd, NULL, FALSE); // Fenster updaten
					return 0;
				case 2:
					SendMessage(hwndEdit2, EM_SETREADONLY, FALSE, 0);
					return 0;
			}
			return 0;

		case WM_PAINT:
			PAINTSTRUCT ps;
			BeginPaint (hwnd, &amp;ps);

			SetTextColor(ps.hdc, RGB(255,0,0));
			SetBkColor(ps.hdc, RGB(255,255,0));

			TextOut (ps.hdc, 20, 20, &quot;Ich bin ein Fenster.&quot;, 20);

			SetTextColor(ps.hdc, RGB(255,0,0));
			SetBkColor(ps.hdc, RGB(255,255,0));

			if(pszBuffer != NULL)
				TextOut(ps.hdc, 20, 70, pszBuffer, lstrlen(pszBuffer)); // lstrlen wg. UNICODE Kompatibilität

			EndPaint(hwnd, &amp;ps);
			return 0;

		case WM_DESTROY:
			if(pszBuffer != NULL)
			{
				delete [] pszBuffer;
				pszBuffer = NULL;
			}
			PostQuitMessage (0);
			return 0;
	}

	return DefWindowProc (hwnd, uiMessage, wParam, lParam);
}
</code></pre>
<p>PS: Hab auch die (neue) Speicherreservierung aus C++ drin <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>EDIT: Mir ist gerade aufgefallen, dass du MyBrush erstellst aber nie löscht... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/26a0.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--warning"
      title=":warning:"
      alt="⚠"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1104836</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1104836</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Wed, 26 Jul 2006 18:27:22 GMT</pubDate></item><item><title><![CDATA[Reply to Editbox-Anfängerproblem on Thu, 27 Jul 2006 07:00:35 GMT]]></title><description><![CDATA[<p>cool danke jetzt klappts,</p>
<p>tut mir leid wenn ich so viele umstände bereitet hab.</p>
<p>schönen tag noch <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1105054</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1105054</guid><dc:creator><![CDATA[Rille]]></dc:creator><pubDate>Thu, 27 Jul 2006 07:00:35 GMT</pubDate></item></channel></rss>