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
|
// 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;
}
|