<?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[GetWindowText Anfängerfrage]]></title><description><![CDATA[<p>Hallo!<br />
Bin Anfänger und hab auch schon ein Problem. Möchte mit GetWindowText einen Text aus nem Textfeld auslesen, das haut nur nicht ganz hin. Irgendwas passt GetWindowText und AddString an meinem char str[100] nicht...</p>
<p>Hier ist mal der Quelltext:</p>
<pre><code class="language-cpp">void CZinsenDlg::OnBnRechnen()
{
// TODO: Add your control notification handler code here
double Startkapital, Zinssatz;
int Laufzeit;
double Ertrag;
char str[100];

// alte Werte aus Liste löschen
m_Ausgabe.ResetContent();

// Benutzereingaben einlesen
m_Startkapital.GetWindowText(str, 100);
Startkapital = atof(str);
m_Zinssatz.GetWindowText(str, 100);
Zinssatz = atof(str);
m_Laufzeit.GetWindowText(str, 100);
Laufzeit = (int) atof(str);

//Kapitalentwicklung über die Jahre
for(int i = 0;i &lt;= Laufzeit; i++)
{
Ertrag = ErtragOhneZinseszins(Startkapital, Zinssatz, i);
sprintf(str, &quot;%lf&quot;, Ertrag);
m_Ausgabe.AddString(str);
}
m_Ausgabe.SetCurSel(Laufzeit);

}
</code></pre>
<p>Und die Fehlermedungen:</p>
<p>zinsendlg.cpp(108) : error C2664: 'int CWnd::GetWindowTextW(LPTSTR,int) const' : cannot convert parameter 1 from 'char [100]' to 'LPTSTR'<br />
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast</p>
<p>zinsendlg.cpp(110) : error C2664: 'int CWnd::GetWindowTextW(LPTSTR,int) const' : cannot convert parameter 1 from 'char [100]' to 'LPTSTR'<br />
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast</p>
<p>zinsendlg.cpp(112) : error C2664: 'int CWnd::GetWindowTextW(LPTSTR,int) const' : cannot convert parameter 1 from 'char [100]' to 'LPTSTR'<br />
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast</p>
<p>zinsendlg.cpp(120) : error C2664: 'CComboBox::AddString' : cannot convert parameter 1 from 'char [100]' to 'LPCTSTR'<br />
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast</p>
<p>Ich hoffe, ich hab das jetzt eh in die richtige Kategorie gepostet (hab nicht gewusst ob vc++ oder WinAPI) und dass mir bald jemand helfen kann!<br />
Danke, cremlin</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/190887/getwindowtext-anfängerfrage</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 09:05:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/190887.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 28 Aug 2007 07:26:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to GetWindowText Anfängerfrage on Tue, 28 Aug 2007 07:26:33 GMT]]></title><description><![CDATA[<p>Hallo!<br />
Bin Anfänger und hab auch schon ein Problem. Möchte mit GetWindowText einen Text aus nem Textfeld auslesen, das haut nur nicht ganz hin. Irgendwas passt GetWindowText und AddString an meinem char str[100] nicht...</p>
<p>Hier ist mal der Quelltext:</p>
<pre><code class="language-cpp">void CZinsenDlg::OnBnRechnen()
{
// TODO: Add your control notification handler code here
double Startkapital, Zinssatz;
int Laufzeit;
double Ertrag;
char str[100];

// alte Werte aus Liste löschen
m_Ausgabe.ResetContent();

// Benutzereingaben einlesen
m_Startkapital.GetWindowText(str, 100);
Startkapital = atof(str);
m_Zinssatz.GetWindowText(str, 100);
Zinssatz = atof(str);
m_Laufzeit.GetWindowText(str, 100);
Laufzeit = (int) atof(str);

//Kapitalentwicklung über die Jahre
for(int i = 0;i &lt;= Laufzeit; i++)
{
Ertrag = ErtragOhneZinseszins(Startkapital, Zinssatz, i);
sprintf(str, &quot;%lf&quot;, Ertrag);
m_Ausgabe.AddString(str);
}
m_Ausgabe.SetCurSel(Laufzeit);

}
</code></pre>
<p>Und die Fehlermedungen:</p>
<p>zinsendlg.cpp(108) : error C2664: 'int CWnd::GetWindowTextW(LPTSTR,int) const' : cannot convert parameter 1 from 'char [100]' to 'LPTSTR'<br />
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast</p>
<p>zinsendlg.cpp(110) : error C2664: 'int CWnd::GetWindowTextW(LPTSTR,int) const' : cannot convert parameter 1 from 'char [100]' to 'LPTSTR'<br />
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast</p>
<p>zinsendlg.cpp(112) : error C2664: 'int CWnd::GetWindowTextW(LPTSTR,int) const' : cannot convert parameter 1 from 'char [100]' to 'LPTSTR'<br />
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast</p>
<p>zinsendlg.cpp(120) : error C2664: 'CComboBox::AddString' : cannot convert parameter 1 from 'char [100]' to 'LPCTSTR'<br />
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast</p>
<p>Ich hoffe, ich hab das jetzt eh in die richtige Kategorie gepostet (hab nicht gewusst ob vc++ oder WinAPI) und dass mir bald jemand helfen kann!<br />
Danke, cremlin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1353504</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353504</guid><dc:creator><![CDATA[cremlin]]></dc:creator><pubDate>Tue, 28 Aug 2007 07:26:33 GMT</pubDate></item><item><title><![CDATA[Reply to GetWindowText Anfängerfrage on Tue, 28 Aug 2007 07:35:12 GMT]]></title><description><![CDATA[<p>Nimm doch einen CString. <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/1353512</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353512</guid><dc:creator><![CDATA[estartu]]></dc:creator><pubDate>Tue, 28 Aug 2007 07:35:12 GMT</pubDate></item><item><title><![CDATA[Reply to GetWindowText Anfängerfrage on Tue, 28 Aug 2007 07:36:23 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">void CZinsenDlg::OnBnRechnen()
{
// TODO: Add your control notification handler code here
double Startkapital, Zinssatz;
int Laufzeit;
double Ertrag;
CString str;

// alte Werte aus Liste löschen
m_Ausgabe.ResetContent();

// Benutzereingaben einlesen
m_Startkapital.GetWindowText(str);
Startkapital = atof(str);
m_Zinssatz.GetWindowText(str);
Zinssatz = atof(str);
m_Laufzeit.GetWindowText(str);
Laufzeit = (int) atof(str);

//Kapitalentwicklung über die Jahre
for(int i = 0;i &lt;= Laufzeit; i++)
{
Ertrag = ErtragOhneZinseszins(Startkapital, Zinssatz, i);
str.Format(&quot;%lf&quot;, Ertrag);
m_Ausgabe.AddString(str);
}
m_Ausgabe.SetCurSel(Laufzeit);

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1353513</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353513</guid><dc:creator><![CDATA[loop]]></dc:creator><pubDate>Tue, 28 Aug 2007 07:36:23 GMT</pubDate></item><item><title><![CDATA[Reply to GetWindowText Anfängerfrage on Tue, 28 Aug 2007 08:00:20 GMT]]></title><description><![CDATA[<p>cremlin schrieb:</p>
<blockquote>
<p>zinsendlg.cpp(108) : error C2664: 'int CWnd::GetWindowTextW(LPTSTR,int) const' : cannot convert parameter 1 from 'char [100]' to 'LPTSTR'<br />
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast</p>
</blockquote>
<p>Falsche Projekteinstellungen - GetWindoeTextW() ist die UNICODE-Variante und erwartet ein wchar_t-Array als Ziel für die Ausgabe. Das heißt, du brauchst einen <code>wchar_t str[100];</code> , <code>TCHAR str[100];</code> (funktioniert unabhängig von den Projekteinstellungen) oder <code>CString str;</code> (wohl die beste Alternative).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1353537</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353537</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 28 Aug 2007 08:00:20 GMT</pubDate></item><item><title><![CDATA[Reply to GetWindowText Anfängerfrage on Tue, 28 Aug 2007 08:08:52 GMT]]></title><description><![CDATA[<p>Danke für die schnelle Antwort. Jetzt hab ich zwar kein Problem mit GetWindowText mehr, dafür aber mit atof:</p>
<p>zinsendlg.cpp(140) : error C2664: 'atof' : cannot convert parameter 1 from 'CString' to 'const char *'<br />
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called</p>
<p>zinsendlg.cpp(142) : error C2664: 'atof' : cannot convert parameter 1 from 'CString' to 'const char *'<br />
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called</p>
<p>zinsendlg.cpp(144) : error C2664: 'atof' : cannot convert parameter 1 from 'CString' to 'const char *'<br />
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called</p>
<p>zinsendlg.cpp(150) : error C2664: 'void ATL::CStringT&lt;BaseType,StringTraits&gt;::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [4]' to 'const wchar_t *'<br />
with<br />
[<br />
BaseType=wchar_t,<br />
StringTraits=StrTraitMFC_DLL&lt;wchar_t&gt;<br />
]</p>
<p>Blickt da wer durch??<br />
Hab das Beispiel Zeichen für Zeichen aus dem Buch &quot;Jetzt lerne ich Visual C++ .NET&quot; übernommen und es funktioniert trotzdem nicht <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="😞"
    /> ärgerlich</p>
<p>Sollte ich also die Projekteinstellungen ändern? Und wo/wie ändere ich das auf die &quot;nicht-unicode-variante&quot;?<br />
lg cremlin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1353542</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353542</guid><dc:creator><![CDATA[cremlin]]></dc:creator><pubDate>Tue, 28 Aug 2007 08:08:52 GMT</pubDate></item><item><title><![CDATA[Reply to GetWindowText Anfängerfrage on Tue, 28 Aug 2007 08:25:32 GMT]]></title><description><![CDATA[<p>Wenn Du MFC verwendest dann bitte nicht sprintf oder ähnliches.<br />
Nimm Format von CString.</p>
<p>Eine CString zu int</p>
<pre><code class="language-cpp">int t = 0;
CString cs(&quot;2&quot;);

t = atoi(cs);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1353547</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353547</guid><dc:creator><![CDATA[Unix-Tom]]></dc:creator><pubDate>Tue, 28 Aug 2007 08:25:32 GMT</pubDate></item><item><title><![CDATA[Reply to GetWindowText Anfängerfrage on Tue, 28 Aug 2007 08:20:38 GMT]]></title><description><![CDATA[<p>cremlin schrieb:</p>
<blockquote>
<p>zinsendlg.cpp(140) : error C2664: 'atof' : cannot convert parameter 1 from 'CString' to 'const char *'<br />
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called</p>
</blockquote>
<p>Ja, atof() wiederum erwartet char-Daten und keine wchar_t's - ergo mußt du es ersetzen durch die UNICODE-Variante '_wtof()' (bzw. '_ttof()').</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1353550</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353550</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 28 Aug 2007 08:20:38 GMT</pubDate></item><item><title><![CDATA[Reply to GetWindowText Anfängerfrage on Tue, 28 Aug 2007 08:35:07 GMT]]></title><description><![CDATA[<p>Ok, jetzt ist nurnoch die letzte Fehlermeldung aktuell. str.Format erwartet also &quot;const wchar_t*&quot;....<br />
Wie krieg ich das jetzt noch hin?<br />
Ich muss doch irgendwo die Projekteinstellungen so ändern können, dass kein unicode verwendet wird, oder? Sonst muss ich jedes Programm aus dem Buch umschreiben damit es bei mir funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1353559</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353559</guid><dc:creator><![CDATA[cremlin]]></dc:creator><pubDate>Tue, 28 Aug 2007 08:35:07 GMT</pubDate></item><item><title><![CDATA[Reply to GetWindowText Anfängerfrage on Tue, 28 Aug 2007 08:41:29 GMT]]></title><description><![CDATA[<p>cremlin schrieb:</p>
<blockquote>
<p>Ok, jetzt ist nurnoch die letzte Fehlermeldung aktuell. str.Format erwartet also &quot;const wchar_t*&quot;....<br />
Wie krieg ich das jetzt noch hin?</p>
</blockquote>
<p>Klammere den Formatstring in _T(...) oder TEXT(...).</p>
<blockquote>
<p>Ich muss doch irgendwo die Projekteinstellungen so ändern können, dass kein unicode verwendet wird, oder? Sonst muss ich jedes Programm aus dem Buch umschreiben damit es bei mir funktioniert.</p>
</blockquote>
<p>In den Projekteinstellungen unter C/C++ -&gt; Präprozessor kannst du den Eintrag UNICODE aus den Präprozessor-Definitionen rausnehmen, dann compiliert er wieder im ANSI-Modus (alles verwendet char-Daten).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1353562</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353562</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 28 Aug 2007 08:41:29 GMT</pubDate></item><item><title><![CDATA[Reply to GetWindowText Anfängerfrage on Tue, 28 Aug 2007 08:58:28 GMT]]></title><description><![CDATA[<p>Bei den Präprozessordefinitionen steht nur WIN32;_WINDOWS;_DEBUG , nichts von UNICODE...<br />
Tut leid wenn ich mich etwas dumm anstelle, aber was genau soll ich mit _T() einklammern? Hab schon alle Kombinationen versucht. Am längsten hat er kompilliert, wie ich %lf eingeklammert hab, aber funktioniert hats trotzdem nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1353575</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353575</guid><dc:creator><![CDATA[cremlin]]></dc:creator><pubDate>Tue, 28 Aug 2007 08:58:28 GMT</pubDate></item><item><title><![CDATA[Reply to GetWindowText Anfängerfrage on Tue, 28 Aug 2007 09:24:51 GMT]]></title><description><![CDATA[<p>Schreib statt &quot;blablaZeichenkette&quot; einfach _T(&quot;blablaZeichenkette&quot;).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1353595</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353595</guid><dc:creator><![CDATA[estartu]]></dc:creator><pubDate>Tue, 28 Aug 2007 09:24:51 GMT</pubDate></item><item><title><![CDATA[Reply to GetWindowText Anfängerfrage on Tue, 28 Aug 2007 14:12:25 GMT]]></title><description><![CDATA[<p>Ok, auch auf die gefahr hin, dass ich wie ein mensch ohne hirn klinge: Was genau soll ich in _T() einklammern?? Den quelltext hab ich ja schon gepostet und es geht jetzt nur noch um die zeile str.Format(&quot;%lf&quot;, Ertrag); wenn ich das richtig sehe. Und was in dieser zeile soll ich jetzt einklammern? Will doch nur das Programm mal zum laufen kriegen, dann lass ich euch schon in ruhe...<br />
lg, cremlin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1353876</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353876</guid><dc:creator><![CDATA[cremlin]]></dc:creator><pubDate>Tue, 28 Aug 2007 14:12:25 GMT</pubDate></item><item><title><![CDATA[Reply to GetWindowText Anfängerfrage on Tue, 28 Aug 2007 16:55:50 GMT]]></title><description><![CDATA[<p>Du brauchst uns nicht in Ruhe lassen, allerdings versuchen wir hier, eher generell zu erklären als nur schnell den Code hinzurotzen.</p>
<pre><code class="language-cpp">zeile str.Format(_T(&quot;%lf&quot;), Ertrag);
</code></pre>
<p>So war das gemeint.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1353969</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1353969</guid><dc:creator><![CDATA[estartu]]></dc:creator><pubDate>Tue, 28 Aug 2007 16:55:50 GMT</pubDate></item></channel></rss>