diff options
Diffstat (limited to 'platform/windows/gsprint')
-rw-r--r-- | platform/windows/gsprint/dllmain.cpp | 19 | ||||
-rw-r--r-- | platform/windows/gsprint/gsprint.cpp | 73 | ||||
-rw-r--r-- | platform/windows/gsprint/gsprint.h | 12 |
3 files changed, 104 insertions, 0 deletions
diff --git a/platform/windows/gsprint/dllmain.cpp b/platform/windows/gsprint/dllmain.cpp new file mode 100644 index 00000000..bfaa6519 --- /dev/null +++ b/platform/windows/gsprint/dllmain.cpp @@ -0,0 +1,19 @@ +// dllmain.cpp : Defines the entry point for the DLL application. +#include <windows.h> + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + diff --git a/platform/windows/gsprint/gsprint.cpp b/platform/windows/gsprint/gsprint.cpp new file mode 100644 index 00000000..4f4a3924 --- /dev/null +++ b/platform/windows/gsprint/gsprint.cpp @@ -0,0 +1,73 @@ +// gsprint.cpp : Defines the exported functions for the DLL application. +// +#include "gsprint.h" +#include "stdlib.h" + +#define FAIL -1 + +/* Code to handle the special device properties window as well as make sure + * that the values are maintained when we leave */ +SYMBOL_DECLSPEC int __stdcall ShowPropertiesDialog(void *hptr, void *printername, bool show_win) +{ + HWND hWnd = (HWND)hptr; + HANDLE hPrinter = NULL; + LPDEVMODE pDevMode; + DWORD dwNeeded, dwRet; + wchar_t *output = NULL; + + int lenA = lstrlenA((char*)printername); + int lenW = ::MultiByteToWideChar(CP_ACP, 0, (char*)printername, lenA, NULL, 0); + if (lenW > 0) + { + output = new wchar_t[lenW + 1]; + if (output == NULL) + return -1; + ::MultiByteToWideChar(CP_ACP, 0, (char*)printername, lenA, output, lenW); + output[lenW] = 0; + } + else + return FAIL; + + if (!OpenPrinter(output, &hPrinter, NULL)) + { + delete[] output; + return FAIL; + } + + /* First get the size needed */ + dwNeeded = DocumentProperties(hWnd, hPrinter, output, NULL, NULL, 0); + pDevMode = (LPDEVMODE)malloc(dwNeeded); + if (pDevMode == NULL) + { + delete[] output; + ClosePrinter(hPrinter); + return FAIL; + } + + /* Now actually get the DEVMODE data. DM_IN_PROMPT brings up the window. + * DM_OUT_BUFFER ensures that we get the values that have been set */ + DWORD fMode = DM_OUT_BUFFER; + if (show_win) + fMode = fMode | DM_IN_PROMPT; + + dwRet = DocumentProperties(hWnd, hPrinter, output, pDevMode, NULL, fMode); + if (dwRet != IDOK) + { + delete[] output; + ClosePrinter(hPrinter); + free(pDevMode); + return FAIL; + } + + /* This is the secret to ensure that the DEVMODE settings are saved. Fun + * finding this bit of information in the MS literature */ + PRINTER_INFO_9 new_info; + new_info.pDevMode = pDevMode; + SetPrinter(hPrinter, 9, (LPBYTE)&new_info, 0); + + /* Clean up */ + free(pDevMode); + delete[] output; + ClosePrinter(hPrinter); + return 0; +} diff --git a/platform/windows/gsprint/gsprint.h b/platform/windows/gsprint/gsprint.h new file mode 100644 index 00000000..cfc2c7b3 --- /dev/null +++ b/platform/windows/gsprint/gsprint.h @@ -0,0 +1,12 @@ +#include <windows.h> +#include <winspool.h> + +#ifdef __cplusplus +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif + +#define SYMBOL_DECLSPEC __declspec(dllexport) + +EXTERN_C SYMBOL_DECLSPEC int __stdcall ShowPropertiesDialog(void *ctx, void *printername, bool show_win); |