Ich hab ein kleines Problem mit meinem Code. Der Code ist einfach aus einem Buch abgetippt und sollte normalerweise funktionieren, aber ich weiß nicht ganz was ich falsch gemacht hab.
Hier mal die Fehlermeldung:
C:\Programme\Microsoft Visual Studio\MyProjects\hw\Cpp5.cpp(96) : error C2065: 'RegisterClassEX' : nichtdeklarierter Bezeichner
Fehler beim Ausführen von cl.exe.
Und der Code dazu:
// gdi.cpp
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
HDC hdc;
RECT rect;
int x,y;
const char sztext[] = "Maus";
HANDLE font; // Benutzerdefinierte Schriftart
HANDLE brush; // Füllmuster für geometrische Figuren
HANDLE pen; // Stiftform für Linien
LOGFONT lpLFont; // Parameterstruktur der Schriftart
memset(&lpLFont,0,sizeof(lpLFont)); // Struktur mit initial.
lpLFont.lfHeight = 13; // Schrifthöhe
lpLFont.lfWidth = 3; // Breite (0=zur Höhe)
lpLFont.lfWeight = 320; // Schriftdicke
lpLFont.lfCharSet = ANSI_CHARSET; // Zeichensatz
lpLFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
// Erzeugen der GDI Objekte
font = CreateFontIndirect(&lpLFont); // Erstelle den Font
brush = CreateSolidBrush(RGB(255,0,0)); // Füllpinsel ROT
pen = CreatePen(PS_SOLID,1,RGB(0,255,0)); // Stift, 1 Pixel, GRÜN
switch(message)
{
case WM_LBUTTONDOWN: // Wenn linke Maustaste gedrückt
{
hdc = GetDC(hwnd);
x = LOWORD(lparam); // enthält x Koordinate des Klicks
y = HIWORD(lparam); // enthält y Koordinate des Klicks
TextOut(hdc, x, y, sztext, strlen(sztext));
ReleaseDC(hwnd, hdc);
return(0);
} break;
case WM_MOVE: // Wenn Fenster bewegt wird
{
hdc = GetDC(hwnd);
GetClientRect(hwnd, &rect);
SelectObject(hdc, font);
SelectObject(hdc, pen);
SetBkMode(hdc, TRANSPARENT); // hier überflüssig
SetTextColor(hdc, RGB(0,0,255)); // Textfarbe BLAU
MoveToEx(hdc, 40, 20, NULL);
LineTo(hdc, 150, 70);
FrameRect(hdc, &rect, (HBRUSH)brush);
TextOut(hdc, 100, 100, "Andere Schriftart als bei Mausklick", 35);
Arc(hdc, rect.left, rect.top, rect.right, rect.bottom, rect.left, rect.top, rect.left, rect.top);
// Aufräumen!
DeleteObject(pen);
DeleteObject(font);
ReleaseDC(hwnd, hdc);
return(0);
} break;
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
} break;
default:break;
} // switch
return (DefWindowProc(hwnd, message, wparam, lparam));
} // WindowProc
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprevinst, LPSTR lpcmdline, int ncmdshow)
{
WNDCLASSEX winclass;
HWND hwnd;
MSG message;
const char szclassname[] = "Klassenname";
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinst;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = szclassname;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
if (!(RegisterClassEX(&winclass))) // ACHTUNG: HIER SOLL DER FEHLER SEIN
return(0);
if (!(hwnd = CreateWindowEx(NULL, szclassname, "3D Spieleprogrammierung - Titelleiste", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,0,400,300,NULL,NULL,hinst,NULL)))
return(0);
ShowWindow(hwnd, ncmdshow);
UpdateWindow(hwnd);
while(GetMessage(&message,NULL,0,0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}