Fehlermeldung



  • Also, wenn ich diesen Code kompiliere bekomme ich eine Fehlermeldung die ich nicht verstehe!

    #include <windows.h>
    
    LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg,
                              WPARAM wParam, LPARAM lParam );
    
    LPCSTR MainClassName = "Eingabe vom Anwender";
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       PSTR szCmdLine, int iCmdShow)
    {
       WNDCLASSEX wc;
       MSG wmsg;
       HWND hWnd;
    
       wc.cbSize  = sizeof(WNDCLASSEX);
       wc.style          = 0;
       wc.lpfnWndProc = WndProc;
       wc.cbClsExtra = 0;
       wc.cbWndExtra = 0;
       wc.hInstance = hInstance;
       wc.hIcon = LoadIcon(GetModuleHandle(NULL),
                         IDI_APPLICATION);
       wc.hCursor         = LoadCursor(NULL, IDC_CROSS);
       wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
       wc.lpszMenuName  = MainClassName;
       wc.lpszClassName = MainClassName;
       wc.hIconSm         = LoadIcon(GetModuleHandle(NULL),
                           IDI_APPLICATION);
    
       if(!RegisterClassEx(&wc))
          {
           MessageBox(NULL, "Windows Registrations Fehler", "Error!",
                      MB_ICONEXCLAMATION | MB_OK);
           return 0;
          }
    
        hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, MainClassName,
                              "Gerätekontex Beispiel",
                              WS_SYSMENU|WS_VISIBLE,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              600, 480 ,NULL,NULL,hInstance, NULL);
    
        if(hWnd == NULL)
        {
          if(MessageBox(NULL, "Fehler beim Erstellen des Fensters!",
                     "Error!", MB_ICONEXCLAMATION | MB_OK) == IDOK)
              return 0;
        }
    
    while(GetMessage(&wmsg,NULL,0,0))
       {
          TranslateMessage(&wmsg);
          DispatchMessage(&wmsg);
       }
       return wmsg.wParam;
    }
    
    LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg,
                              WPARAM wParam, LPARAM lParam )
    {
      static POINT  ptCursor;
      static HDC    hDC;
      static char   szMsg[128];
      static char   szTmp[30];
      static int x, y;
      BYTE cBuf[256];
      RECT rc;
    
      switch( uMsg )
       {
          case WM_KEYDOWN :
               {
                  GetKeyboardState(cBuf);
                  if( cBuf[VK_SHIFT]&0x80 && cBuf[VK_CONTROL]&0x80
                                          && cBuf['A']&0x80)
                       MessageBox(NULL, "Sie haben die Tasten\n"
                              "[CONTOL]+[SHIFT]+[A] gleichzeitig\n"
                                  "gedrückt",
                                  "[CONTROL] + [SHIFT] + [A]",
                                  MB_ICONINFORMATION|MB_OK
                                 |MB_DEFBUTTON1);
                  else
                  {
                    SetRect(&rc, 0, 0, 480, 20);
                    InvalidateRect( hWnd, &rc, TRUE );
                    UpdateWindow( hWnd );
                    hDC = GetDC( hWnd );
                    GetKeyNameText( lParam, szTmp, 30 );
                    wsprintf(szMsg, "Taste \"%s\" betätigt",szTmp);
                    TextOut( hDC, 10, 0, szMsg, lstrlen( szMsg ) );
                    ReleaseDC( hWnd, hDC );
                  }
               }
               break;
          case WM_KEYUP :
                switch( wParam )
                   {
                    int bAntwort;
                    case VK_ESCAPE:
                    bAntwort =
                     MessageBox(NULL,"Sie haben \"ESC\" gedrückt!\n"
                               "Programm beenden?","Abfrage",
                               MB_ICONINFORMATION | MB_OKCANCEL |
                               MB_DEFBUTTON1);
                     if(bAntwort == IDOK)
                        PostQuitMessage(0);
                     else
                        break;
                    }
               break;
          case WM_SYSCHAR :
               MessageBox(NULL, "Sie haben einen ASCII-Code für\n"
                          "eine Buchstabentaste gedrückt,\n"
                          "während die [ALT]-Taste gedrückt war",
                          "[ALT] + ASCII-Taste = WM_SYSCHAR",
                          MB_ICONINFORMATION | MB_OK |
                          MB_DEFBUTTON1);
               break;
    
          case WM_MOUSEMOVE :
                  x = LOWORD(lParam);
                  y = HIWORD(lParam);
                  hDC = GetDC( hWnd );
                  wsprintf( szMsg,"Cursor X = %04d,Y = %04d",x, y );
                  TextOut( hDC, 10, 30, szMsg, lstrlen( szMsg ) );
                  ReleaseDC( hWnd, hDC );
                  break;
         case WM_LBUTTONDOWN :
                  x = LOWORD(lParam);
                  y = HIWORD(lParam);
                  hDC = GetDC( hWnd );
                  wsprintf( szMsg,
                  "Linke Maustaste an Pos.: X = %04d, Y = %04d",x,y);
                  TextOut( hDC, 10, 60, szMsg, lstrlen( szMsg ) );
                  ReleaseDC( hWnd, hDC );
                  break;
         case WM_RBUTTONDOWN :
                  x = LOWORD(lParam);
                  y = HIWORD(lParam);
                  hDC = GetDC( hWnd );
                  wsprintf( szMsg,
                  "Rechte Maustaste an Pos.: X = %04d, Y = %04d"
                                                           ,x,y);
                  TextOut( hDC, 10, 90, szMsg, lstrlen( szMsg ) );
                  ReleaseDC( hWnd, hDC );
                  break;
          case WM_DESTROY :
                  PostQuitMessage(0);
                  break;
    
          default :
                return(DefWindowProc( hWnd, uMsg, wParam, lParam ) );
       }
    
       return( 0L );
    }
    

    Fahlermeldung:

    C:\Programme\Microsoft Visual Studio\MyProjects\shadow3\shadow3.cpp(9) : error C2065: 'uMsg' : nichtdeklarierter Bezeichner
    C:\Programme\Microsoft Visual Studio\MyProjects\shadow3\shadow3.cpp(13) : error C2065: 'wParam' : nichtdeklarierter Bezeichner
    Fehler beim Ausführen von cl.exe.

    kann mir das bitte jemand erklären!

    Mfg und Danke



  • Was ist daran unverständlich? In den Zeilen 9 und 13 (~Auf welche Stellen im Quelltext verweist denn dein Compiler?~) werden Variablennamen verwendet, die an dieser Stelle nicht bekannt sind.

    (was mir auffällt: Der switch-Block unter 'case WM_KEYUP:' sieht etwas deplaziert aus)

    PS: versuch mal eine einheitliche Einrückung hinzubekommen, das erleichtert es Anderen, deinen Quelltext zu lesen.



  • Habe deinen Quelltext gerade kopiert und im DevStudio
    ein Projekt angelegt.

    Kompiliert und funktioniert.

    Prüfe mal deine Projekteinstellugen

    Ich habe einfach ein leeres Win32 Projekt erzeugt, Quelltext
    kopiert. Fertig



  • Hab ich selbst auch schon bemerkt. Hab aus versehen ein Win-Konsolen Projekt erzeugt.

    Aber trotzdem Danke!


Anmelden zum Antworten