Salut a tous....
Voila j'ai deux ptits pbs quand je lance cette appli ci-dessous... (VC++)
La première est q'une fois sur deux ma variable hWnd apres le createWindow() est NULL... Why?!
Et ensuite dans le cas ou hWnd n'est pas nulle le prog me fait un access violation sur:
ddrval = DirectDrawCreate(NULL, &pDD, NULL);
Why a nouveau?!!!
Merci de m'aider je debute la prog 3D..... Please help me!!!
A+,
H@ldwin.
//------ Include Files ------//
#include "stdafx.h"
#define INITGUID
#include <stdio.h>
#include <conio.h>
#include <ddraw.h>
#include <mmsystem.h>
//------ Window Class Information ------//
static char szClass[] = "PIT";
static char szCaption[] = "H@ldwin";
LPDIRECTDRAW lpDirectDraw;
HRESULT hRes;
LPDIRECTDRAWSURFACE lpDDSPrimaire;
LPDIRECTDRAWSURFACE surf = NULL;
LPDIRECTDRAWSURFACE lpDDSBack=NULL;
HDC hdc;
static BOOL init(HINSTANCE hInstance,int nCmdShow);
LRESULT CALLBACK
WindowProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam);
//------ Windows Message Handler ------//
LRESULT CALLBACK
WindowProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_KEYDOWN:
switch (wParam)
{
case VK_LEFT:
break;
case VK_RIGHT:
break;
case VK_ESCAPE:
DestroyWindow(hWnd);
break;
default:
break;
}
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0L;
}
static BOOL init(HINSTANCE hInstance,int nCmdShow)
{
WNDCLASS wc;
HRESULT ddrval;
LPDIRECTDRAW pDD;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof(DWORD);
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szClass;
if (!RegisterClass(&wc)) {
return FALSE;
}
// Get dimensions of display
int ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int ScreenHeight = GetSystemMetrics(SM_CYSCREEN);
// Create a window and display
HWND hWnd;
hWnd = CreateWindow(szClass, // class
szCaption, // caption
WS_VISIBLE|WS_POPUP, // style
0, // left
0, // top
ScreenWidth, // width
ScreenHeight, // height
NULL, // parent window
NULL, // menu
hInstance, // instance
NULL); // parms
if (!hWnd) {
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
ddrval = DirectDrawCreate(NULL, &pDD, NULL);
if (ddrval != DD_OK) {
return FALSE;
}
return TRUE;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
BOOL t = FALSE;
t = init(hInstance,nCmdShow);
MSG msg;
while (GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (msg.wParam);
}