Fireworx Mini JLI'ler
Anmeldedatum: 16.12.2003 Beiträge: 7
Medaillen: Keine
|
Verfasst am: 16.12.2003, 16:18 Titel: Zugriffsverletzung bei DrawText |
|
|
Hi!
Immer wenn ich das DrawText-Beispiel aus Kapitel 19 ausführe, stürzt das Programm ab und das devenv sagt irgendwas von 'ner Zugriffsverletzung.
Code: | #include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
LPDIRECT3D9 lpD3D = NULL;
LPDIRECT3DDEVICE9 lpD3DDevice = NULL;
LPD3DXFONT lpD3DFont = NULL;
//Anwendungsfenster erzeugen
HWND CreateMainWindow(HINSTANCE hInstance);
//Callback-Funktion
LRESULT CALLBACK MessageHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
bool InitDirect3D(HWND hWnd);
void CleanUpDirect3D(void);
//Globale Varibale für Fensterhandle
HWND hWnd = 0;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
hWnd = CreateMainWindow(hInstance);
if(0 == hWnd)
{
MessageBox(0, "Fenster konnte nicht erzeugt werdne", "Fehler", MB_OK);
return -1;
}
if(!InitDirect3D(hWnd))
{
return -1;
}
MSG msg;
while(GetMessage(&msg, NULL, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
CleanUpDirect3D();
return 0;
}
bool InitDirect3D(HWND hWnd)
{
lpD3D = Direct3DCreate9(D3D_SDK_VERSION);
if(lpD3D == NULL)
{
return false;
}
D3DPRESENT_PARAMETERS PParams;
ZeroMemory(&PParams, sizeof(PParams));
PParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
PParams.hDeviceWindow = hWnd;
PParams.Windowed = true;
PParams.BackBufferWidth = 800;
PParams.BackBufferHeight = 600;
PParams.BackBufferFormat = D3DFMT_A8R8G8B8;
if(FAILED(lpD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &PParams, &lpD3DDevice)))
{
return false;
}
return true;
}
void CleanUpDirect3D(void)
{
if(lpD3DDevice != NULL)
{
lpD3DDevice->Release();
lpD3DDevice = NULL;
}
if(lpD3D != NULL)
{
lpD3D->Release();
lpD3D = NULL;
}
}
void CreateD3DFont(void)
{
LOGFONT LogFont = {0};
strcpy(LogFont.lfFaceName, "Arial");
D3DXCreateFontIndirect(lpD3DDevice, &LogFont, &lpD3DFont);
}
HWND CreateMainWindow(HINSTANCE hInstance)
{
WNDCLASSEX wndClass = {
sizeof(WNDCLASSEX),
CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW,
MessageHandler,
0,
0,
hInstance,
LoadIcon(NULL, IDI_WINLOGO),
LoadCursor(NULL, IDC_ARROW),
(HBRUSH)GetStockObject(WHITE_BRUSH),
NULL,
"WindowClass",
LoadIcon(NULL, IDI_WINLOGO)
};
RegisterClassEx(&wndClass);
return CreateWindowEx(NULL, "windowClass", "Ein einfaches Fenster", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, 400, 300, NULL, NULL, hInstance, NULL);
}
LRESULT CALLBACK MessageHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
D3DCOLOR ClearColor = D3DCOLOR_XRGB(0, 0, 0xFF);
D3DCOLOR TextColor = D3DCOLOR_XRGB(0xFF, 0, 0);
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;
case WM_KEYDOWN:
switch(wParam)
{
case VK_ESCAPE:
DestroyWindow(hWnd);
break;
}
break;
case WM_PAINT:
lpD3DDevice->Clear(0, 0, D3DCLEAR_TARGET, ClearColor, 0, 0);
RECT r = {100, 100, 0, 0};
lpD3DDevice->BeginScene();
lpD3DFont->DrawText("Hallo Direct3D", -1, &r, DT_CALCRECT, TextColor); //In dieser Zeile gibt's die Zugriffsverletzung
lpD3DFont->DrawText("Hallo Direct3D", -1, &r, DT_CENTER, TextColor);
lpD3DDevice->EndScene();
lpD3DDevice->Present(0,0,0,0);
break;
}
return (DefWindowProc(hwnd, msg, wParam, lParam));
} |
|
|