creating a device with directx C++

    g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
     g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);    

//set present parameters
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed   = TRUE;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.BackBufferWidth = d3ddm.Height;
d3dpp.BackBufferHeight = d3ddm.Width;
d3dpp.hDeviceWindow = hWnd;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.EnableAutoDepthStencil = TRUE;

                     D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &d3dDevice );

the call to createdevice fails when i change the d3dpp.windowed to FALSE. anyone got a suggestion to what my problem is???
Who is Participating?
joachimcConnect With a Mentor Commented:
ShowWindow( D3DApp::ourHWND, SW_SHOWDEFAULT );
UpdateWindow( D3DApp::ourHWND );
When you switch into a full screen the handle of the window must be a top level window.  so check the setting for the variable d3dpp.hDeviceWindow
There could be two reasons.

I think you are trying to use parameters that you don't have access to in full screen.
you can not use d3ddm.Format as your parameter when you don't have them from the windows screen.

You explicitely have to set
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.BackBufferWidth = d3ddm.Height;
d3dpp.BackBufferHeight = d3ddm.Width;

d3dpp.BackBufferFormat       = D3DFMT_A8R8G8B8; //example
d3dpp.BackBufferWidth = 800;
d3dpp.BackBufferHeight = 600;

The other reason could be that you don't have a T&L graphics card so you can create the HAL device. But that seems unlikely since you can create the device in windowed mode.
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Hi makkbru,
When you want to switch to a full screen mode, you have to fully control the primary buffer and there wouldnt be any window and hence no window handler. Please check the hDeviceWindow property.
makkbruAuthor Commented:
I checked the format and resoulution width EnumAdapterModes(), and they worked fine....(and my graphics card rules (radeon 9700 pro)so no problem with the HAL device)
... so i guess it must be the hDeviceWindow which ****s up things....

 what do you mean by "check the setting for the variable d3dpp.hDeviceWindow"? hWnd is the window handle from the main window...:
hWnd = CreateWindow("winclass1", // class
           "3d ",      // title
           WS_POPUP | WS_VISIBLE,
           0,0,        // x,y
           WINDOW_WIDTH,  // width
           WINDOW_HEIGHT, // height
           NULL,        // handle to parent
           NULL,        // handle to menu
           GetModuleHandle(NULL),// instance
do i have to send my window to the top or something like that??? if so, how ???

thanks for your help! :)
makkbruAuthor Commented:
hmmmm... it still not working
I used the CheckDeviceFormat to check if the format was ok and it was....
CheckDeviceType did of course return D3DERR_NOTAVAILABLE...

my 3dcard supports two monitors so it should have two adapters (right?)... I have deactivated the secondary adapter in devicemanager... and GetAdapterCount() returns 1. (the odd thing is that GetAdapterCount() still returned 1 when I activated the secondary adapter in devicemanager)... could this be my problem?? if so how do i fix it???...
Try creating the device with

If you want to you can take the first DX tutorials init stuff and try if that works. If it does just clip the code from that one. Doesn't seem worth the time to search through the code anymore.
makkbruAuthor Commented:
thanks guys...
I'll just wait a week or so to see if somone has a bright idea, before i give away the points.
makkbruAuthor Commented:
well, it wasnt exactly what i was looking for.... but thanks for the help
All Courses

From novice to tech pro — start learning today.