Archived

This topic is now archived and is closed to further replies.

DarkDragon

Please tell me what's wrong

Recommended Posts

Please help me I don''t know what''s wrong with my code, whe i run it give me an error, in debug mode a message box says "Unhandled exception" --------------------------------------------------------------- #define WIN32_LEAN_AND_MEAN #define INITGUID #include #include #include #define INIT_DXSTRUCT(dxs) { ZeroMemory(&dxs, sizeof(dxs)); dxs.dwSize = sizeof(dxs); } LPDIRECTDRAW7 ObjDD7; LPDIRECTDRAWSURFACE7 PrimSurf, BackBuffer; DDSURFACEDESC2 ddsd; HWND hWnd; LRESULT CALLBACK WindowFnc(HWND, UINT, WPARAM, LPARAM); BOOL Inicializar(int, int, int); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX WindowClass; MSG msg; WindowClass.cbClsExtra = 0; WindowClass.cbSize = sizeof(WNDCLASSEX); WindowClass.cbWndExtra = 0; WindowClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); WindowClass.hIcon = LoadIcon(hInstance, "MI_ICONO"); WindowClass.hIconSm = LoadIcon(hInstance, "MI_ICONO"); WindowClass.hInstance = hInstance; WindowClass.lpfnWndProc = (WNDPROC)WindowFnc; WindowClass.lpszClassName = "Clase de Ventana"; WindowClass.lpszMenuName = NULL; WindowClass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; if(!(RegisterClassEx(&WindowClass))) return 1; hWnd = CreateWindowEx(NULL, "Clase de Ventana", "Pinganito", WS_POPUP | WS_VISIBLE, 0, 0, 640, 480, NULL, NULL, hInstance, NULL); if(!hWnd) return 1; if(Inicializar(800, 600, 16) == FALSE) return 1; while(TRUE) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } DDBLTFX fx; INIT_DXSTRUCT(fx); fx.dwFillColor = 0; BackBuffer->Blt(NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &fx); PrimSurf->Blt(NULL, BackBuffer, NULL, DDBLT_WAIT, NULL); } return msg.wParam; } LRESULT CALLBACK WindowFnc(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch(msg) { case WM_DESTROY: PostQuitMessage(0); break; } return(DefWindowProc(hWnd, msg, wparam, lparam)); } BOOL Inicializar(int width, int height, int bpp) { if(FAILED(DirectDrawCreateEx(NULL, (void**)&ObjDD7, IID_IDirectDraw7, NULL))) { MessageBox(hWnd,"No se pudo crear DirectDraw7","Error", MB_OK | MB_ICONEXCLAMATION); return FALSE; } if(FAILED(ObjDD7->SetCooperativeLevel(hWnd,DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT))) { MessageBox(hWnd,"No se pudo Ajustar DirectDraw","Error", MB_OK | MB_ICONEXCLAMATION); return FALSE; } if(FAILED(ObjDD7->SetDisplayMode(width, height, bpp, 0, 0))) { MessageBox(hWnd,"No se pudo escoger el mode de Video","Error", MB_OK | MB_ICONEXCLAMATION); return FALSE; } return TRUE; INIT_DXSTRUCT(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.dwBackBufferCount = 1; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; if(FAILED(ObjDD7->CreateSurface(&ddsd, &PrimSurf, NULL))) { MessageBox(hWnd,"No se pudo Crear Bitmaps","Error", MB_OK | MB_ICONEXCLAMATION); return FALSE; } INIT_DXSTRUCT(ddsd); ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; if(FAILED(PrimSurf->GetAttachedSurface(&ddsd.ddsCaps, &BackBuffer))) { MessageBox(hWnd,"No se pudo crear Buffer","Error", MB_OK | MB_ICONEXCLAMATION); return FALSE; } }

Share this post


Link to post
Share on other sites
I don''t believe this is the solution but,
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;

TranslateMessage(&msg);
DispatchMessage(&msg);
}
//I once get error because i didn''t have else here
else
{
DDBLTFX fx;
INIT_DXSTRUCT(fx);
fx.dwFillColor = 0;
BackBuffer->Blt(NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &fx);

PrimSurf->Blt(NULL, BackBuffer, NULL, DDBLT_WAIT, NULL);
}

Share this post


Link to post
Share on other sites