1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
| #include <ddraw.h>
#include "InitClass.h"
/*Ctor qui créér une fenetre*/
TInitD3DEnv::TInitD3DEnv(HINSTANCE hInst,WNDPROC D3DWinProc,HWND idHWnd ,char *ClassName,char* Title,int Width,int Height,bool FullScreen)
{
WNDCLASSEX wc;
_Full = FullScreen;
Err = 0;
XReso = 1024;
YReso = 768;
Full_Bits = 32;
wc.hInstance = hInst;
wc.lpszClassName = ClassName;
wc.lpfnWndProc = D3DWinProc;
wc.style = CS_OWNDC;
wc.cbSize = sizeof(WNDCLASSEX);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
if(!RegisterClassEx(&wc)) Err = 1;
if(_Full)
{
idHWnd = CreateWindowEx(
0, /* Extended possibilites for variation */
ClassName, /* Classname */
Title, /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
0,
0,
GetSystemMetrics(SM_CXSCREEN), /* The programs width */
GetSystemMetrics(SM_CYSCREEN), /* and height in pixels */
NULL, /* The window is a child-window to desktop */
NULL, /* No menu */
hInst, /* Program Instance handler */
NULL /* No Window Creation data */
);
}
else
{
idHWnd = CreateWindowEx(
0, /* Extended possibilites for variation */
ClassName, /* Classname */
Title, /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
(GetSystemMetrics(SM_CYSCREEN)-Height)/2, /* Windows decides the position */
(GetSystemMetrics(SM_CXSCREEN)-Width)/2, /* where the window ends up on the screen */
Width, /* The programs width */
Height, /* and height in pixels */
NULL, /* The window is a child-window to desktop */
NULL, /* No menu */
hInst, /* Program Instance handler */
NULL /* No Window Creation data */
);
}
hWnd = idHWnd;
if (idHWnd == NULL)
Err = 0;
else
{
ShowWindow(idHWnd, 1);
InitDD();
}
}
TInitD3DEnv::~TInitD3DEnv()
{
lpDD->Release();
lpDD = NULL;
}
int TInitD3DEnv::GetLastErr()
{
return Err;
}
/*Change la résolution d'affichage*/
void TInitD3DEnv::SetDisplayRes(int XRes,int YRes, int bits)
{
ddrval=lpDD->SetDisplayMode(XRes, YRes, bits);
if(ddrval!=DD_OK)
{
lpDD->Release();
Err = 1;
}
}
/*renvoie le mode d'affichage actual (fullscreen ou window) afin de "switcher" entre les deux sur demande de l'user*/
int TInitD3DEnv::GetDisplayMode()
{
return mod;
}
/*Passe du mode fenétré en plein ecran*/
void TInitD3DEnv::SwitchWindowedToFull()
{
ddrval=lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
if(ddrval!=DD_OK)
{
lpDD->Release();
Err = 1;
}
mod = dmFULLSCREEN;
}
/*passe du mode Plein ecran au fenetré*/
void TInitD3DEnv::SwitchFullToWindowed()
{
ddrval=lpDD->SetCooperativeLevel(hWnd, DDSCL_NORMAL) ;
if(ddrval!=DD_OK)
{
lpDD->Release();
Err = 1;
}
mod = dmWINDOWED;
}
void TInitD3DEnv::InitDD()
{
ddrval=DirectDrawCreate(NULL, &lpDD, NULL);
if(_Full)
{
SwitchWindowedToFull();
SetDisplayRes(XReso,YReso,Full_Bits);
}
} |
Partager