<?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[Problem mit BS_DEFPUSHBUTTON]]></title><description><![CDATA[<p>Hi Leutz!</p>
<p>Folgendes: Ich habe ein Fenster, das ich als Dialog verwende (also mit CreateWindow() erstellt). Darauf befinden sich mehrere Buttons, eine ListBox und ein Eingabefeld. Einer der Buttons wurde mit BS_DEFPUSHBUTTON erzeugt und ist dementsprechend auch bei der Laufzeit des Programms markiert (also fetter Rand). Wenn ich aber nun z.B. in der Listbox bin, oder gar keine Komponente meines Fensters den Fokus hat, und ich Enter drücke, passiert gar nichts. Nur wenn ich vorher den Fokus auf den Button mit SetFocus() setze gehts. Um diesen Effekt immer zu erreichen, setze ich den Fokus nun jedes mal wenn das WM_COMMAND für den Button ausgeführt wurde wieder auf den Button. Aber eigentlich sollte dieser Button ausgeführt werden wenn ich, egal wo, auf dem Fenster Enter drücke.</p>
<p>Versteht ihr was ich meine?</p>
<p>Ich dachte erst es läge an meinem Message-Loop, den Fehler konnte ich auch beheben (sieht jetzt wie unten aus) nur liegt das Problem wohl noch woanders.</p>
<p>So sieht mein Code (Auszüge) aus:</p>
<pre><code class="language-cpp">[...]

//Fenster erzeugen
hWin = CreateWindowEx (0, szAppName, &quot;&quot;, WS_CAPTION | WS_SYSMENU
    | WS_BORDER | WS_SIZEBOX, 0, 0, 400, 200, NULL, NULL, hInstance, NULL);

hList = CreateWindowEx(WS_EX_CLIENTEDGE ,&quot;listbox&quot;, NULL, WS_CHILD | WS_VISIBLE | ES_LEFT
 | WS_VSCROLL | LBS_NOINTEGRALHEIGHT , 0, 0, 185, 140, hWin, (HMENU) LIST, 
   hInstance, NULL) ;
SendMessage(hList, WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);

hButton1 = CreateWindowEx(0, &quot;button&quot;, &quot;&amp;Ok&quot;, WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
  1, 185, 100, 25, hWin, (HMENU) BUTTON1, hInstance, NULL) ;
SendMessage(hButton1, WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);

hButton2 = CreateWindowEx(0, &quot;button&quot;, &quot;&amp;Cancel&quot;, WS_CHILD | WS_VISIBLE,
  300, 185, 100, 25, hWin, (HMENU) BUTTON2, hInstance, NULL) ;
SendMessage(hButton2, WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);

[...]

SetFocus(hButton1); //Fokus setzen
while(GetMessage(&amp;msg, NULL, 0, 0))
{
    //Abfangen von Dialog Messages
    if(!IsDialogMessage(GetForegroundWindow(), &amp;msg))
    {
        TranslateMessage(&amp;msg);
        DispatchMessage(&amp;msg);
    }
}

[...]
//In der WndProc...
        case WM_COMMAND:
                        if(hWnd == hWin)
                        {

                                if(LOWORD(wParam) == BUTTON1)
                                {
                                        MessageBox(NULL, &quot;Test&quot;, &quot;&quot;, 0);
                                        SetFocus(hButton1); //Erneutes setzen
                                }
                        }
                        return 0;
</code></pre>
<p>Könnt ihr mir helfen??</p>
<p>Danke &amp; Gruss,<br />
code_pilot :p</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/69114/problem-mit-bs_defpushbutton</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Apr 2026 20:25:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/69114.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 24 Mar 2004 13:48:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit BS_DEFPUSHBUTTON on Wed, 24 Mar 2004 13:52:31 GMT]]></title><description><![CDATA[<p>Hi Leutz!</p>
<p>Folgendes: Ich habe ein Fenster, das ich als Dialog verwende (also mit CreateWindow() erstellt). Darauf befinden sich mehrere Buttons, eine ListBox und ein Eingabefeld. Einer der Buttons wurde mit BS_DEFPUSHBUTTON erzeugt und ist dementsprechend auch bei der Laufzeit des Programms markiert (also fetter Rand). Wenn ich aber nun z.B. in der Listbox bin, oder gar keine Komponente meines Fensters den Fokus hat, und ich Enter drücke, passiert gar nichts. Nur wenn ich vorher den Fokus auf den Button mit SetFocus() setze gehts. Um diesen Effekt immer zu erreichen, setze ich den Fokus nun jedes mal wenn das WM_COMMAND für den Button ausgeführt wurde wieder auf den Button. Aber eigentlich sollte dieser Button ausgeführt werden wenn ich, egal wo, auf dem Fenster Enter drücke.</p>
<p>Versteht ihr was ich meine?</p>
<p>Ich dachte erst es läge an meinem Message-Loop, den Fehler konnte ich auch beheben (sieht jetzt wie unten aus) nur liegt das Problem wohl noch woanders.</p>
<p>So sieht mein Code (Auszüge) aus:</p>
<pre><code class="language-cpp">[...]

//Fenster erzeugen
hWin = CreateWindowEx (0, szAppName, &quot;&quot;, WS_CAPTION | WS_SYSMENU
    | WS_BORDER | WS_SIZEBOX, 0, 0, 400, 200, NULL, NULL, hInstance, NULL);

hList = CreateWindowEx(WS_EX_CLIENTEDGE ,&quot;listbox&quot;, NULL, WS_CHILD | WS_VISIBLE | ES_LEFT
 | WS_VSCROLL | LBS_NOINTEGRALHEIGHT , 0, 0, 185, 140, hWin, (HMENU) LIST, 
   hInstance, NULL) ;
SendMessage(hList, WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);

hButton1 = CreateWindowEx(0, &quot;button&quot;, &quot;&amp;Ok&quot;, WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
  1, 185, 100, 25, hWin, (HMENU) BUTTON1, hInstance, NULL) ;
SendMessage(hButton1, WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);

hButton2 = CreateWindowEx(0, &quot;button&quot;, &quot;&amp;Cancel&quot;, WS_CHILD | WS_VISIBLE,
  300, 185, 100, 25, hWin, (HMENU) BUTTON2, hInstance, NULL) ;
SendMessage(hButton2, WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);

[...]

SetFocus(hButton1); //Fokus setzen
while(GetMessage(&amp;msg, NULL, 0, 0))
{
    //Abfangen von Dialog Messages
    if(!IsDialogMessage(GetForegroundWindow(), &amp;msg))
    {
        TranslateMessage(&amp;msg);
        DispatchMessage(&amp;msg);
    }
}

[...]
//In der WndProc...
        case WM_COMMAND:
                        if(hWnd == hWin)
                        {

                                if(LOWORD(wParam) == BUTTON1)
                                {
                                        MessageBox(NULL, &quot;Test&quot;, &quot;&quot;, 0);
                                        SetFocus(hButton1); //Erneutes setzen
                                }
                        }
                        return 0;
</code></pre>
<p>Könnt ihr mir helfen??</p>
<p>Danke &amp; Gruss,<br />
code_pilot :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/487702</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/487702</guid><dc:creator><![CDATA[code_pilot]]></dc:creator><pubDate>Wed, 24 Mar 2004 13:52:31 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit BS_DEFPUSHBUTTON on Wed, 24 Mar 2004 15:43:13 GMT]]></title><description><![CDATA[<p>Ich weiß, in der WinAPI ist das mit Fokus und bestimmte Tasten belegen immer so ein Problem. Wenn Du unbedingt auf der Entertaste den Button aktivieren willst, würde sich das z.B. schonmal mit</p>
<p>RegisterHotKey()</p>
<p>lösen lassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/487874</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/487874</guid><dc:creator><![CDATA[ChrisK]]></dc:creator><pubDate>Wed, 24 Mar 2004 15:43:13 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit BS_DEFPUSHBUTTON on Wed, 24 Mar 2004 15:44:51 GMT]]></title><description><![CDATA[<p>Keine Ahnung, ob's daran liegt, aber setz doch mal bei IsDialogMessage anstelle von GetForegroundWindow() das Handle deines Hauptfensters (also hWin) ein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/487876</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/487876</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Wed, 24 Mar 2004 15:44:51 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit BS_DEFPUSHBUTTON on Wed, 24 Mar 2004 17:11:49 GMT]]></title><description><![CDATA[<p>Du solltest am besten die DefDlgProc benutzen.<br />
(Dazu muss man beim Registrieren der Fensterklasse cbWndExtra noch auf DLGWINDOWEXTRA setzen)</p>
<p>Dann wird der Fokus immer wieder hergestellt und du brauchst es nicht immer seltst machen wie nach der MessageBox.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/487976</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/487976</guid><dc:creator><![CDATA[.]]></dc:creator><pubDate>Wed, 24 Mar 2004 17:11:49 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit BS_DEFPUSHBUTTON on Wed, 24 Mar 2004 21:57:18 GMT]]></title><description><![CDATA[<p>Hallo, danke erstmal ich werds mir mal anschauen... ach ja HotKeys haben mich sowieso schonmal interessiert <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>~cp</p>
]]></description><link>https://www.c-plusplus.net/forum/post/488197</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/488197</guid><dc:creator><![CDATA[code_pilot]]></dc:creator><pubDate>Wed, 24 Mar 2004 21:57:18 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit BS_DEFPUSHBUTTON on Thu, 25 Mar 2004 00:55:09 GMT]]></title><description><![CDATA[<p>und dem Button noch die ID IDOK geben. Hotkeys brauchst du für diesen Fall nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/488231</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/488231</guid><dc:creator><![CDATA[IDOK]]></dc:creator><pubDate>Thu, 25 Mar 2004 00:55:09 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit BS_DEFPUSHBUTTON on Thu, 25 Mar 2004 14:17:11 GMT]]></title><description><![CDATA[<p>Warum das? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> Ich kann das define doch nennen wie ich will oder wie oder wat (oder wer oder warum und ... wieso eigentlich oder wie oder wat ...)</p>
<p>~cp <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>
]]></description><link>https://www.c-plusplus.net/forum/post/488589</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/488589</guid><dc:creator><![CDATA[code_pilot]]></dc:creator><pubDate>Thu, 25 Mar 2004 14:17:11 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit BS_DEFPUSHBUTTON on Thu, 25 Mar 2004 14:21:08 GMT]]></title><description><![CDATA[<p>BS_DEFPUSHBUTTON ist nur der Startzustand. Wenn du einen anderen Button anklickst, bekommt dieser den DEFPUSHBUTTON-Status. Wenn die Listbox den Focus bekommt, wird der Button mit der ID IDOK zum DEFPUSHBUTTON.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/488596</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/488596</guid><dc:creator><![CDATA[IDOK]]></dc:creator><pubDate>Thu, 25 Mar 2004 14:21:08 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit BS_DEFPUSHBUTTON on Thu, 25 Mar 2004 14:22:04 GMT]]></title><description><![CDATA[<p>Anstatt BUTTON1 schreibst du einfach IDOK hin. (das ist schon definiert)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/488598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/488598</guid><dc:creator><![CDATA[IDOK]]></dc:creator><pubDate>Thu, 25 Mar 2004 14:22:04 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit BS_DEFPUSHBUTTON on Thu, 25 Mar 2004 15:21:12 GMT]]></title><description><![CDATA[<p>Stimmt, so is dat. Ich würde dir außerdem empfehlen, für den Dialog ein Resource-Skript zu erstellen. Dann brauchst du erstens nicht die ganzen CreateWindow's in deinem Code, und zweitens sieht der Dialog dann auf jedem System und bei jeder Auflösung gleich aus. Zur Zeit ist der Dialog bei 600x800-Auflösung riesig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/488694</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/488694</guid><dc:creator><![CDATA[WebFritzi]]></dc:creator><pubDate>Thu, 25 Mar 2004 15:21:12 GMT</pubDate></item></channel></rss>