Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

20.11.2010, 17:37

Problem mit Windows Fenster

Hallo Community,
Ich bin Anfänger und gerade dabei ein Windows Fenster zu erstellen.
QUELLCODE:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#define STRICT
#include <windows.h>
#include "stdafx.h"
#include <tchar.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
const wchar_t szAppName[] = L"Ein eigenes Fenster";
const wchar_t szWinName[] =  L"Titelleiste";

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     HWND       hWnd;
   MSG      msg;
   WNDCLASS   wc;
        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(WHITE_BRUSH);
     wc.lpszClassName =  szAppName;
   wc.lpszMenuName  =  NULL;
     RegisterClass(&wc);

        hWnd = CreateWindowW(szAppName,
                    L"Titelleiste",
                    WS_OVERLAPPEDWINDOW,
                    CW_USEDEFAULT,          /* X-Position auf dem Monitor */
                    CW_USEDEFAULT,          /* Y-Position auf dem Monitor */
                    CW_USEDEFAULT,          /* Fensterbreite            */
                    CW_USEDEFAULT,          /* Fensterhoehe             */
                    NULL,
                    NULL,
                    hInstance,
                    NULL);

return 0;
}


Dabei tauchen folgende Fehler auf:

Zitat

Fehler 4 fatal error LNK1120: 1 nicht aufgelöste externe Verweise. C:\Users\XXX\Desktop\ProgrammierenLernen\ErstesProjekt\Debug\ErstesProjekt.exe

Fehler 3 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)" in Funktion "_WinMain@16". ErstesProjekt.obj

Hoffe ihr könnt mir helfen.

Tobi

GR-PA

Treue Seele

Beiträge: 326

Wohnort: Daheim

Beruf: Faulenzer

  • Private Nachricht senden

2

20.11.2010, 17:45

Die Fehlermeldung sagt doch schon alles. Die Funktion WndProc ist zwar deklariert, aber nicht definiert. Um eine Funktion verwenden zu können muss diese natürlich auch definiert sein.
Signaturen werden überbewertet

3

20.11.2010, 18:05

Was müsste ich denn ändern, damit die Funktion Definiert ist?
Entschuldige bitte, aber ich bin noch anfänger.

EDIT:
Ah habs gefunden.
Ich muss also nur #define davor setzen.
aber danke :D

EDIT 2:
Oh jetzt kommt doch wieder ein Fehler:
QUELLCODE:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#define STRICT
#include <windows.h>
#include "stdafx.h"
#include <tchar.h>

const wchar_t szAppName[] = L"Ein eigenes Fenster";
const wchar_t szWinName[] =  L"Titelleiste";
   #define   LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     HWND       hWnd;
   MSG      msg;
   WNDCLASS   wc;

        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(WHITE_BRUSH);
     wc.lpszClassName =  szAppName;
   wc.lpszMenuName  =  NULL;
     RegisterClass(&wc);

        hWnd = CreateWindowW(szAppName,
                    L"Titelleiste",
                    WS_OVERLAPPEDWINDOW,
                    CW_USEDEFAULT,          /* X-Position auf dem Monitor */
                    CW_USEDEFAULT,          /* Y-Position auf dem Monitor */
                    CW_USEDEFAULT,          /* Fensterbreite            */
                    CW_USEDEFAULT,          /* Fensterhoehe             */
                    NULL,
                    NULL,
                    hInstance,
                    NULL);

return 0;
}


FEHLER:

Zitat

Fehler 2 error C2065: 'WndProc': nichtdeklarierter Bezeichner c:\users\XXXX\desktop\programmierenlernen\erstesprojekt\erstesprojekt.cpp 17

Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »supertobs« (20.11.2010, 18:12)


4

20.11.2010, 18:37

OMG...
Lass das define oben weg.

C-/C++-Quelltext

1
2
3
4
5
6
7
8
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // <- Deklaration
...

// somewhere in your project
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM) // <- Definition
{
// Anweisungen hierher
}


Würde mal ein Buch, Tutorial oä. zu Rate ziehen.
Hab das Gefühl, Anfänger hin oder her, dass du die Grundlagen nicht intus hast.
fka tm

5

20.11.2010, 18:45

OMG bin ich blöd ;)
warum war ich nur so dumm und hab den syntax nicht erkannt?.
Naja ist ´jetzt ja auch egal, hauptsache es funktioniert.

Dankeschön

Werbeanzeige