• Advertisement

Archived

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

Error Creating Window

This topic is 5717 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I get this error: Out of this code:
  
#include <windows.h>
#include <ddraw.h>

#include "resource.h"
#define INITGUID
#define WIN32_LEAN_AND_MEAN
#define MsgB(x) MessageBox(NULL,x,"Error!",MB_OK);
#define MsgB2(x) MessageBox(NULL,x,"Yeah!",MB_OK);
#define SR(x) if(x){x->Release(); x=NULL;}
LPDIRECTDRAW7 lpDD = NULL;
LPDIRECTDRAWSURFACE7 lpDDSp=NULL;
LPDIRECTDRAWSURFACE7 lpDDSp2=NULL;
LPDIRECTDRAWCLIPPER lpDDClip=NULL;
LPDIRECTDRAWSURFACE7 lpDDSbmp=NULL;


int DrawImage();
LPDIRECTDRAWSURFACE7 BitMap();
int InitDD();
int Cleanup();

int X,Y;
BOOL gameloop=true;
HWND hWnd;

LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam){
	if(!lpDD){
		return 0L;
	}

	switch(msg){
	case WM_COMMAND:{
		switch(LOWORD(wParam)){
		case IDCLOSE:
			DestroyWindow(hWnd);
			return 0L; 
			break;
		case IDSHOW:
			DrawImage();
			break;
		}
					}
	case WM_CREATE: {		





					}break;
	case WM_PAINT:{


				  }break;

	case WM_DESTROY:{
		Cleanup();
		PostQuitMessage(0);
					 }break;
	default:	return DefWindowProc(hWnd,msg,wParam,lParam);
	
	}return 0L;
}
int Cleanup(){
	SR(lpDDSbmp)
	SR(lpDDSp)
	SR(lpDDClip)
	SR(lpDD)
return 1;}



LPDIRECTDRAWSURFACE7 BitMap()
{
	HRESULT result;
	HBITMAP hbitmap;
	BITMAP bitmap;
	HDC SrcDC;
	HDC DesDC;

	hbitmap = (HBITMAP)LoadImage(0,"back.bmp",IMAGE_BITMAP,0,0, LR_LOADFROMFILE);
	if(!hbitmap){
		MsgB("Failed To Load Bitmap Into HBITMAP")
			return 0;
	}

	if(!GetObject(hbitmap,sizeof(bitmap),&bitmap)){
		MsgB("Failed To Load HBitmap Into Bitmap")return 0;}



	DDSURFACEDESC2 ddsd2;

	ZeroMemory(&ddsd2,sizeof(ddsd2));
	ddsd2.dwSize = sizeof(DDSURFACEDESC2);
	ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT ;
	ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
	ddsd2.dwWidth = 1024;
	ddsd2.dwHeight = 768;
	result = lpDD->CreateSurface(&ddsd2,&lpDDSbmp,0);
	if(result != DD_OK){
		MsgB("Create Surface Bitmap failed") 
			DeleteObject(hbitmap);
			exit(0);}
	else{
		lpDDSbmp->GetDC(&DesDC);
		HDC SrcDC= CreateCompatibleDC(DesDC);

		SelectObject(SrcDC,hbitmap);
		BitBlt(DesDC,1024/4,768/4,bitmap.bmWidth,bitmap.bmHeight,SrcDC,0,0,SRCCOPY);
		lpDDSbmp->ReleaseDC(DesDC);
		DeleteDC(SrcDC);
	}

	DeleteObject(hbitmap);



	return lpDDSbmp;
}

int DrawImage(){
		lpDDSp->Flip(0,DDFLIP_WAIT);
		return 1;
}
	

int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPevInst, LPSTR CmdLine,int CmdShow){
	WNDCLASSEX wc;
	MSG msg;



	


	wc.cbSize = sizeof(WNDCLASSEX);
	wc.cbClsExtra = NULL;
	wc.lpszMenuName =MAKEINTRESOURCE(101);
	wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
	wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
	wc.hInstance = hInst;
	wc.lpfnWndProc=(WNDPROC) WndProc;
	wc.hCursor = LoadCursor(NULL,IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wc.cbWndExtra = sizeof(DWORD);
	wc.lpszClassName = "ClassName";
	wc.style= CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;

	if(!RegisterClassEx(&wc))
	{
	MsgB("Error Registering Class")
		return 0;
	}
		HWND hWnd; 





	HRESULT haha;
	if(!(hWnd =
		CreateWindowEx(NULL,
     "ClassName",
	 "TitleBar",
	  WS_VISIBLE |WS_POPUP,
	  0,0,
	  1024,768,
	  0,0,
	  hInst,0))) 
	{
		MsgB("Error Creating Window")
			return 0;
	}
	haha = InitDD();
	if(haha){
		MsgB2("Yeah! DD initialized!")
			}
	else{
		MsgB("Damn! DD initializing Failed!")	
			return 0;}
	haha =NULL;



	LPDIRECTDRAWSURFACE7 piet = BitMap();
	if(piet){
		MsgB2("Yeah! BMP Loaded into Surface!!")
	}else{MsgB("Damn! BMP loading Failed!")	
			return 0;}
		piet = NULL;

	ShowWindow(hWnd, CmdShow);
  UpdateWindow(hWnd);


X = 1024;
Y = 768;


    while (GetMessage(&msg, NULL, NULL, NULL))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
	
		return msg.wParam;
}
int InitDD()
{
	HRESULT ddrval;
	
ddrval = DirectDrawCreateEx(NULL,(void**)&lpDD,IID_IDirectDraw7,NULL);
	if(!ddrval == DD_OK){
		MsgB("CreateDDObj failed")return 0;}

  if(lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT)
== DDERR_INVALIDPARAMS){
		MsgB("SetCoLevel FAiled")return 0;}
	ddrval = lpDD->SetDisplayMode( 1024, 768, 32, 0, 0);

	if(ddrval != DD_OK){
		MsgB("SDM fail")
			return 0;
	}
	ddrval = lpDD->CreateClipper(0,&lpDDClip,0);	
	if(!ddrval == DD_OK){
		MsgB("create Clip fail")return 0;}



    DDSURFACEDESC2 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, &lpDDSp, NULL );
	if (ddrval!=DD_OK) {
	MsgB("createsurf fail")return 0;}

DDSCAPS2 ddscaps;
ZeroMemory(&ddscaps, sizeof(ddscaps));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
ddrval = lpDDSp->GetAttachedSurface(&ddscaps,&lpDDSp2);
	if (ddrval!=DD_OK)
	{
		MsgB("GetAttached fail")
			return 0;
	}
	return 1;
    
}
  
_________________________________________________________________________ Can someone be nice and help me on my way to be the next Hideo Kojima? Thought So...

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement