000
13.04.2005, 21:20 Uhr
~_radix
Gast
|
Hi Leutz,
ich hab ein Problem. Und zwar habe ich ganz "normal" mit DD ein Primary Surface erstellt und davon nen Backbuffer abgeleitet. Die einzige Möglichkeit, nun irgendetwas ins Backbuffersurface zu zeichen, geht mit GDI Funktionen - und die brauchen nen HDC zum Surface.
Nur mein Programm hängt sich immer bei <BackBufferSurface->GetDC(&hdc)> auf und ich weiß nicht warum. Hab alles 100 mal überprüft, und alles so gecodet, wie s in der MSDN steht.
Hier mal der Code....
C++: |
// ************************* // ** defines / includes ** // *************************
#define STRICT #define CName "DD_Application"
#include <windows.h> #include <ddraw.h> #include <fstream.h>
// ************************* // ** Glabals u.a. ** // *************************
LPDIRECTDRAW7 lpdd = 0; LPDIRECTDRAWSURFACE7 primsurf = 0; LPDIRECTDRAWSURFACE7 backsurf = 0;
const char SetFile[] = "settings.ini"; short WindowXSize = 0, WindowYSize = 0, WindowDepth = 0, MSecDelay = 0; short FullScreen = -1; HDC hdc = 0;
bool Keys[256];
void CleanUp(); LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
// ************************* // ** WinMain ** // *************************
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { char Buffer[30]; ifstream In; In.open(SetFile, ios.in); In >> Buffer; In >> Buffer; In >> WindowXSize; In >> Buffer; In >> WindowYSize; In >> Buffer; In >> WindowDepth; In >> Buffer; In >> FullScreen; In >> Buffer; In >> Buffer; In >> MSecDelay; In.close(); if (!WindowXSize || !WindowYSize || !WindowDepth || !MSecDelay || FullScreen == -1) { MessageBox(NULL, "KONFIGURATIONEN UNGÜLTIG!", "ERROR", MB_OK|MB_ICONERROR); return 1; } DWORD MYSCL_DISPMODE; if (FullScreen) MYSCL_DISPMODE = DDSCL_FULLSCREEN|DDSCL_EXCLUSIVE; else MYSCL_DISPMODE = DDSCL_NORMAL; WNDCLASSEX wce; wce.cbSize = sizeof(wce); wce.cbClsExtra = 0; wce.cbWndExtra = 0; wce.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wce.hCursor = NULL; ShowCursor(FALSE); wce.hIcon = LoadIcon(NULL, IDI_APPLICATION); wce.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wce.hInstance = hInstance; wce.lpfnWndProc = WndProc; wce.lpszClassName = CName; wce.lpszMenuName = NULL; wce.style = CS_HREDRAW|CS_VREDRAW; if (!RegisterClassEx(&wce)) { MessageBox(NULL, "KONNTE WINDOW NICHT REGISTRIEREN!", "ERROR", MB_OK|MB_ICONERROR); return 1; } HWND hwnd; if (!(hwnd = CreateWindowEx(NULL, CName, CName, WS_POPUP|WS_SYSMENU, 0, 0, WindowXSize, WindowYSize, NULL, NULL, hInstance, NULL))) { MessageBox(NULL, "KONNTE FENSTER NICHT ERSTELLEN!", "ERROR", MB_OK|MB_ICONERROR); return 1; }
ShowWindow(hwnd, SW_SHOW); UpdateWindow(hwnd);
// ************************* // ** InitDD ** // *************************
DDSURFACEDESC2 primdesc; DDSCAPS2 backdesc; if (DirectDrawCreateEx(NULL, (VOID**)&lpdd, IID_IDirectDraw7, NULL) != DD_OK) { MessageBox(hwnd, "INITIALISIEREN VON LPDIRECTDRAW FEHLGESCHLAGEN!", "ERROR", MB_OK|MB_ICONERROR); return 1; } if (lpdd->SetCooperativeLevel(hwnd, MYSCL_DISPMODE) != DD_OK) { MessageBox(hwnd, "KONNTE COOPERATIVELEVEL NICHT SETZEN!", "ERROR", MB_OK|MB_ICONERROR); CleanUp(); return 1; } if (MYSCL_DISPMODE == DDSCL_FULLSCREEN) if (lpdd->SetDisplayMode(WindowXSize, WindowYSize, WindowDepth, 0, 0) != DD_OK) { MessageBox(hwnd, "DISPLAYMODE NICHT UNTERSTÜTZT!", "ERROR", MB_OK|MB_ICONERROR); CleanUp(); return 1; }
ZeroMemory(&primdesc, sizeof(primdesc)); primdesc.dwSize = sizeof(primdesc); primdesc.dwFlags = DDSD_CAPS|DDSD_BACKBUFFERCOUNT; primdesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX; primdesc.dwBackBufferCount = 1; if (lpdd->CreateSurface(&primdesc, &primsurf, NULL) != DD_OK) { MessageBox(hwnd, "KONNTE SURFACE NICHT ERSTELLEN!", "ERROR", MB_OK|MB_ICONERROR); CleanUp(); return 1; }
backdesc.dwCaps = DDSCAPS_BACKBUFFER; primsurf->GetAttachedSurface(&backdesc, &backsurf);
// ************************* // ** MainLoop ** // *************************
MSG msg; short FPS = 0, FPSLen = 0; char FPSText[10]; unsigned long FPSTime; RECT rect; SetRect(&rect, 0, 0, WindowXSize - 1, WindowYSize - 1);
while (msg.message != WM_QUIT) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } if (Keys[VK_ESCAPE]) { SendMessage(hwnd, WM_DESTROY, 0, 0); continue; } if (GetTickCount() - FPSTime > 999) { FPSLen = wsprintf(FPSText, "FPS: %i", FPS); FPS = 0; FPSTime = GetTickCount(); }
backsurf->GetDC(&hdc); SetPixel(hdc, WindowXSize - 1, WindowYSize - 1, RGB(255, 0, 0)); TextOut(hdc, 0, 0, FPSText, FPSLen); backsurf->ReleaseDC(hdc); while (primsurf->Flip(NULL, DDFLIP_WAIT) != DD_OK); FPS++; }
// ************************* // ** CleanUp ** // *************************
CleanUp(); UnregisterClass(CName, hInstance); return msg.wParam; }
// ************************* // ** Some Functions ** // *************************
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0;
case WM_KEYDOWN: Keys[wp] = 1; return 0;
case WM_KEYUP: Keys[wp] = 0; return 0; } return DefWindowProc(hwnd, msg, wp, lp); }
void CleanUp() { if (backsurf) backsurf->Release(); if (primsurf) primsurf->Release(); if (lpdd) lpdd->Release(); }
|
Verbesserungsvorschläge und HILFE sehr willkommen!
MfG radix |