Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Mausbewegungen abfangen + Scrollrad

Empfohlene Antworten

Veröffentlicht

Hallo Leute!

Hat jemand eine Idee wie man in einer C++ Konsolenanwendung (kein MFC, etc.) Mausbewegungen abfangen kann?

Ich möchte einen Punkt in einem drei dimensionalen Raum bewegen.

=> Mein 3 dimensionales Koordinatensystem hat die Achsen X, Y und Z.

Nun habe ich mir gedacht das die Mausbewegungen nach rechts und links die x Koordinaten ändern und die bewegungen nach oben und unten die Y Koordinate.

Das Scrollrad soll die Z Koordinaten übenehmen.

Leider habe keinen Ansatz wie ich das realisiern könnte.

Pseudocode:



if( maus wird nach oben bewegt ) { Y++; }

if( maus wird nach unten bewegt) { Y--; }


if( maus wird nach rechts bewegt ) { X++; }

if( maus wird nach ulinks bewegt  ) { X--; }


if( scrollrad wird nach oben bewegt ) { Z++; }

if( scrollrad  wird nach unten bewegt) { Z--; }



Gruß

Happyman0815

Ansatz:


#include <cstdlib>

#include <iostream>



HWND GetConsoleHwnd(void);

using namespace std;


int main(int argc, char *argv[])

{

    MSG messages; 

    HWND hwnd =  GetConsoleHwnd(); 


    while (GetMessage (&messages, NULL, 0, 0))

    {

        /* Translate virtual-key messages into character messages */

        TranslateMessage(&messages);

        /* Send message to WindowProcedure */

        DispatchMessage(&messages);

    }


    system("PAUSE");

    return EXIT_SUCCESS;

}




LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

    switch (message)                  /* handle the messages */

    {

        case WM_DESTROY:

            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */

            break;


        case WM_LBUTTONDOWN:

             std::cout << "Linksklick";

            break;


        case WM_MOUSEWHEEL:

             //MessageBox(hwnd,"Aktuelle Zeichenfarbe ist Weiss","lol",MB_OK);

             std::cout << "Scrollrad";

             return 0;

             break;

        default:                      /* for messages that we don't deal with */

            return DefWindowProc (hwnd, message, wParam, lParam);

    }


    return 0;

}




   HWND GetConsoleHwnd(void)

   {

       #define MY_BUFSIZE 1024 // Buffer size for console window titles.

       HWND hwndFound;         // This is what is returned to the caller.

       char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated

                                           // WindowTitle.

       char pszOldWindowTitle[MY_BUFSIZE]; // Contains original

                                           // WindowTitle.


       // Fetch current window title.


       GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);


       // Format a "unique" NewWindowTitle.


       wsprintf(pszNewWindowTitle,"%d/%d",

                   GetTickCount(),

                   GetCurrentProcessId());


       // Change current window title.


       SetConsoleTitle(pszNewWindowTitle);


       // Ensure window title has been updated.


       Sleep(40);


       // Look for NewWindowTitle.


       hwndFound=FindWindow(NULL, pszNewWindowTitle);


       // Restore original window title.


       SetConsoleTitle(pszOldWindowTitle);


       return(hwndFound);

   }

Leider werden die Messages nicht abgefangen :/

Es wird nur eine Message empfangen wenn ich die Fenster wechsel und dann wieder die Console in den Vordergrund hole.

Gruß

Happyman0815

  • 2 Wochen später...

Deine WindowProcedure ist in Ordnung, aber GetConsoleHwnd scheint mir nicht unbedingt koscher. Probier es mal mit einem 'echten' Window (CreateWindow).

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.