Archived

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

OoMMMoO

My code does nothing please help

Recommended Posts

Here is my code
    
#include<windows.h>
#include<ddraw.h>
#include<string.h>

LRESULT CALLBACK WndProc(HWND hwnd,UINT imessage,WPARAM wparam,LPARAM lparam)
{
	switch(imessage)
	{
	case WM_CLOSE:
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd,imessage,wparam,lparam);
	}
	return 0;
}

const char *Cname="Tutorial",*Wname="Tutorial";

int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE,LPSTR,int nCmdShow)
{
	LPDIRECTDRAW lpdd;
	HRESULT ddrval;
	HWND hwnd;
	MSG message;
	WNDCLASS wndclass;

	wndclass.cbClsExtra=0;
	wndclass.cbWndExtra=0;
	wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
	wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
	wndclass.hIcon=LoadIcon(hinstance,NULL);
	wndclass.lpfnWndProc=WndProc;
	wndclass.style=CS_HREDRAW/CS_VREDRAW;

	if(!RegisterClass(&wndclass))return false;

	hwnd=CreateWindow(Cname,Wname,WS_OVERLAPPEDWINDOW,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),NULL,NULL,hinstance,NULL);
	
	ShowWindow(hwnd,nCmdShow);
	while(GetMessage(&message,hwnd,0,0))
	{
		TranslateMessage(&message);
		DispatchMessage(&message);
	}
	
	ddrval=DirectDrawCreate(NULL,&lpdd,NULL);
	if(ddrval!=DD_OK)
		MessageBox(NULL,"Error creating DX!","ERROR",MB_OK);

		ddrval=lpdd->SetCooperativeLevel(hwnd,DDSCL_EXCLUSIVE/DDSCL_FULLSCREEN);
		if(ddrval!=DD_OK)
			MessageBox(NULL,"Error Setting Coop Lev","ERROR",MB_OK);
	ddrval=lpdd->SetDisplayMode(648,480,8);
	if(ddrval!=DD_OK)
		MessageBox(NULL,"Error setting mode","ERROR",MB_OK);
	
	LPDIRECTDRAWSURFACE lpddpsurface;
	DDSURFACEDESC ddsd;

ZeroMemory(&ddsd, sizeof(ddsd));

ddsd.dwSize = sizeof(ddsd);

ddsd.dwFlags = DDSD_CAPS / DDSD_BACKBUFFERCOUNT;

ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE / DDSCAPS_FLIP / DDSCAPS_COMPLEX;

ddsd.dwBackBufferCount = 1;

ddrval = lpdd->CreateSurface( &ddsd, &lpddpsurface, NULL );

if( ddrval != DD_OK )

{

// Couldn''t create surface


}


	return message.wParam;

}
    
it compiles and executes but does nothing at all isnt it supposed to make the screen go black? is my code right?

Share this post


Link to post
Share on other sites
Move all of your directx code up in front of your message handling loop. Put it between the ShowWindow () and the while (GetMessage()) and it should work. With what you''re doing now your DX code never executes until the program gets a message to quit. You should put your DX code in an initialization function that gets called after you create the window, it will help organize your code.
And no, it isn''t because you didn''t handle the WM_PAINT message. You will want to do something there though, otherwise windows will assume that you didn''t get the message and keep sending it. Just put BeginPaint and Endpaints where you would handle the WM_PAINT.
Let me know if it still won''t work.

-BacksideSnap-

Share this post


Link to post
Share on other sites