2006-04-13 20:47:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <ddraw.h>
|
|
|
|
|
2012-03-14 06:27:06 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#define DEFAULT_OUTPUT_FILE "enumdisplay.txt"
|
|
|
|
char *outputfile = DEFAULT_OUTPUT_FILE;
|
|
|
|
|
|
|
|
HMODULE hDDrawDLL = NULL;
|
|
|
|
LPDIRECTDRAW lpDD = NULL;
|
|
|
|
FILE *output = NULL;
|
|
|
|
|
|
|
|
void usage(void)
|
|
|
|
{
|
2012-03-14 06:25:26 +00:00
|
|
|
printf(
|
|
|
|
"enumdisplay by Jonathon Fowler (jf@jonof.id.au)\n"
|
|
|
|
"Options:\n"
|
|
|
|
" -h, -?, --help This message\n"
|
|
|
|
" -o <filename> Use different output file (default: "
|
|
|
|
DEFAULT_OUTPUT_FILE ", use - for stdout)\n"
|
|
|
|
);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dumpdevmode(DEVMODE *devmode)
|
|
|
|
{
|
2012-03-14 06:25:26 +00:00
|
|
|
fprintf(output, "\tdmFields has");
|
|
|
|
if (devmode->dmFields & DM_PELSWIDTH) fprintf(output, " DM_PELSWIDTH");
|
|
|
|
if (devmode->dmFields & DM_PELSHEIGHT) fprintf(output, " DM_PELSHEIGHT");
|
|
|
|
if (devmode->dmFields & DM_BITSPERPEL) fprintf(output, " DM_BITSPERPEL");
|
2012-03-14 06:27:06 +00:00
|
|
|
fprintf(output, "\n\tdmPelsWidth = %lu\n", devmode->dmPelsWidth);
|
|
|
|
fprintf(output, "\tdmPelsHeight = %lu\n", devmode->dmPelsHeight);
|
|
|
|
fprintf(output, "\tdmBitsPerPel = %lu\n", devmode->dmBitsPerPel);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-03-14 06:27:06 +00:00
|
|
|
HRESULT WINAPI ddenum(DDSURFACEDESC *ddsd, VOID *udata ATTRIBUTE((unused)))
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-03-14 06:25:26 +00:00
|
|
|
fprintf(output, "\tdwFlags has");
|
|
|
|
if (ddsd->dwFlags & DDSD_WIDTH) fprintf(output, " DDSD_WIDTH");
|
|
|
|
if (ddsd->dwFlags & DDSD_HEIGHT) fprintf(output, " DDSD_HEIGHT");
|
|
|
|
if (ddsd->dwFlags & DDSD_PIXELFORMAT) fprintf(output, " DDSD_PIXELFORMAT");
|
2012-03-14 06:27:06 +00:00
|
|
|
fprintf(output, "\n\tdwWidth = %lu\n", ddsd->dwWidth);
|
|
|
|
fprintf(output, "\tdwHeight = %lu\n", ddsd->dwHeight);
|
2012-03-14 06:25:26 +00:00
|
|
|
fprintf(output, "\tddpfPixelFormat.dwFlags has");
|
|
|
|
if (ddsd->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED1) fprintf(output, " DDPF_PALETTEINDEXED1");
|
|
|
|
if (ddsd->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED2) fprintf(output, " DDPF_PALETTEINDEXED2");
|
|
|
|
if (ddsd->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED4) fprintf(output, " DDPF_PALETTEINDEXED4");
|
|
|
|
if (ddsd->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) fprintf(output, " DDPF_PALETTEINDEXED8");
|
|
|
|
if (ddsd->ddpfPixelFormat.dwFlags & DDPF_RGB) fprintf(output, " DDPF_RGB");
|
2012-03-14 06:27:06 +00:00
|
|
|
fprintf(output, "\n\tddpfPixelFormat.dwRGBBitCount = %lu\n", ddsd->ddpfPixelFormat.dwRGBBitCount);
|
2012-03-14 06:25:26 +00:00
|
|
|
fprintf(output, "\n");
|
|
|
|
|
|
|
|
return(DDENUMRET_OK);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-11-06 07:49:44 +00:00
|
|
|
typedef HRESULT (WINAPI *aDirectDrawCreateType)(GUID *, LPDIRECTDRAW *, IUnknown *);
|
|
|
|
typedef HRESULT (WINAPI *aDirectDrawEnumerateType)(LPDDENUMCALLBACK, LPVOID);
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
int InitDirectDraw(void)
|
|
|
|
{
|
2012-03-14 06:25:26 +00:00
|
|
|
HRESULT result;
|
2012-11-06 07:49:44 +00:00
|
|
|
aDirectDrawCreateType aDirectDrawCreate;
|
|
|
|
aDirectDrawEnumerateType aDirectDrawEnumerate;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-03-14 06:25:26 +00:00
|
|
|
hDDrawDLL = LoadLibrary("DDRAW.DLL");
|
|
|
|
if (!hDDrawDLL) { fprintf(output, "Failed loading DDRAW.DLL\n"); return -1; }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-06 07:49:44 +00:00
|
|
|
aDirectDrawEnumerate = (aDirectDrawEnumerateType)GetProcAddress(hDDrawDLL, "DirectDrawEnumerateA");
|
2012-03-14 06:25:26 +00:00
|
|
|
if (!aDirectDrawEnumerate) { fprintf(output, "Error fetching DirectDrawEnumerate\n"); return -1; }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-06 07:49:44 +00:00
|
|
|
aDirectDrawCreate = (aDirectDrawCreateType)GetProcAddress(hDDrawDLL, "DirectDrawCreate");
|
2012-03-14 06:25:26 +00:00
|
|
|
if (!aDirectDrawCreate) { fprintf(output, "Error fetching DirectDrawCreate\n"); return -1; }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-03-14 06:25:26 +00:00
|
|
|
result = aDirectDrawCreate(NULL, &lpDD, NULL);
|
2012-03-14 06:27:06 +00:00
|
|
|
if (result != DD_OK) { fprintf(output, "DirectDrawCreate() failed (%ld)\n", result); return -1; }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-03-14 06:25:26 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UninitDirectDraw(void)
|
|
|
|
{
|
2012-03-14 06:25:26 +00:00
|
|
|
if (lpDD) IDirectDraw_Release(lpDD);
|
|
|
|
lpDD = NULL;
|
|
|
|
if (hDDrawDLL) FreeLibrary(hDDrawDLL);
|
|
|
|
hDDrawDLL = NULL;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2012-03-14 06:25:26 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
DEVMODE devmode;
|
|
|
|
HRESULT hresult;
|
|
|
|
|
|
|
|
for (i=1; i<argc; i++) {
|
|
|
|
if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-?") || !strcmp(argv[i], "--help")) {
|
|
|
|
usage();
|
|
|
|
return 0;
|
|
|
|
} else if (!strcmp(argv[i], "-o")) {
|
|
|
|
outputfile = argv[++i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(outputfile, "-")) {
|
|
|
|
output = fdopen(1, "wt");
|
|
|
|
outputfile = NULL;
|
|
|
|
} else {
|
|
|
|
output = fopen(outputfile, "wt");
|
|
|
|
if (!output) {
|
|
|
|
fprintf(stderr, "enumdisplay: failed to open %s for output\n", outputfile);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(output,
|
|
|
|
"enumdisplay results\n"
|
|
|
|
"\n"
|
|
|
|
"Display settings:\n"
|
|
|
|
);
|
|
|
|
ZeroMemory(&devmode, sizeof(devmode));
|
|
|
|
devmode.dmSize = sizeof(DEVMODE);
|
|
|
|
if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode)) {
|
|
|
|
fprintf(output, "\tEnumDisplaySettings() FAILED!\n");
|
|
|
|
} else {
|
|
|
|
dumpdevmode(&devmode);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(output,
|
|
|
|
"\n"
|
|
|
|
"All modes from EnumDisplaySettings:\n"
|
|
|
|
);
|
|
|
|
ZeroMemory(&devmode, sizeof(devmode));
|
|
|
|
devmode.dmSize = sizeof(DEVMODE);
|
|
|
|
i = 0;
|
|
|
|
while (EnumDisplaySettings(NULL, i, &devmode)) {
|
|
|
|
dumpdevmode(&devmode);
|
|
|
|
fprintf(output, "\n");
|
|
|
|
ZeroMemory(&devmode, sizeof(devmode));
|
|
|
|
devmode.dmSize = sizeof(DEVMODE);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!InitDirectDraw()) {
|
|
|
|
fprintf(output,
|
|
|
|
"\n"
|
|
|
|
"All modes from IDirectDraw::EnumDisplayModes:\n"
|
|
|
|
);
|
|
|
|
hresult = IDirectDraw_EnumDisplayModes(lpDD, 0, NULL, (LPVOID)0, ddenum);
|
|
|
|
if (hresult != DD_OK) {
|
2012-03-14 06:27:06 +00:00
|
|
|
fprintf(output, "\tIDirectDraw::EnumDisplayModes() FAILED! (%ld)\n", hresult);
|
2012-03-14 06:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
UninitDirectDraw();
|
|
|
|
|
|
|
|
if (outputfile) fclose(output);
|
|
|
|
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|