Hallo Leute,
ich versuche seit einer woche DirectX 10 zu lernen, aber ich scheitere schon beim erzeugen eines einfachen Windows.
Hier ist mein sourcecode:
Wenn ich das Programm ausführen will, dann kommt beim Aufruf von CreateWindowEx(...) die folgende Fehlermeldung:
CXX0030: Error: expression cannot be evaluated
ich versuche seit einer woche DirectX 10 zu lernen, aber ich scheitere schon beim erzeugen eines einfachen Windows.
Hier ist mein sourcecode:
C++:
#include <windows.h>
#include <WindowsX.h>
//GLOBALS
//Alias zum Fenster
HWND g_hWnd;
LPCWSTR g_CLASSNAME = TEXT("PythagorasTree");
const bool g_FULLSCREEN = false;
int g_ScreenWidth;
int g_ScreenHeight;
//Prototypes
bool AssignApplicationAndCreateWindow(HWND& hWnd, HINSTANCE hInstance);
// Unsere Callback-Funktion zum Auswerten der Fensternachrichten
LRESULT CALLBACK WndProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam);
bool FullScreenMode();
bool RunWindow();
bool ShutDownWindow(HINSTANCE& hInstance);
bool Error(LPCWSTR cmd);
//Einstiegspunkt
//hInstance: Alias zur Anwendung
//hPrevInstance: Ehemaliger Alias
//lpCmdLine: Kommandozeile
//nShowCmd: die Art, wie das Fenster gestartet werden soll
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
if(!AssignApplicationAndCreateWindow(g_hWnd, hInstance))
{
//Fehlermeldung
}
while(RunWindow())
{
//Hauptschleife
}
if(!ShutDownWindow(hInstance))
{
//Fehlermeldung
}
}
bool ShutDownWindow(HINSTANCE& hInstance)
{
if(g_FULLSCREEN)
{
ChangeDisplaySettings(NULL, 0);
}
//DestroyWindow(g_hwnd);
//g_hwnd = NULL;
UnregisterClass(TEXT("PT"), hInstance);
hInstance = NULL;
return true;
}
bool AssignApplicationAndCreateWindow(HWND& hWnd, HINSTANCE hInstance)
{
// WNDCLASS-Struktur für die Applikationsbeschreibung für Windows füllen
WNDCLASSEX wc;
int posX, posY;
posX = 0;
posY = 0;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hIconSm = wc.hIcon;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = TEXT("PT");
wc.cbSize = sizeof(WNDCLASSEX);
if(FAILED(RegisterClassEx(&wc)))
{
return Error(TEXT("Window could not be registered!"));
}
g_ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
g_ScreenHeight = GetSystemMetrics(SM_CYSCREEN);
if(g_FULLSCREEN)
{
if(!FullScreenMode())
{
//MessageBox(NULL, L"Could not Change Display Mode!", L"Fatal Error!", MB_ICONERROR);
return Error(L"Could not Change Display Mode!");
}
posX = posY = 0;
}
else
{
g_ScreenWidth = 800;
g_ScreenWidth = 600;
// Place the window in the middle of the screen.
posX = (GetSystemMetrics(SM_CXSCREEN) - g_ScreenWidth) / 2;
posY = (GetSystemMetrics(SM_CXSCREEN) - g_ScreenHeight) / 2;
}
hWnd = CreateWindow(WS_EX_APPWINDOW, g_CLASSNAME, g_CLASSNAME,
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP,
posX, posY, g_ScreenWidth, g_ScreenHeight, NULL, NULL, hInstance, NULL);
if(hWnd == NULL)
{
//Fehlermeldung
//MessageBox(NULL, L"Could not Change Display Mode!", L"Fatal Error!", MB_ICONERROR);
return Error(L"Window could not be created!");
}
ShowWindow(hWnd, NULL);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
return true;
}
bool FullScreenMode()
{
// The DEVMODE data structure contains information
// about the initialization and environment of a printer
// or a display device.
DEVMODE dmScreenSettings;
ZeroMemory(&dmScreenSettings, sizeof(DEVMODE));
//dmScreenSettings mit 0 initialisieren
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
//die Größe in Byte festlegen
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
//Die Breite und Höhe des Ausgabegeräts in pixel angeben
dmScreenSettings.dmPelsWidth = (unsigned long)g_ScreenWidth;
dmScreenSettings.dmPelsHeight = (unsigned long)g_ScreenHeight;
//Die Farbe in bits per pixel angeben
dmScreenSettings.dmBitsPerPel = 32;
dmScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
if(FAILED(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN)))
{
return false;
}
return true;
}
bool RunWindow()
{
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT)
return false;
}
return true;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if((msg == WM_DESTROY) || (msg = WM_CLOSE))
{
PostQuitMessage(0);
return 0;
}
if((msg == WM_KEYDOWN) && (wParam == VK_ESCAPE))
{
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
bool Error(LPCWSTR msg)
{
MessageBox(NULL, msg, L"Fatal Error!", MB_ICONERROR);
return false;
}
Wenn ich das Programm ausführen will, dann kommt beim Aufruf von CreateWindowEx(...) die folgende Fehlermeldung:
CXX0030: Error: expression cannot be evaluated