mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-24 17:49:52 +01:00
save window position
This commit is contained in:
parent
2e9378796a
commit
3d7f370438
92
main.c
92
main.c
@ -44,6 +44,19 @@ DWORD WINAPI render_main(void);
|
|||||||
DWORD WINAPI render_soft_main(void);
|
DWORD WINAPI render_soft_main(void);
|
||||||
DWORD WINAPI render_dummy_main(void);
|
DWORD WINAPI render_dummy_main(void);
|
||||||
|
|
||||||
|
void SaveWindowPosition()
|
||||||
|
{
|
||||||
|
if (ddraw->windowed)
|
||||||
|
{
|
||||||
|
char buf[16];
|
||||||
|
sprintf(buf, "%d", ddraw->posX);
|
||||||
|
WritePrivateProfileString("ddraw", "posX", buf, ddraw->ini_path);
|
||||||
|
|
||||||
|
sprintf(buf, "%d", ddraw->posY);
|
||||||
|
WritePrivateProfileString("ddraw", "posY", buf, ddraw->ini_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HRESULT __stdcall ddraw_Compact(IDirectDrawImpl *This)
|
HRESULT __stdcall ddraw_Compact(IDirectDrawImpl *This)
|
||||||
{
|
{
|
||||||
printf("DirectDraw::Compact(This=%p)\n", This);
|
printf("DirectDraw::Compact(This=%p)\n", This);
|
||||||
@ -221,8 +234,8 @@ HRESULT __stdcall ddraw_SetDisplayMode(IDirectDrawImpl *This, DWORD width, DWORD
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* center the window with correct dimensions */
|
/* center the window with correct dimensions */
|
||||||
int x = (This->mode.dmPelsWidth / 2) - (This->render.width / 2);
|
int x = (This->posX != -1) ? This->posX : (This->mode.dmPelsWidth / 2) - (This->render.width / 2);
|
||||||
int y = (This->mode.dmPelsHeight / 2) - (This->render.height / 2);
|
int y = (This->posY != -1) ? This->posY : (This->mode.dmPelsHeight / 2) - (This->render.height / 2);
|
||||||
RECT dst = { x, y, This->render.width+x, This->render.height+y };
|
RECT dst = { x, y, This->render.width+x, This->render.height+y };
|
||||||
AdjustWindowRect(&dst, GetWindowLong(This->hWnd, GWL_STYLE), FALSE);
|
AdjustWindowRect(&dst, GetWindowLong(This->hWnd, GWL_STYLE), FALSE);
|
||||||
SetWindowPos(This->hWnd, HWND_NOTOPMOST, dst.left, dst.top, (dst.right - dst.left), (dst.bottom - dst.top), SWP_SHOWWINDOW);
|
SetWindowPos(This->hWnd, HWND_NOTOPMOST, dst.left, dst.top, (dst.right - dst.left), (dst.bottom - dst.top), SWP_SHOWWINDOW);
|
||||||
@ -295,15 +308,35 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
switch(uMsg)
|
switch(uMsg)
|
||||||
{
|
{
|
||||||
|
case WM_MOVE:
|
||||||
|
{
|
||||||
|
if (ddraw->windowed)
|
||||||
|
{
|
||||||
|
int x = (int)(short)LOWORD(lParam);
|
||||||
|
int y = (int)(short)HIWORD(lParam);
|
||||||
|
|
||||||
|
if (x != -32000)
|
||||||
|
ddraw->posX = x; // -32000 = Exit/Minimize
|
||||||
|
|
||||||
|
if (y != -32000)
|
||||||
|
ddraw->posY = y;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Carmageddon stops the main loop when it sees these, DefWindowProc is also bad */
|
/* Carmageddon stops the main loop when it sees these, DefWindowProc is also bad */
|
||||||
case WM_WINDOWPOSCHANGING:
|
//case WM_WINDOWPOSCHANGING:
|
||||||
case WM_WINDOWPOSCHANGED:
|
//case WM_WINDOWPOSCHANGED:
|
||||||
return 0;
|
// return 0;
|
||||||
|
|
||||||
/* C&C and RA really don't want to close down */
|
/* C&C and RA really don't want to close down */
|
||||||
case WM_SYSCOMMAND:
|
case WM_SYSCOMMAND:
|
||||||
if (wParam == SC_CLOSE)
|
if (wParam == SC_CLOSE)
|
||||||
{
|
{
|
||||||
|
if (ddraw->windowed)
|
||||||
|
{
|
||||||
|
SaveWindowPosition();
|
||||||
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||||
@ -528,6 +561,11 @@ ULONG __stdcall ddraw_Release(IDirectDrawImpl *This)
|
|||||||
{
|
{
|
||||||
FreeLibrary(This->real_dll);
|
FreeLibrary(This->real_dll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ddraw->windowed)
|
||||||
|
{
|
||||||
|
SaveWindowPosition();
|
||||||
|
}
|
||||||
|
|
||||||
DeleteCriticalSection(&This->cs);
|
DeleteCriticalSection(&This->cs);
|
||||||
|
|
||||||
@ -623,14 +661,13 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
|
|
||||||
/* load configuration options from ddraw.ini */
|
/* load configuration options from ddraw.ini */
|
||||||
char cwd[MAX_PATH];
|
char cwd[MAX_PATH];
|
||||||
char ini_path[MAX_PATH];
|
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
GetCurrentDirectoryA(sizeof(cwd), cwd);
|
GetCurrentDirectoryA(sizeof(cwd), cwd);
|
||||||
snprintf(ini_path, sizeof(ini_path), "%s\\ddraw.ini", cwd);
|
snprintf(This->ini_path, sizeof(This->ini_path), "%s\\ddraw.ini", cwd);
|
||||||
|
|
||||||
if(GetFileAttributes(ini_path) == 0xFFFFFFFF)
|
if(GetFileAttributes(This->ini_path) == 0xFFFFFFFF)
|
||||||
{
|
{
|
||||||
FILE *fh = fopen(ini_path, "w");
|
FILE *fh = fopen(This->ini_path, "w");
|
||||||
fputs(
|
fputs(
|
||||||
"[ddraw]\n"
|
"[ddraw]\n"
|
||||||
"; width and height of the window, defaults to the size game requests\r\n"
|
"; width and height of the window, defaults to the size game requests\r\n"
|
||||||
@ -661,11 +698,14 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
"renderer=gdi\n"
|
"renderer=gdi\n"
|
||||||
"; force CPU0 affinity, avoids crashes with RA, *might* have a performance impact\n"
|
"; force CPU0 affinity, avoids crashes with RA, *might* have a performance impact\n"
|
||||||
"singlecpu=true\n"
|
"singlecpu=true\n"
|
||||||
|
"; Windows position, -1 = center to screen\n"
|
||||||
|
"posX=-1\n"
|
||||||
|
"posY=-1\n"
|
||||||
, fh);
|
, fh);
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPrivateProfileStringA("ddraw", "windowed", "TRUE", tmp, sizeof(tmp), ini_path);
|
GetPrivateProfileStringA("ddraw", "windowed", "TRUE", tmp, sizeof(tmp), This->ini_path);
|
||||||
if (tolower(tmp[0]) == 'n' || tolower(tmp[0]) == 'f' || tolower(tmp[0]) == 'd' || tmp[0] == '0')
|
if (tolower(tmp[0]) == 'n' || tolower(tmp[0]) == 'f' || tolower(tmp[0]) == 'd' || tmp[0] == '0')
|
||||||
{
|
{
|
||||||
This->windowed = FALSE;
|
This->windowed = FALSE;
|
||||||
@ -675,7 +715,7 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
This->windowed = TRUE;
|
This->windowed = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPrivateProfileStringA("ddraw", "border", "TRUE", tmp, sizeof(tmp), ini_path);
|
GetPrivateProfileStringA("ddraw", "border", "TRUE", tmp, sizeof(tmp), This->ini_path);
|
||||||
if (tolower(tmp[0]) == 'n' || tolower(tmp[0]) == 'f' || tolower(tmp[0]) == 'd' || tmp[0] == '0')
|
if (tolower(tmp[0]) == 'n' || tolower(tmp[0]) == 'f' || tolower(tmp[0]) == 'd' || tmp[0] == '0')
|
||||||
{
|
{
|
||||||
This->border = FALSE;
|
This->border = FALSE;
|
||||||
@ -685,7 +725,7 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
This->border = TRUE;
|
This->border = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPrivateProfileStringA("ddraw", "boxing", "FALSE", tmp, sizeof(tmp), ini_path);
|
GetPrivateProfileStringA("ddraw", "boxing", "FALSE", tmp, sizeof(tmp), This->ini_path);
|
||||||
if (tolower(tmp[0]) == 'n' || tolower(tmp[0]) == 'f' || tolower(tmp[0]) == 'd' || tmp[0] == '0')
|
if (tolower(tmp[0]) == 'n' || tolower(tmp[0]) == 'f' || tolower(tmp[0]) == 'd' || tmp[0] == '0')
|
||||||
{
|
{
|
||||||
This->boxing = FALSE;
|
This->boxing = FALSE;
|
||||||
@ -695,17 +735,19 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
This->boxing = TRUE;
|
This->boxing = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
This->render.maxfps = GetPrivateProfileIntA("ddraw", "max_fps", 120, ini_path);
|
This->render.maxfps = GetPrivateProfileIntA("ddraw", "max_fps", 120, This->ini_path);
|
||||||
This->render.width = GetPrivateProfileIntA("ddraw", "width", 0, ini_path);
|
This->render.width = GetPrivateProfileIntA("ddraw", "width", 0, This->ini_path);
|
||||||
This->render.height = GetPrivateProfileIntA("ddraw", "height", 0, ini_path);
|
This->render.height = GetPrivateProfileIntA("ddraw", "height", 0, This->ini_path);
|
||||||
|
This->posX = GetPrivateProfileIntA("ddraw", "posX", 0, This->ini_path);
|
||||||
|
This->posY = GetPrivateProfileIntA("ddraw", "posY", 0, This->ini_path);
|
||||||
|
|
||||||
This->render.bpp = GetPrivateProfileIntA("ddraw", "bpp", 32, ini_path);
|
This->render.bpp = GetPrivateProfileIntA("ddraw", "bpp", 32, This->ini_path);
|
||||||
if (This->render.bpp != 16 && This->render.bpp != 24 && This->render.bpp != 32)
|
if (This->render.bpp != 16 && This->render.bpp != 24 && This->render.bpp != 32)
|
||||||
{
|
{
|
||||||
This->render.bpp = 0;
|
This->render.bpp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPrivateProfileStringA("ddraw", "filter", tmp, tmp, sizeof(tmp), ini_path);
|
GetPrivateProfileStringA("ddraw", "filter", tmp, tmp, sizeof(tmp), This->ini_path);
|
||||||
if (tolower(tmp[0]) == 'l' || tolower(tmp[3]) == 'l')
|
if (tolower(tmp[0]) == 'l' || tolower(tmp[3]) == 'l')
|
||||||
{
|
{
|
||||||
This->render.filter = 1;
|
This->render.filter = 1;
|
||||||
@ -715,7 +757,7 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
This->render.filter = 0;
|
This->render.filter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPrivateProfileStringA("ddraw", "adjmouse", "FALSE", tmp, sizeof(tmp), ini_path);
|
GetPrivateProfileStringA("ddraw", "adjmouse", "FALSE", tmp, sizeof(tmp), This->ini_path);
|
||||||
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
||||||
{
|
{
|
||||||
This->adjmouse = TRUE;
|
This->adjmouse = TRUE;
|
||||||
@ -725,7 +767,7 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
This->adjmouse = FALSE;
|
This->adjmouse = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPrivateProfileStringA("ddraw", "mhack", "TRUE", tmp, sizeof(tmp), ini_path);
|
GetPrivateProfileStringA("ddraw", "mhack", "TRUE", tmp, sizeof(tmp), This->ini_path);
|
||||||
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
||||||
{
|
{
|
||||||
This->mhack = TRUE;
|
This->mhack = TRUE;
|
||||||
@ -735,7 +777,7 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
This->mhack = FALSE;
|
This->mhack = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPrivateProfileStringA("ddraw", "devmode", "FALSE", tmp, sizeof(tmp), ini_path);
|
GetPrivateProfileStringA("ddraw", "devmode", "FALSE", tmp, sizeof(tmp), This->ini_path);
|
||||||
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
||||||
{
|
{
|
||||||
This->devmode = TRUE;
|
This->devmode = TRUE;
|
||||||
@ -746,7 +788,7 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
This->devmode = FALSE;
|
This->devmode = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPrivateProfileStringA("ddraw", "vsync", "FALSE", tmp, sizeof(tmp), ini_path);
|
GetPrivateProfileStringA("ddraw", "vsync", "FALSE", tmp, sizeof(tmp), This->ini_path);
|
||||||
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
||||||
{
|
{
|
||||||
This->vsync = TRUE;
|
This->vsync = TRUE;
|
||||||
@ -756,10 +798,10 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
This->vsync = FALSE;
|
This->vsync = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPrivateProfileStringA("ddraw", "sensitivity", "0", tmp, sizeof(tmp), ini_path);
|
GetPrivateProfileStringA("ddraw", "sensitivity", "0", tmp, sizeof(tmp), This->ini_path);
|
||||||
This->sensitivity = strtof(tmp, NULL);
|
This->sensitivity = strtof(tmp, NULL);
|
||||||
|
|
||||||
GetPrivateProfileStringA("ddraw", "vhack", "false", tmp, sizeof(tmp), ini_path);
|
GetPrivateProfileStringA("ddraw", "vhack", "false", tmp, sizeof(tmp), This->ini_path);
|
||||||
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
||||||
{
|
{
|
||||||
This->vhack = 2;
|
This->vhack = 2;
|
||||||
@ -773,7 +815,7 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
This->vhack = 0;
|
This->vhack = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPrivateProfileStringA("ddraw", "renderer", "gdi", tmp, sizeof(tmp), ini_path);
|
GetPrivateProfileStringA("ddraw", "renderer", "gdi", tmp, sizeof(tmp), This->ini_path);
|
||||||
if(tolower(tmp[0]) == 'd' || tolower(tmp[0]) == 'd')
|
if(tolower(tmp[0]) == 'd' || tolower(tmp[0]) == 'd')
|
||||||
{
|
{
|
||||||
printf("DirectDrawCreate: Using dummy renderer\n");
|
printf("DirectDrawCreate: Using dummy renderer\n");
|
||||||
@ -790,7 +832,7 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
|
|||||||
This->renderer = render_main;
|
This->renderer = render_main;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPrivateProfileStringA("ddraw", "singlecpu", "true", tmp, sizeof(tmp), ini_path);
|
GetPrivateProfileStringA("ddraw", "singlecpu", "true", tmp, sizeof(tmp), This->ini_path);
|
||||||
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
if (tolower(tmp[0]) == 'y' || tolower(tmp[0]) == 't' || tolower(tmp[0]) == 'e' || tmp[0] == '1')
|
||||||
{
|
{
|
||||||
printf("DirectDrawCreate: Setting CPU0 affinity\n");
|
printf("DirectDrawCreate: Setting CPU0 affinity\n");
|
||||||
|
5
main.h
5
main.h
@ -83,7 +83,10 @@ typedef struct IDirectDrawImpl
|
|||||||
BOOL vhack;
|
BOOL vhack;
|
||||||
BOOL isredalert;
|
BOOL isredalert;
|
||||||
DWORD WINAPI (*renderer)(void);
|
DWORD WINAPI (*renderer)(void);
|
||||||
|
int posX;
|
||||||
|
int posY;
|
||||||
|
char ini_path[MAX_PATH];
|
||||||
|
|
||||||
} IDirectDrawImpl;
|
} IDirectDrawImpl;
|
||||||
|
|
||||||
typedef struct IDirectDrawImplVtbl IDirectDrawImplVtbl;
|
typedef struct IDirectDrawImplVtbl IDirectDrawImplVtbl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user