<?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 Fenster, wenn Button gedrück wird]]></title><description><![CDATA[<p>Moin moin,</p>
<p>ich möchte, wenn man einen Button drückt, dass ein Text im Hauptfenster erscheint</p>
<pre><code class="language-cpp">case WM_COMMAND:
  switch(LOWORD(wParam))
  {
  case ID_START:
     hdc = BeginPaint (hwnd, &amp;ps);  // Text
     TextOut (hdc, 15, 10, &quot;Ich bin ein Text&quot; !!!&quot;, 35);
     EndPaint (hwnd, &amp;ps);
  break;
</code></pre>
<p>so dachte ich mir das zuerst, doch dann bekam ich den heißen tipp:</p>
<p>Das darf nicht im WM_COMMAND Handler stehen sondern nur im WM_PAINT Handler.</p>
<p>In WM_COMMAND setzt du nur eine Variable und rufst dann InvalidateRect auf.</p>
<pre><code class="language-cpp">case WM_COMMAND:
   ZeigeText = true;
   InvalidateRect(hWnd, NULL, TRUE);
</code></pre>
<p>daaurf hin machte ich folgendes:</p>
<pre><code class="language-cpp">switch(LOWORD(wParam))
{
   case ID_START: // Aktion bei Button &quot;Sart&quot;   
   start = true;
      InvalidateRect(hwnd, NULL, TRUE);          
}
</code></pre>
<p>und in WM_PAINT</p>
<pre><code class="language-cpp">if(start == true)
         TextOut (hdc, 20, 100, &quot;Hier konmmt die Zahl !!!&quot;, 24);
</code></pre>
<p>doch es funzt nicht, ich brauche eure hilfe, ich weiß nich mehr weiter...</p>
<p>Es kann gut sein, dass ich etwas grundlegendes nicht verstanden habe oder so, aba schickt mir doch bitte einen kompletten quelltext (nicht wie oben), damit ich das endlich verstehe <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>
]]></description><link>https://www.c-plusplus.net/forum/topic/113115/text-im-fenster-wenn-button-gedrück-wird</link><generator>RSS for Node</generator><lastBuildDate>Wed, 01 Jul 2026 19:44:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/113115.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 19 Jun 2005 18:42:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Text im Fenster, wenn Button gedrück wird on Sun, 19 Jun 2005 18:42:33 GMT]]></title><description><![CDATA[<p>Moin moin,</p>
<p>ich möchte, wenn man einen Button drückt, dass ein Text im Hauptfenster erscheint</p>
<pre><code class="language-cpp">case WM_COMMAND:
  switch(LOWORD(wParam))
  {
  case ID_START:
     hdc = BeginPaint (hwnd, &amp;ps);  // Text
     TextOut (hdc, 15, 10, &quot;Ich bin ein Text&quot; !!!&quot;, 35);
     EndPaint (hwnd, &amp;ps);
  break;
</code></pre>
<p>so dachte ich mir das zuerst, doch dann bekam ich den heißen tipp:</p>
<p>Das darf nicht im WM_COMMAND Handler stehen sondern nur im WM_PAINT Handler.</p>
<p>In WM_COMMAND setzt du nur eine Variable und rufst dann InvalidateRect auf.</p>
<pre><code class="language-cpp">case WM_COMMAND:
   ZeigeText = true;
   InvalidateRect(hWnd, NULL, TRUE);
</code></pre>
<p>daaurf hin machte ich folgendes:</p>
<pre><code class="language-cpp">switch(LOWORD(wParam))
{
   case ID_START: // Aktion bei Button &quot;Sart&quot;   
   start = true;
      InvalidateRect(hwnd, NULL, TRUE);          
}
</code></pre>
<p>und in WM_PAINT</p>
<pre><code class="language-cpp">if(start == true)
         TextOut (hdc, 20, 100, &quot;Hier konmmt die Zahl !!!&quot;, 24);
</code></pre>
<p>doch es funzt nicht, ich brauche eure hilfe, ich weiß nich mehr weiter...</p>
<p>Es kann gut sein, dass ich etwas grundlegendes nicht verstanden habe oder so, aba schickt mir doch bitte einen kompletten quelltext (nicht wie oben), damit ich das endlich verstehe <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>
]]></description><link>https://www.c-plusplus.net/forum/post/812760</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/812760</guid><dc:creator><![CDATA[Hobby Programmierer]]></dc:creator><pubDate>Sun, 19 Jun 2005 18:42:33 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Fenster, wenn Button gedrück wird on Sun, 19 Jun 2005 18:44:24 GMT]]></title><description><![CDATA[<p>ist start static oder global?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/812763</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/812763</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Sun, 19 Jun 2005 18:44:24 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Fenster, wenn Button gedrück wird on Sun, 19 Jun 2005 18:45:11 GMT]]></title><description><![CDATA[<p>zeig mal den ganzen quelltext damit ich das bei mir compilieren kann</p>
]]></description><link>https://www.c-plusplus.net/forum/post/812764</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/812764</guid><dc:creator><![CDATA[alles]]></dc:creator><pubDate>Sun, 19 Jun 2005 18:45:11 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Fenster, wenn Button gedrück wird on Sun, 19 Jun 2005 19:26:52 GMT]]></title><description><![CDATA[<p>hier is der gesamte code (start ist static)</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

#define ID_START   1
#define ID_ENDE    2

#define ID_RAHMEN  3
#define ID_LEVEL1  4
#define ID_LEVEL2  5
#define ID_LEVEL3  6
#define ID_RAHMEN2 7
#define ID_LISTE   8

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

void winButtons		  (HWND, HWND, HWND, HWND, LPARAM);
void winButtonsAktion (HWND, WPARAM, bool&amp;);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
   static TCHAR szAppName[] = TEXT (&quot;Klassenname&quot;);
   HWND         hwnd;
   MSG          msg;
   WNDCLASSEX   wndclassex = {0};

   wndclassex.cbSize        = sizeof(WNDCLASSEX);
   wndclassex.style         = CS_HREDRAW | CS_VREDRAW;
   wndclassex.lpfnWndProc   = WndProc;
   wndclassex.cbClsExtra    = 0;
   wndclassex.cbWndExtra    = 0;
   wndclassex.hInstance     = hInstance;
   wndclassex.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
   wndclassex.hCursor       = LoadCursor (NULL, IDC_ARROW);
   wndclassex.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
   wndclassex.lpszMenuName  = NULL;
   wndclassex.lpszClassName = szAppName;
   wndclassex.hIconSm       = wndclassex.hIcon;

   if (!RegisterClassEx (&amp;wndclassex))
   {
      MessageBox (NULL, TEXT (&quot;RegisterClassEx fehlgeschlagen!&quot;),
                  szAppName, MB_ICONERROR);
      return 0;
   }

   hwnd = CreateWindowEx (WS_EX_OVERLAPPEDWINDOW, // erweiterter Fensterstil
                  szAppName, // Name der Fensterklasse
                  TEXT (&quot;Schnelle Zahlen&quot;), // Fenstertitel
                  WS_OVERLAPPEDWINDOW, // Fensterstil
                  CW_USEDEFAULT, // X-Position des Fensters                      
                  CW_USEDEFAULT, // Y-Position des Fensters       
                  500, // Fensterbreite                 
                  500, // Fensterhöhe                
                  NULL, // übergeordnetes Fenster
                  NULL, // Menü           
                  hInstance, // Programm-Kopiezähler (Programm-ID)            
                  NULL); // zusätzliche Parameter

   ShowWindow (hwnd, iCmdShow);
   UpdateWindow (hwnd);

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

// Die Hauptnachrichtenschleife
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   HDC hdc, hdcMem;
   static HBITMAP hBitMap;
   static BITMAP bitmap ;
   PAINTSTRUCT ps;
   static HWND ButtonHandle, ListHandle, EingHandle;
   int nModePrev;
   static bool start = false;

   switch (message)
   {
   case WM_CREATE:
	  // bild
	  hBitMap = (HBITMAP)LoadImage(0,&quot;zahlen.bmp&quot;,IMAGE_BITMAP, 0, 0,
                 LR_DEFAULTSIZE|LR_LOADFROMFILE|LR_CREATEDIBSECTION);

      if(hBitMap==NULL)
      {
          MessageBox(hwnd,&quot;Bild konnte nicht geladen werden&quot;,&quot;Error&quot;,0);
          return -1;
      }  
      GetObject (hBitMap, sizeof (BITMAP), &amp;bitmap);  

	  winButtons (hwnd, ButtonHandle, ListHandle, EingHandle, lParam);	// Buttons		
      break;

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

      hdcMem = CreateCompatibleDC (hdc);
      SelectObject (hdcMem, hBitMap);
      StretchBlt (hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, 
		       	  hdcMem, 0, 0, 500, 500, SRCCOPY);

      DeleteDC (hdcMem); 		 

      nModePrev = SetBkMode(hdc, TRANSPARENT);
      TextOut (hdc, 15, 10, &quot;Willkommen zu \&quot;Schnelle Zahlen\&quot; !!!&quot;, 35);
      TextOut (hdc, 320, 283, &quot;Ihre Eingabe...&quot;,15);

      if(start == true)
         TextOut (hdc, 180, 100, &quot;Hier konmmt die Zahl !!!&quot;, 24);

      EndPaint (hwnd, &amp;ps);
      break;

   case WM_COMMAND:   	  
	  winButtonsAktion (hwnd, wParam, start);
	  break;

   case WM_DESTROY:
      PostQuitMessage (0);
      break;
   }

   return DefWindowProc (hwnd, message, wParam, lParam);
}

void winButtons (HWND hwnd, HWND ButtonHandle, HWND ListHandle, HWND EingHandle, LPARAM lParam)
{
   // ------------ Start / Ende ----------------
   ButtonHandle = CreateWindow(&quot;BUTTON&quot;, &quot;Start&quot;, WS_CHILD |    // Mein Button
	  						   WS_VISIBLE | BS_PUSHBUTTON | BS_CENTER, 
							   15, 50, 100, 100, hwnd, (HMENU) ID_START, // &lt;-- Kennziffer
							   GetModuleHandle(NULL), NULL);	   
   ButtonHandle = CreateWindow(&quot;BUTTON&quot;, &quot;Ende&quot;, WS_CHILD |    // Mein Button 
	  						   WS_VISIBLE | BS_PUSHBUTTON | BS_CENTER, 
							   15, 350, 100, 100, hwnd, (HMENU) ID_ENDE,  // &lt;-- Kennziffer 
							   GetModuleHandle(NULL), NULL);
   // ------------ Start / Ende ----------------

   // ------------ Levelauswahl ----------------
   ButtonHandle = CreateWindow(&quot;BUTTON&quot;, &quot;Level&quot;, WS_CHILD |    // Rahmen
	  						   WS_VISIBLE | BS_GROUPBOX | BS_CENTER, 
							   15, 200, 100, 100, hwnd, (HMENU) ID_RAHMEN,
							   GetModuleHandle(NULL), NULL);
   ButtonHandle = CreateWindow(&quot;BUTTON&quot;, &quot;Leicht&quot;, WS_CHILD |    // Auswahlmöglichkeit 1
	  						   WS_VISIBLE | BS_AUTORADIOBUTTON | BS_CENTER, 
							   30, 230, 70, 20, hwnd, (HMENU) ID_LEVEL1,
							   GetModuleHandle(NULL), NULL);							   	
   ButtonHandle = CreateWindow(&quot;BUTTON&quot;, &quot;Mittel&quot;, WS_CHILD |    // Auswahlmöglichkeit 2
	  						   WS_VISIBLE | BS_AUTORADIOBUTTON | BS_CENTER, 
							   30, 250, 70, 20, hwnd, (HMENU) ID_LEVEL2,
							   GetModuleHandle(NULL), NULL);
   ButtonHandle = CreateWindow(&quot;BUTTON&quot;, &quot;Schwer&quot;, WS_CHILD |    // Auswahlmöglichkeit 3
	  						   WS_VISIBLE | BS_AUTORADIOBUTTON | BS_CENTER, 
							   30, 270, 70, 20, hwnd, (HMENU) ID_LEVEL3,
							   GetModuleHandle(NULL), NULL);
   // ------------ Levelauswahl ----------------

   // ------------ Eingabe ----------------   
   EingHandle =  CreateWindowEx(WS_EX_LEFT, &quot;edit&quot;, &quot;&quot;, WS_CHILD | WS_VISIBLE,
   			  	 				420, 280, 50, 20, hwnd, NULL,
								((LPCREATESTRUCT) lParam) -&gt; hInstance, NULL);
   // ------------ Eingabe ----------------

   // ------------ Highscore ----------------
   ButtonHandle = CreateWindow(&quot;BUTTON&quot;, &quot;Highscore&quot;, WS_CHILD |    // Rahmen
	  						   WS_VISIBLE | BS_GROUPBOX | BS_CENTER, 
							   200, 320, 215, 130, hwnd, (HMENU) ID_RAHMEN2,
							   GetModuleHandle(NULL), NULL);
   ListHandle = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT(&quot;LISTBOX&quot;), NULL,
   			  				   WS_CHILD | WS_VISIBLE , 213 , 343 ,190 ,100 ,
							   hwnd , (HMENU) ID_LISTE , ((LPCREATESTRUCT)lParam)-&gt;hInstance,NULL);
   // ------------ Highscore ----------------
}

void winButtonsAktion (HWND hwnd, WPARAM wParam, bool &amp;start)
{	
   switch(LOWORD(wParam))
   {
   case ID_START: // Aktion bei Button &quot;Sart&quot;
      HWND hButton;

   	  hButton = GetDlgItem(hwnd, ID_LEVEL1);
   	  if (SendMessage(hButton , BM_GETCHECK, 0, 0)==BST_CHECKED)
	  {
	     MessageBox(NULL, &quot;Spiel wird mit leichter Schwierigkeitsstufe gestartet...&quot;,
		 		    &quot;Aktion...&quot;, MB_OK | MB_SETFOREGROUND);
		 start = true;		    
	  }
	  hButton = GetDlgItem(hwnd, ID_LEVEL2);
   	  if (SendMessage(hButton , BM_GETCHECK, 0, 0)==BST_CHECKED)
	  {
	     MessageBox(NULL, &quot;Spiel wird mit mittlerer Schwierigkeitsstufe gestartet...&quot;,
		 		    &quot;Aktion...&quot;, MB_OK | MB_SETFOREGROUND);
		 start = true;
	  }
	  hButton = GetDlgItem(hwnd, ID_LEVEL3);
   	  if (SendMessage(hButton , BM_GETCHECK, 0, 0)==BST_CHECKED)
	  {
	     MessageBox(NULL, &quot;Spiel wird mit leichter Schwirigkeitsstufe gestartet...&quot;,
		 		    &quot;Aktion...&quot;, MB_OK | MB_SETFOREGROUND);
		 start = true;
	  }

	  if(start == false)
	  { 
	  	 MessageBox(NULL, &quot;Bitte Schwierigkeitsstufe auswählen!!!&quot;,
		 		 	&quot;Aktion...&quot;, MB_OK | MB_SETFOREGROUND);
	  }
      break;

   case ID_ENDE: // Aktion bei Button &quot;Ende&quot;
	  MessageBox(NULL, &quot;Programm wird beendet&quot;,
		 		 &quot;Aktion...&quot;, MB_OK | MB_SETFOREGROUND);
	  PostQuitMessage (0);			
      break;	
   } 
}
</code></pre>
<p>Ich hab versucht, ein paar aufgaben in funktionen zu packen (programmier eigendlich nur c++). Ich bitte euch mich nicht mit verbesserungsvorschlägen zuzuschmeißen, sondern nur dieses eine problem zu beschprechen (sonst blick ich garnich mehr durch^^)</p>
<p>das programm ist noch lange noch nicht fertig (ich muss noch rauskriegen, wie man variabeln in das &quot;TextOut&quot; reinbekommt usw., aber die grundzuüge sind schon fertig^^</p>
<p>um das zu compilieren brauch man die datei &quot;logo.bmp&quot; um exe-ordner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/812809</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/812809</guid><dc:creator><![CDATA[hobby programmierer]]></dc:creator><pubDate>Sun, 19 Jun 2005 19:26:52 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Fenster, wenn Button gedrück wird on Sun, 19 Jun 2005 20:41:56 GMT]]></title><description><![CDATA[<p>ahh, &quot;zahlen.bmp&quot; ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/812869</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/812869</guid><dc:creator><![CDATA[nachtrag]]></dc:creator><pubDate>Sun, 19 Jun 2005 20:41:56 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Fenster, wenn Button gedrück wird on Mon, 20 Jun 2005 08:34:56 GMT]]></title><description><![CDATA[<p>Bitte kürze deinen Code auf das Entscheidene!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/813005</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/813005</guid><dc:creator><![CDATA[zahlen.bmp]]></dc:creator><pubDate>Mon, 20 Jun 2005 08:34:56 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Fenster, wenn Button gedrück wird on Mon, 20 Jun 2005 13:23:35 GMT]]></title><description><![CDATA[<p>hat sich erledigt, es klappt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/813244</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/813244</guid><dc:creator><![CDATA[es funzt]]></dc:creator><pubDate>Mon, 20 Jun 2005 13:23:35 GMT</pubDate></item><item><title><![CDATA[Reply to Text im Fenster, wenn Button gedrück wird on Mon, 20 Jun 2005 13:24:13 GMT]]></title><description><![CDATA[<p>woran lag es?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/813246</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/813246</guid><dc:creator><![CDATA[zahlen.bmp]]></dc:creator><pubDate>Mon, 20 Jun 2005 13:24:13 GMT</pubDate></item></channel></rss>