   Some fullscreen problems...
  I have some troubles during running my fullscreen directx program. When I run two programs at once(for example notepad), and I flip from the fullscreen program to any other program, it resizes the program''s window, or even worse the screen flips between the programs and the fullscreen apps window. I saw that other people who have problems also got answers here.So if someone could help me...// DxTutorial1.cpp : Defines the entry point for the application.//#include "stdafx.h"#include "tchar.h"#include "resource.h"// global variables.#defineFWIDTH800#define FHEIGHT600LPDIRECT3D9g_pD3D = NULL;LPDIRECT3DDEVICE9g_pD3DDev = NULL;// function prototypes.BOOLMyWindowsInit(HINSTANCE hInstance, int nCmdShow, BOOL Windowed);LRESULT CALLBACKMyWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);// DirectX global prototypes.BOOLInit(HWND hWnd, BOOL bWindowed);VOIDRender();VOIDDone(); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTRlpCmdLine, int  nCmdShow){// TODO: Place code here.MSG msg;memset(&msg, 0, sizeof(msg));HACCEL hAccel = NULL;LoadAccelerators(hInstance, (LPCTSTR)IDR_ACCEL);if(!MyWindowsInit(hInstance, nCmdShow, FALSE)){MessageBox(NULL, "MyWindowsInit Failed.", "Error", MB_OK);return 0;}while(msg.message != WM_QUIT){if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){TranslateMessage(&msg;DispatchMessage(&msg;} else {}}return (int)msg.wParam;}//////////////////////////////////////////////////////////////////////////////////BOOL MyWindowsInit(HINSTANCE hInstance, int nCmdShow ,BOOL Windowed){// Declare and clear window class.WNDCLASSEX wcex;//ZeroMemory(&wcex, sizeof(wcex));wcex.cbSize= sizeof(wcex);wcex.style= CS_HREDRAW | CS_VREDRAW;wcex.cbClsExtra= 0;wcex.cbWndExtra= 0;wcex.hInstance= hInstance;wcex.lpfnWndProc= (WNDPROC)MyWndProc;wcex.lpszClassName= _T("TUTORIAL1");wcex.lpszMenuName= (LPCTSTR)IDR_MENU;wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);wcex.hCursor= LoadCursor(hInstance, (LPCTSTR)IDC_ARROW);wcex.hIcon= LoadIcon(hInstance, (LPCTSTR)IDI_APPICON);wcex.hIconSm= LoadIcon(hInstance, (LPCTSTR)IDI_APPICON);// Register wndclass.RegisterClassEx(&wcex);// Declare and set window.HWND hWnd;memset(&hWnd, 0, sizeof(hWnd));if(Windowed){hWnd = CreateWindow(_T("TUTORIAL1"), _T("Tutorial 1 - CreateDevice"),WS_OVERLAPPEDWINDOW, 0, 0, FWIDTH, FHEIGHT, NULL, NULL, hInstance, NULL);}else{hWnd = CreateWindow(_T("TUTORIAL1"), _T("Tutorial 1 - CreateDevice"),WS_POPUP | WS_VISIBLE, 0, 0, FWIDTH, FHEIGHT, NULL, NULL, hInstance, NULL);}if(hWnd==NULL) return FALSE;ShowWindow(hWnd, nCmdShow);UpdateWindow(hWnd);// WE CALL HERE INITif(!Init(hWnd, Windowed)){MessageBox(NULL, "Init Failed.", "Error", MB_OK);return FALSE;};return TRUE;}//////////////////////////////////////////////////////////////////////////////////LRESULT CALLBACK MyWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam){// variables/*PAINTSTRUCT ps;HDC hDC;RECT rect = {0,0,150,50};*/switch (nMsg){case WM_ACTIVATEAPP:if((BOOL)wParam == TRUE){// create the new device.Init(hWnd, FALSE);}if((BOOL)wParam == FALSE){// destroy the new device.Done();}break;case WM_COMMAND:switch(LOWORD(wParam)){case IDM_EXIT:DestroyWindow(hWnd);break;default:return DefWindowProc(hWnd, nMsg, wParam, lParam);}case WM_PAINT:/*hDC = BeginPaint(hWnd, &ps);SetTextColor(hDC, 0x0ff0000);DrawText(hDC,"Paint Method",-1, &rect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);EndPaint(hWnd,&ps);*/Render();break;case WM_DESTROY:Done();PostQuitMessage(0);break;default:return DefWindowProc(hWnd, nMsg, wParam, lParam);}return 0;}////////////////////////////////////////DirectX///////////////////////////////////////////////////BOOL Init(HWND hWnd, BOOL bWindowed){// variables.D3DDISPLAYMODEd3ddm;D3DPRESENT_PARAMETERSd3dpp;HRESULT hr;memset(&d3ddm, 0, sizeof(d3ddm));memset(&d3dpp, 0, sizeof(d3dpp));// initialize the interface.if(NULL==(g_pD3D = Direct3DCreate9(D3D_SDK_VERSION))) return FALSE;if(bWindowed){// get the display mode.if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))) return FALSE;d3dpp.Windowed = bWindowed;d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;d3dpp.BackBufferFormat = d3ddm.Format;}else{// set the display mode.d3ddm.Width = FWIDTH;d3ddm.Height = FHEIGHT;d3ddm.RefreshRate = 0;d3ddm.Format = D3DFMT_R5G6B5;// set the present parametersd3dpp.Windowed = bWindowed;d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;d3dpp.BackBufferHeight = d3ddm.Height;d3dpp.BackBufferWidth = d3ddm.Width;d3dpp.BackBufferFormat = d3ddm.Format;}hr = g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd ,    D3DCREATE_SOFTWARE_VERTEXPROCESSING,   &d3dpp, &g_pD3DDev);if(FAILED(hr)){MessageBox(NULL, "Couldn''t create device", "Error", MB_OK);Done();return FALSE;}return TRUE;}VOID Render(){   if(g_pD3DDev==NULL) return;//Clear the screen    g_pD3DDev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB (0,255,0), 1.0, 0 );  g_pD3DDev->BeginScene();    g_pD3DDev->EndScene();    g_pD3DDev->Present(NULL, NULL, NULL, NULL);  return;}VOID Done(){if(g_pD3D!=NULL){g_pD3D->Release();g_pD3D = NULL;}if(g_pD3DDev!=NULL){g_pD3DDev->Release();g_pD3DDev = NULL;}return;}I don''t know whether the Direct3D has a SetCooperativeLevel function like in directdraw... 