Jump to content
  • Advertisement

Archived

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

Pipo DeClown

SetCoLevel

This topic is 5839 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

ARRRGGGh! I tried everything and it stil doesnt WORK!!!!!!
	if( lpDD->SetCooperativeLevel(g_hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN )
		== DDERR_INVALIDPARAMS)
	{
		MsgB("SetCoLevel Failed")
	return 0;
	}
 
Nothing wrong huh? WHY!!! <marquee width=100% direction=right><table nostyle="filter:glow(color=red,strength=3)"><table nostyle="filter:shadow(color=blue,direction=left)">Can someone be nice and help me on my way to be the next Hideo Kojima?</table></table></marquee>

Share this post


Link to post
Share on other sites
Advertisement
Why not?

If you expect more useful answer, provide more information. Saying "it still doesnt WORK!!!!!!" won''t get you anywhere.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Maybe your g_hWnd is invalid?

Share this post


Link to post
Share on other sites
this is the source:

    
#include <windows.h>
#include <ddraw.h>
#include <mmsystem.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;}
char* Classname = "ClassName";
char* Title = "title";
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 g_hWnd,hWnd2;


LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{

if(!lpDD)
{
return 0L;
}

switch(msg)
{
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 APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPevInst, LPSTR CmdLine, int CmdShow)
{
HRESULT ddrval;
MSG msg;

// Set up and register window class

WNDCLASSEX WndCls = { sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW, WndProc, 0L, 0L,
hInst, LoadIcon(NULL, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW),
(HBRUSH) GetStockObject(BLACK_BRUSH), NULL, Classname,
LoadIcon(NULL, IDI_APPLICATION) };

RegisterClassEx(&WndCls);

g_hWnd = CreateWindowEx( WS_EX_TOPMOST, Classname, Title, WS_POPUP | WS_VISIBLE,
0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
NULL, NULL, hInst, NULL);

UpdateWindow(g_hWnd);
g_hWnd;




// Setup DirectX

ddrval = DirectDrawCreateEx(NULL,(void**)&lpDD,IID_IDirectDraw7,NULL);
if(!ddrval == DD_OK){
MsgB("CreateDDObj failed")return 0;}

ddrval = lpDD->SetCooperativeLevel(g_hWnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT);
if(ddrval != DD_OK)
{
MsgB("SetCoLevel Failed")
return 0;
}

ddrval = lpDD->SetDisplayMode(1024,768, 32, 0, 0);
if(ddrval != DD_OK)
{
MsgB("SDM fail")
return 0;
}
//Do I have to set a Clipper anywayz?

//Cuz Sam (book) didnt when he used more then one surface

lpDD->CreateClipper(0,&lpDDClip,0);
lpDDClip->SetHWnd(0,g_hWnd);


DDSURFACEDESC2 ddsd;
DDSCAPS2 ddscaps;
ZeroMemory(&ddsd,sizeof(ddsd));
ZeroMemory(&ddscaps, sizeof(ddscaps));
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;
}

ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
ddrval = lpDDSp->GetAttachedSurface(&ddscaps,&lpDDSp2);
if (ddrval!=DD_OK)
{
MsgB("GetAttached fail")
return 0;
}

// Message Loop

while( msg.message != WM_QUIT )
{
if( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{

}
}

return msg.wParam;
}


Look at the Window Part, I really dont know whats wrong but it wont compile. But when I do DDSCL_NORMAL it does,
and then I get the "CreatSurf error".
So I exually have 2 problems. Help me....Help me....oH hElp mE....


[edited by - pipo declown on June 29, 2002 4:09:57 AM]

Share this post


Link to post
Share on other sites
Hm, well, you haven''t done lpdd->QueryInterface(), which might be the problem? Honestly, I don''t understand why you do everything you do in DirectX, but I usually have to use QueryInterface() (though I''m using DX6, not 7)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!