<?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 WM_KEYUP]]></title><description><![CDATA[<p>Erstmal Hallo^^<br />
Bin neu hier im Forum, totaler Anfänger in der wind32 programmierung und wollte mal fragen ob ihr mir hier weiterhelfen könnt.</p>
<p>Mein Problem: (hab dazu auch nichts in der such funktion gefunden)</p>
<p>Ich möchte das sich das Programm beendet, wenn man die ESC-Taste drückt. Das hab ich auch geschafft. Jetzt hab ich aber das Problem, sobald das Child-EDIT Fenster anktiv ist(wenn ich mit der Maus reinklicke) dann kommt die WM_KEYUP Nachricht nicht mehr an.<br />
Danach hab ich es versucht als WM_COMMAND Nachricht zu verschicken.<br />
Wenn ich jetzt ESC drücke passiert erstmal noch nichts. Wenn ich jetzt den Fokus wechsle kommt die Nachricht erst an. Das will ich so aber nciht^^</p>
<p>Naja hier mal der Code dazu:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

#define CHAT_OUTPUT   1
#define CHAT_INPUT    2

HWND bChatOutput, bChatInput;

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

LPCSTR lpszName   = &quot;Chat&quot;;

HINSTANCE hInst;

int APIENTRY WinMain(HINSTANCE hInstance,
           HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{

   HWND       hWnd;
   MSG        msg;
   WNDCLASSEX   wc;

   wc.cbSize        =  sizeof(WNDCLASSEX);
   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(BLACK_BRUSH);
   wc.lpszClassName =  lpszName;
   wc.lpszMenuName  =  NULL;
   wc.hIconSm       =  LoadIcon(NULL, IDI_APPLICATION);

   if(!RegisterClassEx(&amp;wc))
      {
       MessageBox(NULL, &quot;Windows Registrations Fehler&quot;, &quot;Error!&quot;,
                  MB_ICONEXCLAMATION | MB_OK);
       return 0;
      }

    hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, lpszName,
                          &quot;Chat&quot;,
                          WS_OVERLAPPED|WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          600, 400,NULL,NULL,hInstance, NULL);

    hInst=hInstance;

    if(hWnd == NULL)
    {
       if(MessageBox(NULL, &quot;Fehler beim Erstellen des Fensters!&quot;,
          &quot;Error!&quot;,        MB_ICONEXCLAMATION | MB_OK) == IDOK);
          return 0;
    }

   if( hWnd == NULL)
      return 0;

   while (GetMessage(&amp;msg, NULL, 0, 0) &gt; 0)
   {
      TranslateMessage(&amp;msg);
      DispatchMessage(&amp;msg);
   }
   return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
   switch (umsg)
   {
   case WM_CREATE:
     bChatOutput = CreateWindow(&quot;EDIT&quot;,&quot;ChatOutput&quot;,WS_CHILD|WS_VISIBLE|
                          WS_DLGFRAME|WS_VSCROLL|ES_MULTILINE|ES_READONLY,
                          10, 10, 567, 318,
                          hWnd, (HMENU)CHAT_OUTPUT, ((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
     bChatInput  = CreateWindow(&quot;EDIT&quot;,&quot;ChatInput&quot;,WS_CHILD|WS_VISIBLE|
                          WS_DLGFRAME|ES_AUTOHSCROLL, 10, 338, 567, 22,
                          hWnd, (HMENU)CHAT_INPUT, ((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
     return 0;
   case WM_KEYUP:
     if ( GetAsyncKeyState (VK_ESCAPE))
     {
       int bAntwort =
       MessageBox(NULL,&quot;Sie haben \&quot;ESC\&quot; gedrückt!\n&quot;
                  &quot;Programm beenden?&quot;,&quot;Abfrage&quot;,
                  MB_ICONINFORMATION | MB_OKCANCEL |
                  MB_DEFBUTTON1);
       if(bAntwort == IDOK)
         PostQuitMessage(0);
       else
         break;
     }
     return 0;
   case WM_DESTROY:
     {
       PostQuitMessage(0);
       return 0;
     }
   case WM_COMMAND:
     if ( GetAsyncKeyState (VK_ESCAPE))
     {
       int bAntwort;
       bAntwort =
       MessageBox(NULL,&quot;Sie haben \&quot;ESC\&quot; gedrückt!\n&quot;
                  &quot;Programm beenden?&quot;,&quot;Abfrage&quot;,
                  MB_ICONINFORMATION | MB_OKCANCEL |
                  MB_DEFBUTTON1);
       if(bAntwort == IDOK)
         PostQuitMessage(0);
       else
         break;
     }  
     return 0;
   }
   return DefWindowProc(hWnd, umsg, wParam, lParam);
}
</code></pre>
<p>Naja wie gesagt bin noch totaler Anfänger und kenn mich gar nicht aus^^</p>
<p>Ich hoffe ihr könnt mir weiter helfen</p>
<p>mfg Nanobot</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/200969/problem-mit-wm_keyup</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 08:30:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/200969.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Dec 2007 11:56:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit WM_KEYUP on Sat, 22 Dec 2007 11:56:21 GMT]]></title><description><![CDATA[<p>Erstmal Hallo^^<br />
Bin neu hier im Forum, totaler Anfänger in der wind32 programmierung und wollte mal fragen ob ihr mir hier weiterhelfen könnt.</p>
<p>Mein Problem: (hab dazu auch nichts in der such funktion gefunden)</p>
<p>Ich möchte das sich das Programm beendet, wenn man die ESC-Taste drückt. Das hab ich auch geschafft. Jetzt hab ich aber das Problem, sobald das Child-EDIT Fenster anktiv ist(wenn ich mit der Maus reinklicke) dann kommt die WM_KEYUP Nachricht nicht mehr an.<br />
Danach hab ich es versucht als WM_COMMAND Nachricht zu verschicken.<br />
Wenn ich jetzt ESC drücke passiert erstmal noch nichts. Wenn ich jetzt den Fokus wechsle kommt die Nachricht erst an. Das will ich so aber nciht^^</p>
<p>Naja hier mal der Code dazu:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

#define CHAT_OUTPUT   1
#define CHAT_INPUT    2

HWND bChatOutput, bChatInput;

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

LPCSTR lpszName   = &quot;Chat&quot;;

HINSTANCE hInst;

int APIENTRY WinMain(HINSTANCE hInstance,
           HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{

   HWND       hWnd;
   MSG        msg;
   WNDCLASSEX   wc;

   wc.cbSize        =  sizeof(WNDCLASSEX);
   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(BLACK_BRUSH);
   wc.lpszClassName =  lpszName;
   wc.lpszMenuName  =  NULL;
   wc.hIconSm       =  LoadIcon(NULL, IDI_APPLICATION);

   if(!RegisterClassEx(&amp;wc))
      {
       MessageBox(NULL, &quot;Windows Registrations Fehler&quot;, &quot;Error!&quot;,
                  MB_ICONEXCLAMATION | MB_OK);
       return 0;
      }

    hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, lpszName,
                          &quot;Chat&quot;,
                          WS_OVERLAPPED|WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          600, 400,NULL,NULL,hInstance, NULL);

    hInst=hInstance;

    if(hWnd == NULL)
    {
       if(MessageBox(NULL, &quot;Fehler beim Erstellen des Fensters!&quot;,
          &quot;Error!&quot;,        MB_ICONEXCLAMATION | MB_OK) == IDOK);
          return 0;
    }

   if( hWnd == NULL)
      return 0;

   while (GetMessage(&amp;msg, NULL, 0, 0) &gt; 0)
   {
      TranslateMessage(&amp;msg);
      DispatchMessage(&amp;msg);
   }
   return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
   switch (umsg)
   {
   case WM_CREATE:
     bChatOutput = CreateWindow(&quot;EDIT&quot;,&quot;ChatOutput&quot;,WS_CHILD|WS_VISIBLE|
                          WS_DLGFRAME|WS_VSCROLL|ES_MULTILINE|ES_READONLY,
                          10, 10, 567, 318,
                          hWnd, (HMENU)CHAT_OUTPUT, ((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
     bChatInput  = CreateWindow(&quot;EDIT&quot;,&quot;ChatInput&quot;,WS_CHILD|WS_VISIBLE|
                          WS_DLGFRAME|ES_AUTOHSCROLL, 10, 338, 567, 22,
                          hWnd, (HMENU)CHAT_INPUT, ((LPCREATESTRUCT) lParam)-&gt;hInstance, NULL);
     return 0;
   case WM_KEYUP:
     if ( GetAsyncKeyState (VK_ESCAPE))
     {
       int bAntwort =
       MessageBox(NULL,&quot;Sie haben \&quot;ESC\&quot; gedrückt!\n&quot;
                  &quot;Programm beenden?&quot;,&quot;Abfrage&quot;,
                  MB_ICONINFORMATION | MB_OKCANCEL |
                  MB_DEFBUTTON1);
       if(bAntwort == IDOK)
         PostQuitMessage(0);
       else
         break;
     }
     return 0;
   case WM_DESTROY:
     {
       PostQuitMessage(0);
       return 0;
     }
   case WM_COMMAND:
     if ( GetAsyncKeyState (VK_ESCAPE))
     {
       int bAntwort;
       bAntwort =
       MessageBox(NULL,&quot;Sie haben \&quot;ESC\&quot; gedrückt!\n&quot;
                  &quot;Programm beenden?&quot;,&quot;Abfrage&quot;,
                  MB_ICONINFORMATION | MB_OKCANCEL |
                  MB_DEFBUTTON1);
       if(bAntwort == IDOK)
         PostQuitMessage(0);
       else
         break;
     }  
     return 0;
   }
   return DefWindowProc(hWnd, umsg, wParam, lParam);
}
</code></pre>
<p>Naja wie gesagt bin noch totaler Anfänger und kenn mich gar nicht aus^^</p>
<p>Ich hoffe ihr könnt mir weiter helfen</p>
<p>mfg Nanobot</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1424766</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1424766</guid><dc:creator><![CDATA[Nanobot]]></dc:creator><pubDate>Sat, 22 Dec 2007 11:56:21 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit WM_KEYUP on Sat, 22 Dec 2007 17:59:04 GMT]]></title><description><![CDATA[<p>Das ist nur konsequent, denn nur das Fenster, dass den Focus hat (also Dein Child Window) bekommt WM_KEY... Nachrichten.</p>
<p>Wie wäre es wenn, Du einen modalen Dialog erzeugst, der hat immer das Verrhalten bei Escape zu schließen.</p>
<p>Ansonsten musst Du die Prüfung in die Message-Loop einbauen oder einen Accelerator verwenden, der eine entsprechende Nachricht versendet.</p>
<p>Ich würde zu letzterem Greifen.</p>
<p>Das sind evtl. für Dich noch alles böhmische Dörfer, aber leider Stoff zum Lernen und Nachschlagen für die Windows Programmierung.</p>
<p>Ich würde den Petzold durcharbeiten, dann lernst Du auch das...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1424891</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1424891</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sat, 22 Dec 2007 17:59:04 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit WM_KEYUP on Sat, 22 Dec 2007 21:27:18 GMT]]></title><description><![CDATA[<p>Ich hab mir mal deinen Acclerator Hinweis zu herzen genommen und versucht zu realisieren. Leider hänge ich schon wieder:</p>
<p>Hab einen modalen Dialog mit der Nachricht &quot;Wollen sie das Programm wirklich beenden&quot;. Und 2 Buttons Ja und Nein.</p>
<p>Dieser funkioniert auch.</p>
<p>Nur kann ich ihn nicht mit der Hotkey Taste Escape aufrufen.</p>
<p>Hier mal ein Teil der resource</p>
<pre><code class="language-cpp">IDR_EXITPROGRAM ACCELERATORS
BEGIN
    VK_ESCAPE,      ID_EXIT,                VIRTKEY, NOINVERT
END
</code></pre>
<p>Und dann wie ich den Dialog aufrufen möchte:</p>
<pre><code class="language-cpp">case WM_COMMAND:
     switch( LOWORD( wParam) )
     {
       case ID_EXIT:
         DialogBox( hInst,
                    MAKEINTRESOURCE(IDR_EXITPROGRAM),
                    hWnd,
                    (DLGPROC)ExitProc );
         break;
     }
     return 0;
</code></pre>
<p>mfg Nanobot</p>
<p>PS:<br />
Gibts den Petzold auch in einer Online Version und wieviel würde er kosten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1424964</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1424964</guid><dc:creator><![CDATA[Nanobot]]></dc:creator><pubDate>Sat, 22 Dec 2007 21:27:18 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit WM_KEYUP on Sun, 23 Dec 2007 12:05:36 GMT]]></title><description><![CDATA[<p>1. Du brauchst keinen modalen Dialog für eune Frage, denn es gibt die API Funktion MessageBox<br />
2. Wie hast Du TRanslateAccelerator in Deine Message Loop eingebaut?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1425138</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1425138</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sun, 23 Dec 2007 12:05:36 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit WM_KEYUP on Sun, 23 Dec 2007 15:08:09 GMT]]></title><description><![CDATA[<p>Ich glaube ich hab jetzt die Funktionsweise von Accelerators verstanden.<br />
Trozdem gibts noch Probleme <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="😞"
    /></p>
<p>Hier erstmal die Message Loop, die überprüft ob ein Hotkey gedrückt wurde, wenn ja dann wird die message &quot;ID_EXIT&quot; gesendet</p>
<pre><code class="language-cpp">HACCEL hAccelTable;                           
   hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)ID_STRING_ACC);                                 
   while (GetMessage(&amp;msg, NULL, 0, 0) &gt; 0)      
   {                                             
      if( !TranslateAccelerator (msg.hwnd, hAccelTable, &amp;msg) )         
      {                                          
        TranslateMessage(&amp;msg);                  
        DispatchMessage(&amp;msg);                   
      }                                          
   }
</code></pre>
<p>Und dann wird über die ID_EXIT im WM_COMMMAND der Dialog, die MessageBox oder was auch immer aufgerufen. Nur das Problem ist das nichts gesendet wird.</p>
<p>Wahrscheinlich hab ich wieder was vergessen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>mfg Nanobot</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1425206</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1425206</guid><dc:creator><![CDATA[Nanobot]]></dc:creator><pubDate>Sun, 23 Dec 2007 15:08:09 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit WM_KEYUP on Sun, 23 Dec 2007 17:12:31 GMT]]></title><description><![CDATA[<p>Bei TranslateAccelerator musst Du das Handle des äußeren Fensters angeben, das die WM_COMMAND Nachricht bekommen soll. Nicht das Handle, des Fensters, das die WM_KEY Nachricht bekommt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1425269</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1425269</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sun, 23 Dec 2007 17:12:31 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit WM_KEYUP on Sun, 23 Dec 2007 18:08:39 GMT]]></title><description><![CDATA[<p>Juhuuu ich habe es geschaft <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Vielen herzlichen Dank nochmal für deine ganzen Tipps!!<br />
Haben mir wirklcih sehr weiter geholfen <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>Was ich falsch gemacht habe:</p>
<pre><code class="language-cpp">HACCEL hAccelTable;
   hAccelTable = LoadAccelerators(hInstance,MAKEINTRESOURCE(IDR_EXITPROGRAM));
</code></pre>
<p>Da hab ich einfach die falsche Resource eingetragen.</p>
<pre><code class="language-cpp">if( !TranslateAccelerator (hWnd, hAccelTable, &amp;msg) )   
      {                                 
        TranslateMessage(&amp;msg);         
        DispatchMessage(&amp;msg);   
      }
</code></pre>
<p>Und hier habe ich, wie du schon gesagt hast, einfach das falsche Handle angegeben.</p>
<p>thx nochmal!!</p>
<p>Nanobot</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1425306</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1425306</guid><dc:creator><![CDATA[Nanobot]]></dc:creator><pubDate>Sun, 23 Dec 2007 18:08:39 GMT</pubDate></item></channel></rss>