2 * Unit test suite for comdlg32 API functions: printer dialogs
4 * Copyright 2006-2007 Detlef Riekenberg
5 * Copyright 2013 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define WIN32_NO_STATUS
27 #include <wine/test.h>
33 //#include "winbase.h"
34 //#include "winerror.h"
43 /* ########################### */
45 extern const IID IID_IObjectWithSite
;
47 static HMODULE hcomdlg32
;
48 static HRESULT (WINAPI
* pPrintDlgExW
)(LPPRINTDLGEXW
);
50 /* ########################### */
52 static const CHAR emptyA
[] = "";
53 static const CHAR PrinterPortsA
[] = "PrinterPorts";
55 static const char *debugstr_guid(const GUID
*guid
)
59 if (!guid
) return "(null)";
60 sprintf(buf
, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
61 guid
->Data1
, guid
->Data2
, guid
->Data3
, guid
->Data4
[0],
62 guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3], guid
->Data4
[4],
63 guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
67 /* ########################### */
69 static void test_PageSetupDlgA(void)
74 pDlg
= HeapAlloc(GetProcessHeap(), 0, (sizeof(PAGESETUPDLGA
)) * 2);
77 SetLastError(0xdeadbeef);
78 res
= PageSetupDlgA(NULL
);
79 ok( !res
&& (CommDlgExtendedError() == CDERR_INITIALIZATION
),
80 "returned %u with %u and 0x%x (expected '0' and "
81 "CDERR_INITIALIZATION)\n", res
, GetLastError(), CommDlgExtendedError());
83 ZeroMemory(pDlg
, sizeof(PAGESETUPDLGA
));
84 pDlg
->lStructSize
= sizeof(PAGESETUPDLGA
) -1;
85 SetLastError(0xdeadbeef);
86 res
= PageSetupDlgA(pDlg
);
87 ok( !res
&& (CommDlgExtendedError() == CDERR_STRUCTSIZE
),
88 "returned %u with %u and 0x%x (expected '0' and "
89 "CDERR_STRUCTSIZE)\n", res
, GetLastError(), CommDlgExtendedError());
91 ZeroMemory(pDlg
, sizeof(PAGESETUPDLGA
));
92 pDlg
->lStructSize
= sizeof(PAGESETUPDLGA
) +1;
93 pDlg
->Flags
= PSD_RETURNDEFAULT
;
94 SetLastError(0xdeadbeef);
95 res
= PageSetupDlgA(pDlg
);
96 ok( !res
&& (CommDlgExtendedError() == CDERR_STRUCTSIZE
),
97 "returned %u with %u and 0x%x (expected '0' and CDERR_STRUCTSIZE)\n",
98 res
, GetLastError(), CommDlgExtendedError());
101 ZeroMemory(pDlg
, sizeof(PAGESETUPDLGA
));
102 pDlg
->lStructSize
= sizeof(PAGESETUPDLGA
);
103 pDlg
->Flags
= PSD_RETURNDEFAULT
| PSD_NOWARNING
;
104 SetLastError(0xdeadbeef);
105 res
= PageSetupDlgA(pDlg
);
106 ok( res
|| (CommDlgExtendedError() == PDERR_NODEFAULTPRN
),
107 "returned %u with %u and 0x%x (expected '!= 0' or '0' and "
108 "PDERR_NODEFAULTPRN)\n", res
, GetLastError(), CommDlgExtendedError());
110 if (!res
&& (CommDlgExtendedError() == PDERR_NODEFAULTPRN
)) {
111 skip("No printer configured.\n");
112 HeapFree(GetProcessHeap(), 0, pDlg
);
116 ok( pDlg
->hDevMode
&& pDlg
->hDevNames
,
117 "got %p and %p (expected '!= NULL' for both)\n",
118 pDlg
->hDevMode
, pDlg
->hDevNames
);
120 GlobalFree(pDlg
->hDevMode
);
121 GlobalFree(pDlg
->hDevNames
);
123 HeapFree(GetProcessHeap(), 0, pDlg
);
127 /* ########################### */
129 static UINT_PTR CALLBACK
print_hook_proc(HWND hdlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
131 if (msg
== WM_INITDIALOG
)
133 /* some driver popup a dialog and hung the test or silently limit the number of copies,
134 when trying to set more than 999 copies */
135 SetDlgItemInt(hdlg
, edt3
, 123, FALSE
);
136 PostMessage(hdlg
, WM_COMMAND
, IDOK
, FALSE
);
141 static void test_PrintDlgA(void)
143 DWORD res
, n_copies
= 0;
149 CHAR buffer
[MAX_PATH
];
153 pDlg
= HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGA
)) * 2);
157 /* will crash with unpatched wine */
158 SetLastError(0xdeadbeef);
159 res
= PrintDlgA(NULL
);
160 ok( !res
&& (CommDlgExtendedError() == CDERR_INITIALIZATION
),
161 "returned %d with 0x%x and 0x%x (expected '0' and "
162 "CDERR_INITIALIZATION)\n", res
, GetLastError(), CommDlgExtendedError());
164 ZeroMemory(pDlg
, sizeof(PRINTDLGA
));
165 pDlg
->lStructSize
= sizeof(PRINTDLGA
) - 1;
166 SetLastError(0xdeadbeef);
167 res
= PrintDlgA(pDlg
);
168 ok( !res
&& (CommDlgExtendedError() == CDERR_STRUCTSIZE
),
169 "returned %d with 0x%x and 0x%x (expected '0' and "
170 "CDERR_STRUCTSIZE)\n", res
, GetLastError(), CommDlgExtendedError());
172 ZeroMemory(pDlg
, sizeof(PRINTDLGA
));
173 pDlg
->lStructSize
= sizeof(PRINTDLGA
) + 1;
174 pDlg
->Flags
= PD_RETURNDEFAULT
;
175 SetLastError(0xdeadbeef);
176 res
= PrintDlgA(pDlg
);
177 ok( !res
&& (CommDlgExtendedError() == CDERR_STRUCTSIZE
),
178 "returned %u with %u and 0x%x (expected '0' and "
179 "CDERR_STRUCTSIZE)\n", res
, GetLastError(), CommDlgExtendedError());
182 ZeroMemory(pDlg
, sizeof(PRINTDLGA
));
183 pDlg
->lStructSize
= sizeof(PRINTDLGA
);
184 pDlg
->Flags
= PD_RETURNDEFAULT
;
185 SetLastError(0xdeadbeef);
186 res
= PrintDlgA(pDlg
);
187 ok( res
|| (CommDlgExtendedError() == PDERR_NODEFAULTPRN
),
188 "returned %d with 0x%x and 0x%x (expected '!= 0' or '0' and "
189 "PDERR_NODEFAULTPRN)\n", res
, GetLastError(), CommDlgExtendedError());
191 if (!res
&& (CommDlgExtendedError() == PDERR_NODEFAULTPRN
)) {
192 skip("No printer configured.\n");
193 HeapFree(GetProcessHeap(), 0, pDlg
);
197 ok(pDlg
->hDevNames
!= NULL
, "(expected '!= NULL')\n");
198 pDevNames
= GlobalLock(pDlg
->hDevNames
);
199 ok(pDevNames
!= NULL
, "(expected '!= NULL')\n");
202 ok(pDevNames
->wDriverOffset
, "(expected '!= 0' for wDriverOffset)\n");
203 ok(pDevNames
->wDeviceOffset
, "(expected '!= 0' for wDeviceOffset)\n");
204 ok(pDevNames
->wOutputOffset
, "(expected '!= 0' for wOutputOffset)\n");
205 ok(pDevNames
->wDefault
== DN_DEFAULTPRN
, "got 0x%x (expected DN_DEFAULTPRN)\n", pDevNames
->wDefault
);
207 driver
= (LPCSTR
)pDevNames
+ pDevNames
->wDriverOffset
;
208 device
= (LPCSTR
)pDevNames
+ pDevNames
->wDeviceOffset
;
209 port
= (LPCSTR
)pDevNames
+ pDevNames
->wOutputOffset
;
210 trace("driver '%s' device '%s' port '%s'\n", driver
, device
, port
);
212 /* The Driver Entry does not include a Path */
213 ptr
= strrchr(driver
, '\\');
214 ok( ptr
== NULL
, "got %p for '%s' (expected NULL for a simple name)\n", ptr
, driver
);
216 /* The Driver Entry does not have an extension (fixed to ".drv") */
217 ptr
= strrchr(driver
, '.');
219 ok( ptr
== NULL
, "got %p for '%s' (expected NULL for no extension)\n", ptr
, driver
);
224 SetLastError(0xdeadbeef);
225 res
= GetProfileStringA(PrinterPortsA
, device
, emptyA
, buffer
, sizeof(buffer
));
226 ptr
= strchr(buffer
, ',');
227 ok( (res
> 1) && (ptr
!= NULL
),
228 "got %u with %u and %p for '%s' (expected '>1' and '!= NULL')\n",
229 res
, GetLastError(), ptr
, buffer
);
231 if (ptr
) ptr
[0] = '\0';
232 ok( lstrcmpiA(driver
, buffer
) == 0,
233 "got driver '%s' (expected '%s')\n", driver
, buffer
);
235 n_copies
= DeviceCapabilities(device
, port
, DC_COPIES
, NULL
, NULL
);
236 ok(n_copies
> 0, "DeviceCapabilities(DC_COPIES) failed\n");
239 GlobalUnlock(pDlg
->hDevNames
);
240 GlobalFree(pDlg
->hDevMode
);
241 GlobalFree(pDlg
->hDevNames
);
243 /* if device doesn't support printing of multiple copies then
244 * an attempt to set number of copies > 1 in print dialog would
245 * cause the PrintDlg under Windows display the MessageBox and
246 * the test will hang waiting for user response.
250 ZeroMemory(pDlg
, sizeof(*pDlg
));
251 pDlg
->lStructSize
= sizeof(*pDlg
);
252 pDlg
->Flags
= PD_ENABLEPRINTHOOK
;
253 pDlg
->lpfnPrintHook
= print_hook_proc
;
254 res
= PrintDlg(pDlg
);
255 ok(res
, "PrintDlg error %#x\n", CommDlgExtendedError());
256 /* Version of Microsoft XPS Document Writer driver shipped before Win7
257 * reports that it can print multiple copies, but returns 1.
259 ok(pDlg
->nCopies
== 123 || broken(pDlg
->nCopies
== 1), "expected nCopies 123, got %d\n", pDlg
->nCopies
);
260 ok(pDlg
->hDevMode
!= 0, "hDevMode should not be 0\n");
261 dm
= GlobalLock(pDlg
->hDevMode
);
262 /* some broken drivers use always PD_USEDEVMODECOPIES */
263 ok((S1(U1(*dm
)).dmCopies
== 1) || broken(S1(U1(*dm
)).dmCopies
== 123),
264 "expected dm->dmCopies 1, got %d\n", S1(U1(*dm
)).dmCopies
);
265 GlobalUnlock(pDlg
->hDevMode
);
266 GlobalFree(pDlg
->hDevMode
);
267 GlobalFree(pDlg
->hDevNames
);
269 ZeroMemory(pDlg
, sizeof(*pDlg
));
270 pDlg
->lStructSize
= sizeof(*pDlg
);
271 pDlg
->Flags
= PD_ENABLEPRINTHOOK
| PD_USEDEVMODECOPIES
;
272 pDlg
->lpfnPrintHook
= print_hook_proc
;
273 res
= PrintDlg(pDlg
);
274 ok(res
, "PrintDlg error %#x\n", CommDlgExtendedError());
275 ok(pDlg
->nCopies
== 1, "expected nCopies 1, got %d\n", pDlg
->nCopies
);
276 ok(pDlg
->hDevMode
!= 0, "hDevMode should not be 0\n");
277 dm
= GlobalLock(pDlg
->hDevMode
);
278 ok(S1(U1(*dm
)).dmCopies
== 123, "expected dm->dmCopies 123, got %d\n", S1(U1(*dm
)).dmCopies
);
279 GlobalUnlock(pDlg
->hDevMode
);
280 GlobalFree(pDlg
->hDevMode
);
281 GlobalFree(pDlg
->hDevNames
);
284 HeapFree(GetProcessHeap(), 0, pDlg
);
287 /* ########################### */
289 static HRESULT WINAPI
callback_QueryInterface(IPrintDialogCallback
*iface
,
290 REFIID riid
, void **ppv
)
292 ok(0, "callback_QueryInterface(%s): unexpected call\n", debugstr_guid(riid
));
293 return E_NOINTERFACE
;
296 static ULONG WINAPI
callback_AddRef(IPrintDialogCallback
*iface
)
298 trace("callback_AddRef\n");
302 static ULONG WINAPI
callback_Release(IPrintDialogCallback
*iface
)
304 trace("callback_Release\n");
308 static HRESULT WINAPI
callback_InitDone(IPrintDialogCallback
*iface
)
310 trace("callback_InitDone\n");
314 static HRESULT WINAPI
callback_SelectionChange(IPrintDialogCallback
*iface
)
316 trace("callback_SelectionChange\n");
320 static HRESULT WINAPI
callback_HandleMessage(IPrintDialogCallback
*iface
,
321 HWND hdlg
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*res
)
323 trace("callback_HandleMessage %p,%04x,%lx,%lx,%p\n", hdlg
, msg
, wp
, lp
, res
);
324 /* *res = PD_RESULT_PRINT; */
328 static const IPrintDialogCallbackVtbl callback_Vtbl
=
330 callback_QueryInterface
,
334 callback_SelectionChange
,
335 callback_HandleMessage
338 static IPrintDialogCallback callback
= { &callback_Vtbl
};
340 static HRESULT WINAPI
unknown_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
342 trace("unknown_QueryInterface %s\n", debugstr_guid(riid
));
344 if (IsEqualGUID(riid
, &IID_IPrintDialogCallback
))
349 else if (IsEqualGUID(riid
, &IID_IObjectWithSite
))
352 return E_NOINTERFACE
;
355 ok(0, "unexpected IID %s\n", debugstr_guid(riid
));
357 return E_NOINTERFACE
;
360 static ULONG WINAPI
unknown_AddRef(IUnknown
*iface
)
362 trace("unknown_AddRef\n");
366 static ULONG WINAPI
unknown_Release(IUnknown
*iface
)
368 trace("unknown_Release\n");
372 static const IUnknownVtbl unknown_Vtbl
=
374 unknown_QueryInterface
,
379 static IUnknown unknown
= { &unknown_Vtbl
};
381 static void test_PrintDlgExW(void)
383 PRINTPAGERANGE pagerange
[2];
388 /* PrintDlgEx not present before w2k */
390 skip("PrintDlgExW not available\n");
394 /* Set CommDlgExtendedError != 0 */
396 SetLastError(0xdeadbeef);
397 res
= pPrintDlgExW(NULL
);
398 ok( (res
== E_INVALIDARG
),
399 "got 0x%x with %u and %u (expected 'E_INVALIDARG')\n",
400 res
, GetLastError(), CommDlgExtendedError());
403 pDlg
= HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGEXW
)) + 8);
406 /* lStructSize must be exact */
407 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
408 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
) - 1;
410 SetLastError(0xdeadbeef);
411 res
= pPrintDlgExW(pDlg
);
412 ok( (res
== E_INVALIDARG
),
413 "got 0x%x with %u and %u (expected 'E_INVALIDARG')\n",
414 res
, GetLastError(), CommDlgExtendedError());
417 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
418 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
) + 1;
420 SetLastError(0xdeadbeef);
421 res
= pPrintDlgExW(pDlg
);
422 ok( (res
== E_INVALIDARG
),
423 "got 0x%x with %u and %u (expected 'E_INVALIDARG')\n",
424 res
, GetLastError(), CommDlgExtendedError());
427 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
428 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
);
429 SetLastError(0xdeadbeef);
430 res
= pPrintDlgExW(pDlg
);
431 ok( (res
== E_HANDLE
),
432 "got 0x%x with %u and %u (expected 'E_HANDLE')\n",
433 res
, GetLastError(), CommDlgExtendedError());
435 /* nStartPage must be START_PAGE_GENERAL for the general page or a valid property sheet index */
436 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
437 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
);
438 pDlg
->hwndOwner
= GetDesktopWindow();
439 pDlg
->Flags
= PD_RETURNDEFAULT
| PD_NOWARNING
| PD_NOPAGENUMS
;
440 res
= pPrintDlgExW(pDlg
);
441 ok((res
== E_INVALIDARG
), "got 0x%x (expected 'E_INVALIDARG')\n", res
);
443 /* Use PD_NOPAGENUMS or set nMaxPageRanges and lpPageRanges */
444 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
445 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
);
446 pDlg
->hwndOwner
= GetDesktopWindow();
447 pDlg
->Flags
= PD_RETURNDEFAULT
| PD_NOWARNING
;
448 pDlg
->nStartPage
= START_PAGE_GENERAL
;
449 res
= pPrintDlgExW(pDlg
);
450 ok((res
== E_INVALIDARG
), "got 0x%x (expected 'E_INVALIDARG')\n", res
);
452 /* this is invalid: a valid lpPageRanges with 0 for nMaxPageRanges */
453 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
454 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
);
455 pDlg
->hwndOwner
= GetDesktopWindow();
456 pDlg
->Flags
= PD_RETURNDEFAULT
| PD_NOWARNING
;
457 pDlg
->lpPageRanges
= pagerange
;
458 pDlg
->nStartPage
= START_PAGE_GENERAL
;
459 res
= pPrintDlgExW(pDlg
);
460 ok((res
== E_INVALIDARG
), "got 0x%x (expected 'E_INVALIDARG')\n", res
);
462 /* this is invalid: NULL for lpPageRanges with a valid nMaxPageRanges */
463 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
464 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
);
465 pDlg
->hwndOwner
= GetDesktopWindow();
466 pDlg
->Flags
= PD_RETURNDEFAULT
| PD_NOWARNING
;
467 pDlg
->nMaxPageRanges
= 1;
468 pDlg
->nStartPage
= START_PAGE_GENERAL
;
469 res
= pPrintDlgExW(pDlg
);
470 ok((res
== E_INVALIDARG
), "got 0x%x (expected 'E_INVALIDARG')\n", res
);
472 /* this works: lpPageRanges with a valid nMaxPageRanges */
473 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
474 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
);
475 pDlg
->hwndOwner
= GetDesktopWindow();
476 pDlg
->Flags
= PD_RETURNDEFAULT
| PD_NOWARNING
;
477 pDlg
->nMaxPageRanges
= 1;
478 pDlg
->lpPageRanges
= pagerange
;
479 pDlg
->nStartPage
= START_PAGE_GENERAL
;
480 res
= pPrintDlgExW(pDlg
);
483 skip("No printer configured.\n");
484 HeapFree(GetProcessHeap(), 0, pDlg
);
488 ok(res
== S_OK
, "got 0x%x (expected S_OK)\n", res
);
490 dn
= GlobalLock(pDlg
->hDevNames
);
491 ok(dn
!= NULL
, "expected '!= NULL' for GlobalLock(%p)\n",pDlg
->hDevNames
);
494 ok(dn
->wDriverOffset
, "(expected '!= 0' for wDriverOffset)\n");
495 ok(dn
->wDeviceOffset
, "(expected '!= 0' for wDeviceOffset)\n");
496 ok(dn
->wOutputOffset
, "(expected '!= 0' for wOutputOffset)\n");
497 ok(dn
->wDefault
== DN_DEFAULTPRN
, "got 0x%x (expected DN_DEFAULTPRN)\n", dn
->wDefault
);
499 GlobalUnlock(pDlg
->hDevNames
);
501 GlobalFree(pDlg
->hDevMode
);
502 GlobalFree(pDlg
->hDevNames
);
504 /* this works also: PD_NOPAGENUMS */
505 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
506 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
);
507 pDlg
->hwndOwner
= GetDesktopWindow();
508 pDlg
->Flags
= PD_RETURNDEFAULT
| PD_NOWARNING
| PD_NOPAGENUMS
;
509 pDlg
->nStartPage
= START_PAGE_GENERAL
;
510 res
= pPrintDlgExW(pDlg
);
511 ok(res
== S_OK
, "got 0x%x (expected S_OK)\n", res
);
512 GlobalFree(pDlg
->hDevMode
);
513 GlobalFree(pDlg
->hDevNames
);
515 /* this works: PD_RETURNDC with PD_RETURNDEFAULT */
516 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
517 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
);
518 pDlg
->hwndOwner
= GetDesktopWindow();
519 pDlg
->Flags
= PD_RETURNDEFAULT
| PD_NOWARNING
| PD_NOPAGENUMS
| PD_RETURNDC
;
520 pDlg
->nStartPage
= START_PAGE_GENERAL
;
521 res
= pPrintDlgExW(pDlg
);
522 ok(res
== S_OK
, "got 0x%x (expected S_OK)\n", res
);
523 ok(pDlg
->hDC
!= NULL
, "HDC missing for PD_RETURNDC\n");
524 GlobalFree(pDlg
->hDevMode
);
525 GlobalFree(pDlg
->hDevNames
);
528 /* this works: PD_RETURNIC with PD_RETURNDEFAULT */
529 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
530 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
);
531 pDlg
->hwndOwner
= GetDesktopWindow();
532 pDlg
->Flags
= PD_RETURNDEFAULT
| PD_NOWARNING
| PD_NOPAGENUMS
| PD_RETURNIC
;
533 pDlg
->nStartPage
= START_PAGE_GENERAL
;
534 res
= pPrintDlgExW(pDlg
);
535 ok(res
== S_OK
, "got 0x%x (expected S_OK)\n", res
);
536 ok(pDlg
->hDC
!= NULL
, "HDC missing for PD_RETURNIC\n");
537 GlobalFree(pDlg
->hDevMode
);
538 GlobalFree(pDlg
->hDevNames
);
541 /* interactive PrintDlgEx tests */
543 if (!winetest_interactive
)
545 skip("interactive PrintDlgEx tests (set WINETEST_INTERACTIVE=1)\n");
549 ZeroMemory(pDlg
, sizeof(PRINTDLGEXW
));
550 pDlg
->lStructSize
= sizeof(PRINTDLGEXW
);
551 pDlg
->hwndOwner
= GetDesktopWindow();
552 pDlg
->Flags
= PD_NOPAGENUMS
| PD_RETURNIC
;
553 pDlg
->nStartPage
= START_PAGE_GENERAL
;
554 pDlg
->lpCallback
= &unknown
;
555 pDlg
->dwResultAction
= S_OK
;
556 res
= pPrintDlgExW(pDlg
);
557 ok(res
== S_OK
, "got 0x%x (expected S_OK)\n", res
);
558 ok(pDlg
->dwResultAction
== PD_RESULT_PRINT
, "expected PD_RESULT_PRINT, got %#x\n", pDlg
->dwResultAction
);
559 ok(pDlg
->hDC
!= NULL
, "HDC missing for PD_RETURNIC\n");
560 GlobalFree(pDlg
->hDevMode
);
561 GlobalFree(pDlg
->hDevNames
);
564 HeapFree(GetProcessHeap(), 0, pDlg
);
567 static BOOL abort_proc_called
= FALSE
;
568 static BOOL CALLBACK
abort_proc(HDC hdc
, int error
) { return abort_proc_called
= TRUE
; }
569 static void test_abort_proc(void)
572 RECT rect
= {0, 0, 100, 100};
573 DOCINFOA doc_info
= {0};
575 char filename
[MAX_PATH
];
578 if (!GetTempFileNameA(".", "prn", 0, filename
))
580 skip("Failed to create a temporary file name\n");
584 pd
.lStructSize
= sizeof(pd
);
585 pd
.Flags
= PD_RETURNDEFAULT
| PD_ALLPAGES
| PD_RETURNDC
| PD_PRINTTOFILE
;
592 skip("No default printer available.\n");
595 GlobalFree(pd
.hDevMode
);
596 GlobalFree(pd
.hDevNames
);
598 ok(pd
.hDC
!= NULL
, "PrintDlg didn't return a DC.\n");
599 if (!(print_dc
= pd
.hDC
))
602 ok(SetAbortProc(print_dc
, abort_proc
) > 0, "SetAbortProc failed\n");
603 ok(!abort_proc_called
, "AbortProc got called unexpectedly by SetAbortProc.\n");
604 abort_proc_called
= FALSE
;
606 doc_info
.cbSize
= sizeof(doc_info
);
607 doc_info
.lpszDocName
= "Some document";
608 doc_info
.lpszOutput
= filename
;
610 job_id
= StartDocA(print_dc
, &doc_info
);
613 GetLastError() == ERROR_SPL_NO_STARTDOC
, /* Vista can fail with this error when using the XPS driver */
614 "StartDocA failed ret %d gle %d\n", job_id
, GetLastError());
618 skip("StartDoc failed\n");
622 /* StartDoc may or may not call abort proc */
624 abort_proc_called
= FALSE
;
625 ok(StartPage(print_dc
) > 0, "StartPage failed\n");
626 ok(!abort_proc_called
, "AbortProc got called unexpectedly by StartPage.\n");
627 abort_proc_called
= FALSE
;
629 /* following functions sometimes call abort proc too */
630 ok(FillRect(print_dc
, &rect
, (HBRUSH
)(COLOR_BACKGROUND
+ 1)), "FillRect failed\n");
631 ok(EndPage(print_dc
) > 0, "EndPage failed\n");
632 ok(EndDoc(print_dc
) > 0, "EndDoc failed\n");
634 abort_proc_called
= FALSE
;
635 ok(DeleteDC(print_dc
), "DeleteDC failed\n");
636 ok(!abort_proc_called
, "AbortProc got called unexpectedly by DeleteDC.\n");
637 abort_proc_called
= FALSE
;
640 SetLastError(0xdeadbeef);
641 if(!DeleteFileA(filename
))
642 trace("Failed to delete temporary file (err = %x)\n", GetLastError());
645 /* ########################### */
649 hcomdlg32
= GetModuleHandleA("comdlg32.dll");
650 pPrintDlgExW
= (void *) GetProcAddress(hcomdlg32
, "PrintDlgExW");
652 test_PageSetupDlgA();