<?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[GetOpenFileName() Problem]]></title><description><![CDATA[<p>Hallo,<br />
Wenn das im Falschen forum gelandet sein sollte dann sry^^</p>
<p>Also folgenes ich beschäftige mich momentan mit der WinAPI und bin nun nachdem Menu darauf gekommen eine Datei zu Öffnen... Ich habe bereits Tutorials darüber gefunden mit einer Standard Dialog Box Dateien zu Öffnen</p>
<p>erstmal der Quelltextausschnitt:</p>
<pre><code class="language-cpp">LPWSTR FileOpen(HWND hWnd)
{
	OPENFILENAME ofn;
	TCHAR szFilter[] = L&quot;Alle Dateien (*.*)\0*.*\0\0&quot;;

	ofn.Flags				= OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
	ofn.hInstance			= NULL;
	ofn.hwndOwner			= NULL;
	ofn.lCustData			= 0L;
	ofn.lpfnHook			= NULL;
	ofn.lpstrCustomFilter	= NULL;
	ofn.lpstrDefExt			= NULL;
	ofn.lpstrFile			= 0;
	ofn.lpstrFileTitle		= NULL;
	ofn.lpstrFilter			= szFilter;
	ofn.lpstrInitialDir		= NULL;
	ofn.lpstrTitle			= NULL;
	ofn.lpTemplateName		= NULL;
	ofn.lStructSize			= sizeof(ofn);
	ofn.nFileExtension		= 0;
	ofn.nFileOffset			= 0;
	ofn.nFilterIndex		= 0;
	ofn.nMaxCustFilter		= 0;
	ofn.nMaxFile			= MAX_PATH;
	ofn.nMaxFileTitle		= MAX_PATH;
	ofn.pvReserved			= NULL;
	ofn.dwReserved			= 0;
	ofn.FlagsEx				= NULL;

	GetOpenFileName(&amp;ofn);

	return ofn.lpstrFile;
}
</code></pre>
<p>So, Beim Kompilieren ist noch alles in Ordnung... nur wenn ich dann versuche eine Datei zu Öffnen steht in &quot;ofn.lpstrFile&quot; nichts drin, Also nich der Pfad + Dateiname etc.<br />
Weshalb ich nich weiter damit arbeiten kann...<br />
Deshalb wollte ich fragen ob jemand vllt. einen Fehler in dem Code Entdeckt.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/191065/getopenfilename-problem</link><generator>RSS for Node</generator><lastBuildDate>Wed, 01 Jul 2026 17:23:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/191065.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 29 Aug 2007 19:24:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to GetOpenFileName() Problem on Wed, 29 Aug 2007 19:24:14 GMT]]></title><description><![CDATA[<p>Hallo,<br />
Wenn das im Falschen forum gelandet sein sollte dann sry^^</p>
<p>Also folgenes ich beschäftige mich momentan mit der WinAPI und bin nun nachdem Menu darauf gekommen eine Datei zu Öffnen... Ich habe bereits Tutorials darüber gefunden mit einer Standard Dialog Box Dateien zu Öffnen</p>
<p>erstmal der Quelltextausschnitt:</p>
<pre><code class="language-cpp">LPWSTR FileOpen(HWND hWnd)
{
	OPENFILENAME ofn;
	TCHAR szFilter[] = L&quot;Alle Dateien (*.*)\0*.*\0\0&quot;;

	ofn.Flags				= OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
	ofn.hInstance			= NULL;
	ofn.hwndOwner			= NULL;
	ofn.lCustData			= 0L;
	ofn.lpfnHook			= NULL;
	ofn.lpstrCustomFilter	= NULL;
	ofn.lpstrDefExt			= NULL;
	ofn.lpstrFile			= 0;
	ofn.lpstrFileTitle		= NULL;
	ofn.lpstrFilter			= szFilter;
	ofn.lpstrInitialDir		= NULL;
	ofn.lpstrTitle			= NULL;
	ofn.lpTemplateName		= NULL;
	ofn.lStructSize			= sizeof(ofn);
	ofn.nFileExtension		= 0;
	ofn.nFileOffset			= 0;
	ofn.nFilterIndex		= 0;
	ofn.nMaxCustFilter		= 0;
	ofn.nMaxFile			= MAX_PATH;
	ofn.nMaxFileTitle		= MAX_PATH;
	ofn.pvReserved			= NULL;
	ofn.dwReserved			= 0;
	ofn.FlagsEx				= NULL;

	GetOpenFileName(&amp;ofn);

	return ofn.lpstrFile;
}
</code></pre>
<p>So, Beim Kompilieren ist noch alles in Ordnung... nur wenn ich dann versuche eine Datei zu Öffnen steht in &quot;ofn.lpstrFile&quot; nichts drin, Also nich der Pfad + Dateiname etc.<br />
Weshalb ich nich weiter damit arbeiten kann...<br />
Deshalb wollte ich fragen ob jemand vllt. einen Fehler in dem Code Entdeckt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1354849</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1354849</guid><dc:creator><![CDATA[izen]]></dc:creator><pubDate>Wed, 29 Aug 2007 19:24:14 GMT</pubDate></item><item><title><![CDATA[Reply to GetOpenFileName() Problem on Wed, 29 Aug 2007 19:44:22 GMT]]></title><description><![CDATA[<p>du musst in ofn.lpstrFile einen Buffer übergeben, du könntest es so machen:</p>
<pre><code class="language-cpp">BOOL FileOpen(HWND hWnd, wchar_t* pBuffer)
{
    // ...
    ofn.lpstrFile = pBuffer;
    // ...
    return GetOpenFileName(&amp;ofn);
}
</code></pre>
<p>der Aufruf:</p>
<pre><code class="language-cpp">wchar_t szFileName[MAX_PATH];
FileOpen(hWnd, szFilename);
// Jetzt hast du in szFilename den Pfad und Dateiname
</code></pre>
<p>aber in der gesamten Struktur sind noch Fehler enthalten.</p>
<p>is nur jetzt zu spät...</p>
<p>wenn bis morgen kein anderer geantwortet hat, schreib ich den Rest morgen <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>MfG DrakoXP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1354873</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1354873</guid><dc:creator><![CDATA[DrakoXP]]></dc:creator><pubDate>Wed, 29 Aug 2007 19:44:22 GMT</pubDate></item><item><title><![CDATA[Reply to GetOpenFileName() Problem on Wed, 29 Aug 2007 20:04:19 GMT]]></title><description><![CDATA[<p>Da ist doch sogar extra ein Beispiel in der MSDN zu drin. Mensch Leute, es sollte selbstverständlich sein, erstmal die MSDN und Dr.Google zu konsultieren, bevor man hier ein Thema aufmacht!</p>
<p><a href="http://msdn2.microsoft.com/en-us/library/ms646829.aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/ms646829.aspx</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1354893</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1354893</guid><dc:creator><![CDATA[tenchou]]></dc:creator><pubDate>Wed, 29 Aug 2007 20:04:19 GMT</pubDate></item><item><title><![CDATA[Reply to GetOpenFileName() Problem on Thu, 30 Aug 2007 07:24:02 GMT]]></title><description><![CDATA[<p>hihi, die MSDN hat auch sinnlosigkeiten drin^^</p>
<p>MSDN schrieb:</p>
<blockquote>
<pre><code class="language-cpp">ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
</code></pre>
</blockquote>
<p>lol, und in der MSDN steht aber auch:</p>
<p>MSDN schrieb:</p>
<blockquote>
<p>OFN_FILEMUSTEXIST<br />
Specifies that the user can type only names of existing files in the File Name entry field. If this flag is specified and the user enters an invalid name, the dialog box procedure displays a warning in a message box. If this flag is specified, the OFN_PATHMUSTEXIST flag is also used. This flag can be used in an Open dialog box. It cannot be used with a Save As dialog box.</p>
</blockquote>
<p>kurz: wenn man OFN_FILEMUSTEXIST benutzt, braucht man OFN_PATHMUSTEXIST nicht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1355089</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355089</guid><dc:creator><![CDATA[DrakoXP]]></dc:creator><pubDate>Thu, 30 Aug 2007 07:24:02 GMT</pubDate></item><item><title><![CDATA[Reply to GetOpenFileName() Problem on Thu, 30 Aug 2007 13:43:55 GMT]]></title><description><![CDATA[<p>Durch die MSDN und Dr.Google habich den code ja so zusammengeflickt wie er ist^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1355360</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355360</guid><dc:creator><![CDATA[izen]]></dc:creator><pubDate>Thu, 30 Aug 2007 13:43:55 GMT</pubDate></item><item><title><![CDATA[Reply to GetOpenFileName() Problem on Thu, 30 Aug 2007 13:39:31 GMT]]></title><description><![CDATA[<p>also soll ich dir mal den Code vervollständigen?</p>
<p>so, dass er funktioniert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1355370</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355370</guid><dc:creator><![CDATA[DrakoXP]]></dc:creator><pubDate>Thu, 30 Aug 2007 13:39:31 GMT</pubDate></item><item><title><![CDATA[Reply to GetOpenFileName() Problem on Thu, 30 Aug 2007 13:44:49 GMT]]></title><description><![CDATA[<p>Naja mittlerweile habich ihn zu laufen gekrigt...<br />
Das Problem war scheinbar nur der Fehlende Buffer, nur du sagtest ja das da noch mehr fehler drin seien... und da wäre es nett wenn du die da raus machen könntest^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1355374</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355374</guid><dc:creator><![CDATA[izen]]></dc:creator><pubDate>Thu, 30 Aug 2007 13:44:49 GMT</pubDate></item><item><title><![CDATA[Reply to GetOpenFileName() Problem on Thu, 30 Aug 2007 14:36:51 GMT]]></title><description><![CDATA[<p>ich schreibe einfach mal, wie ich es gemacht hätte ^^</p>
<pre><code class="language-cpp">// hWnd -&gt; Elternfenster
// pBuffer -&gt; ein wchar_t-Puffer mit der Größe MAX_PATH
BOOL GetFileNameOpen(HWND hWnd, wchar_t* pBuffer)
{
    if (pBuffer == NULL) // Sicherheitsprüfung! (Leider kann man nicht prüfen, ob der Puffer auch groß genug ist xD
        return FALSE;
    OPENFILENAME ofn;
    ofn.dwReserved = 0;
    ofn.Flags = OFN_ENABLESIZING|OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_LONGNAMES;
    ofn.FlagsEx = 0;
    ofn.hInstance = GetModuleHandle(NULL);
    ofn.hwndOwner = hWnd;
    ofn.lCustData = NULL;
    ofn.lpfnHook = NULL;
    ofn.lpstrCustomFilter = NULL;
    ofn.lpstrDefExt = NULL;
    ofn.lpstrFile = pBuffer;
    ofn.lpstrFileTitle = NULL;
    ofn.lpstrFilter = L&quot;Textdateien (*.txt)\0*.txt\0Alle Dateien\0*.*\0\0&quot;; // Filter kannste ja machen, wie du ihn brauchst^^
    ofn.lpstrInitialDir = NULL;
    ofn.lpstrTitle = NULL;
    ofn.lpTemplateName = NULL;
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.nFileExtension = 0;
    ofn.nFileOffset = 0;
    ofn.nFilterIndex = 0;
    ofn.nMaxCustFilter = 0;
    ofn.nMaxFile = MAX_PATH;
    ofn.nMaxFileTitle = 0;
    ofn.pvReserved = NULL;
    return GetOpenFileName(&amp;ofn);
}
</code></pre>
<p>PS.: wenn du in dem Puffer schon was stehen hast, wird das zur Initialisierung verwendet.<br />
hast du den Puffer also erst erzeugt:</p>
<pre><code class="language-cpp">wchar_t szFileName[MAX_PATH];
// dann steht da was undefiniertes, und OpenFileName nutzt das zur Initialisierung!
// also sicherheitshalber noch das machen:
szFileName[0] = L'\0';
// dann geht alles und du kannst
GetFileNameOpen(hWnd, szFileName);
// machen ;)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1355405</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355405</guid><dc:creator><![CDATA[DrakoXP]]></dc:creator><pubDate>Thu, 30 Aug 2007 14:36:51 GMT</pubDate></item></channel></rss>