<?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[Einfaches Programm zum Fenstererstellen mit Buttons]]></title><description><![CDATA[<p>Hallo, haben in der FH jetzt grad das Thema &quot;Gui mit c&quot;</p>
<p>hab hier ein Beispielprogramm mit Visual Studio 2005 erstellt.</p>
<pre><code class="language-cpp">/*-----------------------------------------------------------------------
   HELLOWIN.C  Zeigt &quot;Hello, World!&quot; in einem Dialogfenster an
   vgl. Petzold Kap. 3
  -----------------------------------------------------------------------*/

#include &lt;windows.h&gt;

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
//Deklaration der Windows-Nachrichten-Prozedur

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static TCHAR szAppName[] = TEXT (&quot;HelloWin&quot;) ;
     HWND         hwnd ;										// Window handle
     MSG          msg ;											// MSG Nachrichten Struktur
     WNDCLASS     wndclass ;									// WNDCLASS Struktur

	 //Anwendungsbereich (client area)
     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;			// Neuzeichnen des Fensters
     wndclass.lpfnWndProc   = WndProc ;							// Nachrichtenverarbeitung CALLBACK WndProc
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;	// Cursor
     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;   // Hintergrund
     wndclass.lpszMenuName  = NULL ;	// Zeiger auf null-term. char string, der Ressourcen-Namen des Menüs festlegt
     wndclass.lpszClassName = szAppName ;

     if (!RegisterClass (&amp;wndclass))
     {    // UNICODE-Compilierung ist die einzige realistische Fehlermöglichkeit 
          MessageBox (NULL, TEXT (&quot;Programm arbeitet mit Unicode und setzt Windows NT voraus!&quot;), 
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     }

      hwnd = CreateWindow (szAppName,                 // Name der Fensterklasse
                  TEXT (&quot;Das erste echte Programm&quot;),  // Fenstertitel
                  WS_OVERLAPPEDWINDOW,                // Fensterstil - Art des Fensters
                  CW_USEDEFAULT,                      // X-Position des Fensters
                  CW_USEDEFAULT,                      // Y-Position des Fensters
                  CW_USEDEFAULT,                      // Fensterbreite
                  CW_USEDEFAULT,                      // 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))			// Nachrichten-Schleife  
     {
          TranslateMessage (&amp;msg) ;
          DispatchMessage (&amp;msg) ;
     }
     return msg.wParam ;
}

// Windows-Nachrichten-Prozedur  
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     HDC         hdc ;
     PAINTSTRUCT ps ;
     RECT        rect ;
	 HWND hwndButton1 ;
	 HWND hwndButton2 ;

     switch (message)
     {
	 /*case WM_CREATE:
          PlaySound (TEXT (&quot;yippee.wav&quot;), NULL, SND_FILENAME | SND_ASYNC) ; // WinMM.lib einbinden
          return 0 ;														// ...nicht vergessen*/
	  case WM_CREATE:
			hwndButton1 = CreateWindow ( &quot;button&quot;, &quot;OK&quot;, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 490, 400, 100, 40, hwnd, (HMENU)1,((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
			hwndButton2 = CreateWindow ( &quot;button&quot;, &quot;Cancel&quot;, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 600, 400, 100, 40, hwnd, (HMENU)2,((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
			return 0 ;
	  case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case 1:
					MessageBox(hwnd,&quot;Der Button OK wurde gedrückt&quot;, &quot;Message&quot;, MB_OK);
				break;
				case 2:
					MessageBox(hwnd,&quot;Der Button Cancel wurde gedrückt&quot;, &quot;Message&quot;, MB_OK);
				break;
			}
			return 0;
     case WM_PAINT:
          hdc = BeginPaint (hwnd, &amp;ps) ;

          GetClientRect (hwnd, &amp;rect) ;

          DrawText (hdc, TEXT (&quot;Hello, World!&quot;), -1, &amp;rect,
                    DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;

		  TextOut (hdc, 20, 20, &quot;Ich bin ein Fenster.&quot;, 20); // device context, x, y, string, string-Länge 

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

     case WM_DESTROY:
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}
</code></pre>
<p>Eigentlich sollte es ja 2 Buttons erstellen, aber anstelle bekomme ich nur ein Fenster mit Chinesischen Zeichen.</p>
<p><a href="http://img241.imageshack.us/my.php?image=templa5.jpg" rel="nofollow"></a><a href="http://img241.imageshack.us/img241/2272/templa5.th.jpg" rel="nofollow">http://img241.imageshack.us/img241/2272/templa5.th.jpg</a></p>
<p>Bin mit dem WinAPI aber auch noch recht unerfahren, aber das versteh ich jetzt wirklich net <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: der selbe Code scheint bei Visual Studio 2003 zu funktionieren, versteh das jetzt gar nicht mehr</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/167284/einfaches-programm-zum-fenstererstellen-mit-buttons</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 15:43:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/167284.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 09 Dec 2006 10:21:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Einfaches Programm zum Fenstererstellen mit Buttons on Sat, 09 Dec 2006 10:46:46 GMT]]></title><description><![CDATA[<p>Hallo, haben in der FH jetzt grad das Thema &quot;Gui mit c&quot;</p>
<p>hab hier ein Beispielprogramm mit Visual Studio 2005 erstellt.</p>
<pre><code class="language-cpp">/*-----------------------------------------------------------------------
   HELLOWIN.C  Zeigt &quot;Hello, World!&quot; in einem Dialogfenster an
   vgl. Petzold Kap. 3
  -----------------------------------------------------------------------*/

#include &lt;windows.h&gt;

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
//Deklaration der Windows-Nachrichten-Prozedur

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static TCHAR szAppName[] = TEXT (&quot;HelloWin&quot;) ;
     HWND         hwnd ;										// Window handle
     MSG          msg ;											// MSG Nachrichten Struktur
     WNDCLASS     wndclass ;									// WNDCLASS Struktur

	 //Anwendungsbereich (client area)
     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;			// Neuzeichnen des Fensters
     wndclass.lpfnWndProc   = WndProc ;							// Nachrichtenverarbeitung CALLBACK WndProc
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;	// Cursor
     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;   // Hintergrund
     wndclass.lpszMenuName  = NULL ;	// Zeiger auf null-term. char string, der Ressourcen-Namen des Menüs festlegt
     wndclass.lpszClassName = szAppName ;

     if (!RegisterClass (&amp;wndclass))
     {    // UNICODE-Compilierung ist die einzige realistische Fehlermöglichkeit 
          MessageBox (NULL, TEXT (&quot;Programm arbeitet mit Unicode und setzt Windows NT voraus!&quot;), 
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     }

      hwnd = CreateWindow (szAppName,                 // Name der Fensterklasse
                  TEXT (&quot;Das erste echte Programm&quot;),  // Fenstertitel
                  WS_OVERLAPPEDWINDOW,                // Fensterstil - Art des Fensters
                  CW_USEDEFAULT,                      // X-Position des Fensters
                  CW_USEDEFAULT,                      // Y-Position des Fensters
                  CW_USEDEFAULT,                      // Fensterbreite
                  CW_USEDEFAULT,                      // 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))			// Nachrichten-Schleife  
     {
          TranslateMessage (&amp;msg) ;
          DispatchMessage (&amp;msg) ;
     }
     return msg.wParam ;
}

// Windows-Nachrichten-Prozedur  
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     HDC         hdc ;
     PAINTSTRUCT ps ;
     RECT        rect ;
	 HWND hwndButton1 ;
	 HWND hwndButton2 ;

     switch (message)
     {
	 /*case WM_CREATE:
          PlaySound (TEXT (&quot;yippee.wav&quot;), NULL, SND_FILENAME | SND_ASYNC) ; // WinMM.lib einbinden
          return 0 ;														// ...nicht vergessen*/
	  case WM_CREATE:
			hwndButton1 = CreateWindow ( &quot;button&quot;, &quot;OK&quot;, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 490, 400, 100, 40, hwnd, (HMENU)1,((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
			hwndButton2 = CreateWindow ( &quot;button&quot;, &quot;Cancel&quot;, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 600, 400, 100, 40, hwnd, (HMENU)2,((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
			return 0 ;
	  case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case 1:
					MessageBox(hwnd,&quot;Der Button OK wurde gedrückt&quot;, &quot;Message&quot;, MB_OK);
				break;
				case 2:
					MessageBox(hwnd,&quot;Der Button Cancel wurde gedrückt&quot;, &quot;Message&quot;, MB_OK);
				break;
			}
			return 0;
     case WM_PAINT:
          hdc = BeginPaint (hwnd, &amp;ps) ;

          GetClientRect (hwnd, &amp;rect) ;

          DrawText (hdc, TEXT (&quot;Hello, World!&quot;), -1, &amp;rect,
                    DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;

		  TextOut (hdc, 20, 20, &quot;Ich bin ein Fenster.&quot;, 20); // device context, x, y, string, string-Länge 

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

     case WM_DESTROY:
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}
</code></pre>
<p>Eigentlich sollte es ja 2 Buttons erstellen, aber anstelle bekomme ich nur ein Fenster mit Chinesischen Zeichen.</p>
<p><a href="http://img241.imageshack.us/my.php?image=templa5.jpg" rel="nofollow"></a><a href="http://img241.imageshack.us/img241/2272/templa5.th.jpg" rel="nofollow">http://img241.imageshack.us/img241/2272/templa5.th.jpg</a></p>
<p>Bin mit dem WinAPI aber auch noch recht unerfahren, aber das versteh ich jetzt wirklich net <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: der selbe Code scheint bei Visual Studio 2003 zu funktionieren, versteh das jetzt gar nicht mehr</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1189000</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1189000</guid><dc:creator><![CDATA[mazeli]]></dc:creator><pubDate>Sat, 09 Dec 2006 10:46:46 GMT</pubDate></item><item><title><![CDATA[Reply to Einfaches Programm zum Fenstererstellen mit Buttons on Sat, 09 Dec 2006 13:41:38 GMT]]></title><description><![CDATA[<p>In VC2005 ist das Default UNICODE!!!!<br />
Also bitte *ALLE* String mit dem TEXT oder _T Macro umgeben!!!</p>
<pre><code class="language-cpp">hwndButton1 = CreateWindow ( TEXT(&quot;button&quot;), TEXT(&quot;OK&quot;), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 490, 400, 100, 40, hwnd, (HMENU)1,((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
hwndButton2 = CreateWindow ( TEXT(&quot;button&quot;), TEXT(&quot;Cancel&quot;), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 600, 400, 100, 40, hwnd, (HMENU)2,((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1189115</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1189115</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Sat, 09 Dec 2006 13:41:38 GMT</pubDate></item></channel></rss>