<?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[PlaySound - Frage]]></title><description><![CDATA[<p>Hi,</p>
<p>hab grad ein bisschen mit PlaySound rumgespielt weils bei mir nicht gleich klappen wollte. Ich muss dazu sagen dass ich noch nicht so fit bin in C++.<br />
Jetzt hab ich eine kleine Frage, aber vorher erstmal ein Stück Quelltext:</p>
<pre><code class="language-cpp">#define STRICT

#include &lt;windows.h&gt;
#include &lt;mmsystem.h&gt;

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

const char szAppName[] = &quot;Testfenster&quot;;

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

	wc.style		= CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc	= WndProc;

	wc.cbClsExtra    =  0;
	wc.cbWndExtra    =  0;

	wc.hInstance     =  hInstance;
	wc.hCursor       =  LoadCursor(NULL,IDC_ARROW);
	wc.hIcon         =  LoadIcon(NULL,IDI_APPLICATION);
	wc.hbrBackground =  (HBRUSH)GetStockObject(WHITE_BRUSH);

	wc.lpszClassName =  szAppName;
    wc.lpszMenuName  =  NULL;

	RegisterClass(&amp;wc);

	hWnd = CreateWindow(szAppName,
                       &quot;Testfenster&quot;,
                       WS_OVERLAPPEDWINDOW,
                       CW_USEDEFAULT,          /* X-Position auf dem Monitor */
                       CW_USEDEFAULT,          /* Y-Position auf dem Monitor */
                       500,          /* Fensterbreite              */
                       500,          /* Fensterhoehe               */
                       NULL,
                       NULL,
                       hInstance,
                       NULL);
	PlaySound(&quot;lol.wav&quot;, NULL, SND_FILENAME | SND_ASYNC);
	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_DESTROY:
      {
         PostQuitMessage(0);
         return 0;
      }
   }
	  return DefWindowProc(hWnd, message, wParam, lParam);
}
</code></pre>
<p>So klappt das mit PlaySound.<br />
Aber wenn ich es an einer anderen Stelle einbaue klappt es auf einmal nicht mehr:</p>
<pre><code class="language-cpp">#define STRICT

#include &lt;windows.h&gt;
#include &lt;mmsystem.h&gt;

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

const char szAppName[] = &quot;Testfenster&quot;;

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

	wc.style		= CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc	= WndProc;

	wc.cbClsExtra    =  0;
	wc.cbWndExtra    =  0;

	wc.hInstance     =  hInstance;
	wc.hCursor       =  LoadCursor(NULL,IDC_ARROW);
	wc.hIcon         =  LoadIcon(NULL,IDI_APPLICATION);
	wc.hbrBackground =  (HBRUSH)GetStockObject(WHITE_BRUSH);

	wc.lpszClassName =  szAppName;
    wc.lpszMenuName  =  NULL;

	RegisterClass(&amp;wc);

	hWnd = CreateWindow(szAppName,
                       &quot;Testfenster&quot;,
                       WS_OVERLAPPEDWINDOW,
                       CW_USEDEFAULT,          /* X-Position auf dem Monitor */
                       CW_USEDEFAULT,          /* Y-Position auf dem Monitor */
                       500,          /* Fensterbreite              */
                       500,          /* Fensterhoehe               */
                       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;

   PlaySound(&quot;lol.wav&quot;, NULL, SND_FILENAME | SND_ASYNC);

}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	 switch (message)
   {
		 case WM_DESTROY:
      {
         PostQuitMessage(0);
         return 0;
      }
   }
	  return DefWindowProc(hWnd, message, wParam, lParam);
}
</code></pre>
<p>Warum ist das so?</p>
<p>Danke schonmal,</p>
<p>Patrick <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/topic/185892/playsound-frage</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Jul 2026 11:01:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/185892.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 02 Jul 2007 14:46:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to PlaySound - Frage on Mon, 02 Jul 2007 14:46:39 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>hab grad ein bisschen mit PlaySound rumgespielt weils bei mir nicht gleich klappen wollte. Ich muss dazu sagen dass ich noch nicht so fit bin in C++.<br />
Jetzt hab ich eine kleine Frage, aber vorher erstmal ein Stück Quelltext:</p>
<pre><code class="language-cpp">#define STRICT

#include &lt;windows.h&gt;
#include &lt;mmsystem.h&gt;

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

const char szAppName[] = &quot;Testfenster&quot;;

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

	wc.style		= CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc	= WndProc;

	wc.cbClsExtra    =  0;
	wc.cbWndExtra    =  0;

	wc.hInstance     =  hInstance;
	wc.hCursor       =  LoadCursor(NULL,IDC_ARROW);
	wc.hIcon         =  LoadIcon(NULL,IDI_APPLICATION);
	wc.hbrBackground =  (HBRUSH)GetStockObject(WHITE_BRUSH);

	wc.lpszClassName =  szAppName;
    wc.lpszMenuName  =  NULL;

	RegisterClass(&amp;wc);

	hWnd = CreateWindow(szAppName,
                       &quot;Testfenster&quot;,
                       WS_OVERLAPPEDWINDOW,
                       CW_USEDEFAULT,          /* X-Position auf dem Monitor */
                       CW_USEDEFAULT,          /* Y-Position auf dem Monitor */
                       500,          /* Fensterbreite              */
                       500,          /* Fensterhoehe               */
                       NULL,
                       NULL,
                       hInstance,
                       NULL);
	PlaySound(&quot;lol.wav&quot;, NULL, SND_FILENAME | SND_ASYNC);
	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_DESTROY:
      {
         PostQuitMessage(0);
         return 0;
      }
   }
	  return DefWindowProc(hWnd, message, wParam, lParam);
}
</code></pre>
<p>So klappt das mit PlaySound.<br />
Aber wenn ich es an einer anderen Stelle einbaue klappt es auf einmal nicht mehr:</p>
<pre><code class="language-cpp">#define STRICT

#include &lt;windows.h&gt;
#include &lt;mmsystem.h&gt;

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

const char szAppName[] = &quot;Testfenster&quot;;

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

	wc.style		= CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc	= WndProc;

	wc.cbClsExtra    =  0;
	wc.cbWndExtra    =  0;

	wc.hInstance     =  hInstance;
	wc.hCursor       =  LoadCursor(NULL,IDC_ARROW);
	wc.hIcon         =  LoadIcon(NULL,IDI_APPLICATION);
	wc.hbrBackground =  (HBRUSH)GetStockObject(WHITE_BRUSH);

	wc.lpszClassName =  szAppName;
    wc.lpszMenuName  =  NULL;

	RegisterClass(&amp;wc);

	hWnd = CreateWindow(szAppName,
                       &quot;Testfenster&quot;,
                       WS_OVERLAPPEDWINDOW,
                       CW_USEDEFAULT,          /* X-Position auf dem Monitor */
                       CW_USEDEFAULT,          /* Y-Position auf dem Monitor */
                       500,          /* Fensterbreite              */
                       500,          /* Fensterhoehe               */
                       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;

   PlaySound(&quot;lol.wav&quot;, NULL, SND_FILENAME | SND_ASYNC);

}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	 switch (message)
   {
		 case WM_DESTROY:
      {
         PostQuitMessage(0);
         return 0;
      }
   }
	  return DefWindowProc(hWnd, message, wParam, lParam);
}
</code></pre>
<p>Warum ist das so?</p>
<p>Danke schonmal,</p>
<p>Patrick <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/1316938</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1316938</guid><dc:creator><![CDATA[PatrickB]]></dc:creator><pubDate>Mon, 02 Jul 2007 14:46:39 GMT</pubDate></item><item><title><![CDATA[Reply to PlaySound - Frage on Mon, 02 Jul 2007 14:52:20 GMT]]></title><description><![CDATA[<p>Die Funktion PlaySound im zweiten Dings wird nie abgespielt, weil sie hinter dem &quot;return&quot; steht. Der Computer führt den Code halt bis zum &quot;return&quot; aus und springt dann dahin zurück, von wo aus die Funktion aufgerufen wurde.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1316945</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1316945</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Mon, 02 Jul 2007 14:52:20 GMT</pubDate></item><item><title><![CDATA[Reply to PlaySound - Frage on Mon, 02 Jul 2007 15:04:39 GMT]]></title><description><![CDATA[<p>Achso, stimmt ja.</p>
<p>Aber wenn ich es nach der while-Schleife einfüge funktioniert es auch nicht.<br />
Also so:</p>
<pre><code class="language-cpp">while (GetMessage(&amp;msg, NULL, 0, 0))
    {
        TranslateMessage(&amp;msg);
      DispatchMessage(&amp;msg);
    }
    PlaySound(&quot;lol.wav&quot;, NULL, SND_FILENAME | SND_ASYNC);
    return msg.wParam;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1316961</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1316961</guid><dc:creator><![CDATA[PatrickB]]></dc:creator><pubDate>Mon, 02 Jul 2007 15:04:39 GMT</pubDate></item><item><title><![CDATA[Reply to PlaySound - Frage on Mon, 02 Jul 2007 16:07:18 GMT]]></title><description><![CDATA[<p>Direkt nach PlaySound() ist dein Programm auch beendet. Vermutlich wird PlaySound() da abgebrochen. Nimm da mal das SND_ASYNC raus <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=";D"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1317001</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317001</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Mon, 02 Jul 2007 16:07:18 GMT</pubDate></item><item><title><![CDATA[Reply to PlaySound - Frage on Mon, 02 Jul 2007 17:53:14 GMT]]></title><description><![CDATA[<p>Wenn ich das rausnehme spinnt das Programm ein bisschen. Ich kann nämlich nicht sofort wieder das Programm über das x rechts oben schliessen. Wenn ich da drauf klicke kommt die Fehlermeldung von Windows zum sofort beenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1317065</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317065</guid><dc:creator><![CDATA[PatrickB]]></dc:creator><pubDate>Mon, 02 Jul 2007 17:53:14 GMT</pubDate></item><item><title><![CDATA[Reply to PlaySound - Frage on Mon, 02 Jul 2007 18:37:20 GMT]]></title><description><![CDATA[<p>Kein Wunder, dein Programm kann dann auch keine Messages mehr bearbeiten bis PlaySound() fertig ist. Eben deswegen gibt es ja SND_ASYNC...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1317100</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317100</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Mon, 02 Jul 2007 18:37:20 GMT</pubDate></item><item><title><![CDATA[Reply to PlaySound - Frage on Mon, 02 Jul 2007 19:29:14 GMT]]></title><description><![CDATA[<p>sag mal was versuchst du denn? Wieso spielst du den Sound nach deiner Message Schleife ab? Willst du den Sound beim Beenden des Programms abspielen? Dann reagiere auf die WM_CLOSE oder WM_DESTROY Nachricht.</p>
<p>schirrmie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1317131</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317131</guid><dc:creator><![CDATA[schirrmie]]></dc:creator><pubDate>Mon, 02 Jul 2007 19:29:14 GMT</pubDate></item></channel></rss>