comdlg32: Remove duplicate includes.
[wine] / dlls / comdlg32 / printdlg16.c
1 /*
2  * COMMDLG - Print Dialog
3  *
4  * Copyright 1994 Martin Ayotte
5  * Copyright 1996 Albrecht Kleine
6  * Copyright 1999 Klaas van Gend
7  * Copyright 2000 Huw D M Davies
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #include <ctype.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <string.h>
29
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "wine/wingdi16.h"
36 #include "winuser.h"
37 #include "wine/winuser16.h"
38 #include "commdlg.h"
39 #include "dlgs.h"
40 #include "wine/debug.h"
41 #include "cderr.h"
42 #include "winspool.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
45
46 #include "cdlg.h"
47 #include "cdlg16.h"
48 #include "printdlg.h"
49
50 typedef struct
51 {
52     PRINT_PTRA   print32;
53     LPPRINTDLG16 lpPrintDlg16;
54 } PRINT_PTRA16;
55
56 /* Internal Functions */
57
58 static BOOL PRINTDLG_CreateDevNames16(HGLOBAL16 *hmem, const char* DeviceDriverName,
59                                       const char* DeviceName, const char* OutputPort)
60 {
61     long size;
62     char*   pDevNamesSpace;
63     char*   pTempPtr;
64     LPDEVNAMES lpDevNames;
65     char buf[260];
66     DWORD dwBufLen = sizeof(buf);
67
68     size = strlen(DeviceDriverName) + 1
69             + strlen(DeviceName) + 1
70             + strlen(OutputPort) + 1
71             + sizeof(DEVNAMES);
72
73     if(*hmem)
74         *hmem = GlobalReAlloc16(*hmem, size, GMEM_MOVEABLE);
75     else
76         *hmem = GlobalAlloc16(GMEM_MOVEABLE, size);
77     if (*hmem == 0)
78         return FALSE;
79
80     pDevNamesSpace = GlobalLock16(*hmem);
81     lpDevNames = (LPDEVNAMES) pDevNamesSpace;
82
83     pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
84     strcpy(pTempPtr, DeviceDriverName);
85     lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
86
87     pTempPtr += strlen(DeviceDriverName) + 1;
88     strcpy(pTempPtr, DeviceName);
89     lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
90
91     pTempPtr += strlen(DeviceName) + 1;
92     strcpy(pTempPtr, OutputPort);
93     lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
94
95     GetDefaultPrinterA(buf, &dwBufLen);
96     lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
97     GlobalUnlock16(*hmem);
98     return TRUE;
99 }
100
101
102 /***********************************************************************
103  *           PRINTDLG_WMInitDialog                      [internal]
104  */
105 static LRESULT PRINTDLG_WMInitDialog16(HWND hDlg, WPARAM wParam, PRINT_PTRA16* ptr16)
106 {
107     PRINT_PTRA *PrintStructures = &ptr16->print32;
108     LPPRINTDLG16 lppd = ptr16->lpPrintDlg16;
109     DEVNAMES *pdn;
110     DEVMODEA *pdm;
111     char *name = NULL;
112     UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
113
114     /* load Collate ICONs */
115     PrintStructures->hCollateIcon =
116       LoadIconA(COMDLG32_hInstance, "PD32_COLLATE");
117     PrintStructures->hNoCollateIcon =
118       LoadIconA(COMDLG32_hInstance, "PD32_NOCOLLATE");
119     if(PrintStructures->hCollateIcon == 0 ||
120        PrintStructures->hNoCollateIcon == 0) {
121         ERR("no icon in resourcefile\n");
122         COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
123         EndDialog(hDlg, FALSE);
124     }
125
126     /* load Paper Orientation ICON */
127     /* FIXME: not implemented yet */
128
129     /*
130      * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
131      * must be registered and the Help button must be shown.
132      */
133     if (lppd->Flags & PD_SHOWHELP) {
134         if((PrintStructures->HelpMessageID =
135             RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
136             COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
137             return FALSE;
138         }
139     } else
140         PrintStructures->HelpMessageID = 0;
141
142     if (!(lppd->Flags & PD_PRINTSETUP)) {
143         /* We have a print quality combo box. What shall we do? */
144         if (GetDlgItem(hDlg,cmb1)) {
145             char buf [20];
146
147             FIXME("Print quality only displaying currently.\n");
148
149             pdm = GlobalLock16(lppd->hDevMode);
150             if(pdm) {
151                 switch (pdm->u1.s1.dmPrintQuality) {
152                 case DMRES_HIGH         : strcpy(buf,"High");break;
153                 case DMRES_MEDIUM       : strcpy(buf,"Medium");break;
154                 case DMRES_LOW          : strcpy(buf,"Low");break;
155                 case DMRES_DRAFT        : strcpy(buf,"Draft");break;
156                 case 0                  : strcpy(buf,"Default");break;
157                 default                 : sprintf(buf,"%ddpi",pdm->u1.s1.dmPrintQuality);break;
158                 }
159                 GlobalUnlock16(lppd->hDevMode);
160             } else
161                 strcpy(buf,"Default");
162             SendDlgItemMessageA(hDlg,cmb1,CB_ADDSTRING,0,(LPARAM)buf);
163             SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
164             EnableWindow(GetDlgItem(hDlg,cmb1),FALSE);
165         }
166     }
167
168     /* FIXME: I allow more freedom than either Win95 or WinNT,
169      *        which do not agree to what errors should be thrown or not
170      *        in case nToPage or nFromPage is out-of-range.
171      */
172     if (lppd->nMaxPage < lppd->nMinPage)
173         lppd->nMaxPage = lppd->nMinPage;
174     if (lppd->nMinPage == lppd->nMaxPage)
175         lppd->Flags |= PD_NOPAGENUMS;
176     if (lppd->nToPage < lppd->nMinPage)
177         lppd->nToPage = lppd->nMinPage;
178     if (lppd->nToPage > lppd->nMaxPage)
179         lppd->nToPage = lppd->nMaxPage;
180     if (lppd->nFromPage < lppd->nMinPage)
181         lppd->nFromPage = lppd->nMinPage;
182     if (lppd->nFromPage > lppd->nMaxPage)
183         lppd->nFromPage = lppd->nMaxPage;
184
185     /* If the printer combo box is in the dialog, fill it */
186     if (GetDlgItem(hDlg,comboID)) {
187         /* Fill Combobox
188          */
189         pdn = GlobalLock16(lppd->hDevNames);
190         pdm = GlobalLock16(lppd->hDevMode);
191         if(pdn)
192             name = (char*)pdn + pdn->wDeviceOffset;
193         else if(pdm)
194             name = (char*)pdm->dmDeviceName;
195         PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
196         if(pdm) GlobalUnlock16(lppd->hDevMode);
197         if(pdn) GlobalUnlock16(lppd->hDevNames);
198
199         /* Now find selected printer and update rest of dlg */
200         name = HeapAlloc(GetProcessHeap(),0,256);
201         if (GetDlgItemTextA(hDlg, comboID, name, 255))
202             PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
203     } else {
204         /* else just use default printer */
205         char name[200];
206         DWORD dwBufLen = sizeof(name);
207         BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
208
209         if (ret)
210             PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
211         else
212             FIXME("No default printer found, expect problems!\n");
213     }
214     HeapFree(GetProcessHeap(),0,name);
215
216     return TRUE;
217 }
218
219 /************************************************************
220  *
221  *      PRINTDLG_Get16TemplateFrom32             [Internal]
222  *      Generates a 16 bits template from the Wine 32 bits resource
223  *
224  */
225 static HGLOBAL16 PRINTDLG_Get16TemplateFrom32(LPCSTR PrintResourceName)
226 {
227         HRSRC hResInfo;
228         HGLOBAL hDlgTmpl32;
229         LPCVOID template32;
230         DWORD size;
231         HGLOBAL16 hGlobal16;
232         LPVOID template;
233
234         if (!(hResInfo = FindResourceA(COMDLG32_hInstance,
235                PrintResourceName, (LPSTR)RT_DIALOG)))
236         {
237             COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
238             return 0;
239         }
240         if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo )) ||
241             !(template32 = LockResource( hDlgTmpl32 )))
242         {
243             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
244             return 0;
245         }
246         size = SizeofResource(COMDLG32_hInstance, hResInfo);
247         hGlobal16 = GlobalAlloc16(0, size);
248         if (!hGlobal16)
249         {
250             COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
251             ERR("alloc failure for %d bytes\n", size);
252             return 0;
253         }
254         template = GlobalLock16(hGlobal16);
255         if (!template)
256         {
257             COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
258             ERR("global lock failure for %x handle\n", hGlobal16);
259             GlobalFree16(hGlobal16);
260             return 0;
261         }
262         ConvertDialog32To16(template32, size, template);
263         GlobalUnlock16(hGlobal16);
264         return hGlobal16;
265 }
266
267 static BOOL PRINTDLG_CreateDC16(LPPRINTDLG16 lppd)
268 {
269     DEVNAMES *pdn = GlobalLock16(lppd->hDevNames);
270     DEVMODEA *pdm = GlobalLock16(lppd->hDevMode);
271
272     if(lppd->Flags & PD_RETURNDC) {
273         lppd->hDC = HDC_16(CreateDCA((char*)pdn + pdn->wDriverOffset,
274                               (char*)pdn + pdn->wDeviceOffset,
275                               (char*)pdn + pdn->wOutputOffset,
276                               pdm ));
277     } else if(lppd->Flags & PD_RETURNIC) {
278         lppd->hDC = HDC_16(CreateICA((char*)pdn + pdn->wDriverOffset,
279                               (char*)pdn + pdn->wDeviceOffset,
280                               (char*)pdn + pdn->wOutputOffset,
281                               pdm ));
282     }
283     GlobalUnlock16(lppd->hDevNames);
284     GlobalUnlock16(lppd->hDevMode);
285     return lppd->hDC ? TRUE : FALSE;
286 }
287
288 /************************************************************
289  *
290  *      PRINTDLG_GetDlgTemplate
291  *
292  */
293 static HGLOBAL16 PRINTDLG_GetDlgTemplate16(const PRINTDLG16 *lppd)
294 {
295     HGLOBAL16 hDlgTmpl, hResInfo;
296
297     if (lppd->Flags & PD_PRINTSETUP) {
298         if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
299             hDlgTmpl = lppd->hSetupTemplate;
300         } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
301             hResInfo = FindResource16(lppd->hInstance,
302                                      MapSL(lppd->lpSetupTemplateName), (LPSTR)RT_DIALOG);
303             hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
304         } else {
305             hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32_SETUP");
306         }
307     } else {
308         if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
309             hDlgTmpl = lppd->hPrintTemplate;
310         } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
311             hResInfo = FindResource16(lppd->hInstance,
312                                      MapSL(lppd->lpPrintTemplateName),
313                                      (LPSTR)RT_DIALOG);
314             hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
315         } else {
316             hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32");
317         }
318     }
319     return hDlgTmpl;
320 }
321
322 /**********************************************************************
323  *
324  *      16 bit commdlg
325  */
326
327 /***********************************************************************
328  *           PrintDlg   (COMMDLG.20)
329  *
330  *  Displays the PRINT dialog box, which enables the user to specify
331  *  specific properties of the print job.
332  *
333  * RETURNS
334  *  nonzero if the user pressed the OK button
335  *  zero    if the user cancelled the window or an error occurred
336  *
337  * BUGS
338  *  * calls up to the 32-bit versions of the Dialogs, which look different
339  *  * Customizing is *not* implemented.
340  */
341
342 BOOL16 WINAPI PrintDlg16(
343               LPPRINTDLG16 lppd /* [in/out] ptr to PRINTDLG struct */
344 ) {
345     BOOL      bRet = FALSE;
346     LPVOID   ptr;
347     HINSTANCE16 hInst = GetWindowLongPtrW( HWND_32(lppd->hwndOwner), GWLP_HINSTANCE );
348
349     if(TRACE_ON(commdlg)) {
350         char flagstr[1000] = "";
351         const struct pd_flags *pflag = pd_flags;
352         for( ; pflag->name; pflag++) {
353             if(lppd->Flags & pflag->flag)
354                 strcat(flagstr, pflag->name);
355         }
356         TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
357               "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
358               "flags %08x (%s)\n",
359               lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
360               lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
361               lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
362     }
363
364     if(lppd->lStructSize != sizeof(PRINTDLG16)) {
365         ERR("structure size %d\n",lppd->lStructSize);
366         COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
367         return FALSE;
368     }
369
370     if(lppd->Flags & PD_RETURNDEFAULT) {
371         PRINTER_INFO_2A *pbuf;
372         DRIVER_INFO_3A  *dbuf;
373         HANDLE hprn;
374         DWORD needed;
375
376         if(lppd->hDevMode || lppd->hDevNames) {
377             WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
378             COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
379             return FALSE;
380         }
381         if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
382             WARN("Can't find default printer\n");
383             COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
384             return FALSE;
385         }
386
387         GetPrinterA(hprn, 2, NULL, 0, &needed);
388         pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
389         GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
390         GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
391         dbuf = HeapAlloc(GetProcessHeap(),0,needed);
392         if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
393             ERR("GetPrinterDriverA failed for %s, le %d, fix your config!\n",
394                 pbuf->pPrinterName,GetLastError());
395             HeapFree(GetProcessHeap(), 0, dbuf);
396             HeapFree(GetProcessHeap(), 0, pbuf);
397             COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
398             return FALSE;
399         }
400         ClosePrinter(hprn);
401         PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
402                                 dbuf->pDriverPath,
403                                 pbuf->pPrinterName,
404                                 pbuf->pPortName);
405         lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,pbuf->pDevMode->dmSize+
406                                      pbuf->pDevMode->dmDriverExtra);
407         ptr = GlobalLock16(lppd->hDevMode);
408         memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
409                pbuf->pDevMode->dmDriverExtra);
410         GlobalUnlock16(lppd->hDevMode);
411         HeapFree(GetProcessHeap(), 0, pbuf);
412         HeapFree(GetProcessHeap(), 0, dbuf);
413         bRet = TRUE;
414     } else {
415         HGLOBAL16 hDlgTmpl;
416         PRINT_PTRA *PrintStructures;
417         PRINT_PTRA16 *ptr16;
418
419     /* load Dialog resources,
420      * depending on Flags indicates Print32 or Print32_setup dialog
421      */
422         hDlgTmpl = PRINTDLG_GetDlgTemplate16(lppd);
423         if (!hDlgTmpl) {
424             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
425             return FALSE;
426         }
427         ptr16 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PRINT_PTRA16));
428         ptr16->lpPrintDlg16 = lppd;
429         PrintStructures = &ptr16->print32;
430         PrintStructures->lpPrintDlg = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(PRINTDLGA));
431 #define CVAL(x) PrintStructures->lpPrintDlg->x = lppd->x;
432 #define MVAL(x) PrintStructures->lpPrintDlg->x = MapSL(lppd->x);
433         CVAL(Flags);
434         PrintStructures->lpPrintDlg->hwndOwner = HWND_32(lppd->hwndOwner);
435         PrintStructures->lpPrintDlg->hDC = HDC_32(lppd->hDC);
436         CVAL(nFromPage);CVAL(nToPage);CVAL(nMinPage);CVAL(nMaxPage);
437         CVAL(nCopies);
438         PrintStructures->lpPrintDlg->hInstance = HINSTANCE_32(lppd->hInstance);
439         CVAL(lCustData);
440         MVAL(lpPrintTemplateName);MVAL(lpSetupTemplateName);
441         /* Don't copy rest, it is 16 bit specific */
442 #undef MVAL
443 #undef CVAL
444
445         PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(),0,sizeof(DEVMODEA));
446
447         /* and create & process the dialog .
448          * -1 is failure, 0 is broken hwnd, everything else is ok.
449          */
450         bRet =  (0<DialogBoxIndirectParam16(
451                  hInst, hDlgTmpl, lppd->hwndOwner,
452                  (DLGPROC16)GetProcAddress16(GetModuleHandle16("COMMDLG"),(LPCSTR)21),
453                  (LPARAM)PrintStructures
454                 )
455         );
456         if (!PrintStructures->lpPrinterInfo) bRet = FALSE;
457         if(bRet) {
458             DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
459             PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
460             DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
461
462             if (lppd->hDevMode == 0) {
463                 TRACE(" No hDevMode yet... Need to create my own\n");
464                 lppd->hDevMode = GlobalAlloc16(GMEM_MOVEABLE,
465                                         lpdm->dmSize + lpdm->dmDriverExtra);
466             } else {
467                 WORD locks;
468                 if((locks = (GlobalFlags16(lppd->hDevMode)&GMEM_LOCKCOUNT))) {
469                     WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
470                     while(locks--) {
471                         GlobalUnlock16(lppd->hDevMode);
472                         TRACE("Now got %d locks\n", locks);
473                     }
474                 }
475                 lppd->hDevMode = GlobalReAlloc16(lppd->hDevMode,
476                                                lpdm->dmSize + lpdm->dmDriverExtra,
477                                                GMEM_MOVEABLE);
478             }
479             lpdmReturn = GlobalLock16(lppd->hDevMode);
480             memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
481
482             if (lppd->hDevNames != 0) {
483                 WORD locks;
484                 if((locks = (GlobalFlags16(lppd->hDevNames)&GMEM_LOCKCOUNT))) {
485                     WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
486                     while(locks--)
487                         GlobalUnlock16(lppd->hDevNames);
488                 }
489             }
490             PRINTDLG_CreateDevNames16(&(lppd->hDevNames),
491                     di->pDriverPath,
492                     pi->pPrinterName,
493                     pi->pPortName
494             );
495             GlobalUnlock16(lppd->hDevMode);
496             /* Copy back the [out] integer parameters */
497 #define CVAL(x) lppd->x = PrintStructures->lpPrintDlg->x;
498             CVAL(Flags);
499             CVAL(nFromPage);
500             CVAL(nToPage);
501             CVAL(nCopies);
502 #undef CVAL
503
504         }
505         if (!(lppd->Flags & (PD_ENABLESETUPTEMPLATEHANDLE | PD_ENABLESETUPTEMPLATE)))
506             GlobalFree16(hDlgTmpl); /* created from the 32 bits resource */
507         HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
508         HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
509         HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
510         HeapFree(GetProcessHeap(), 0, ptr16);
511     }
512     if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
513         bRet = PRINTDLG_CreateDC16(lppd);
514
515     TRACE("exit! (%d)\n", bRet);
516     return bRet;
517 }
518
519 /***********************************************************************
520  *           PrintDlgProc   (COMMDLG.21)
521  */
522 BOOL16 CALLBACK PrintDlgProc16(HWND16 hDlg16, UINT16 uMsg, WPARAM16 wParam,
523                             LPARAM lParam)
524 {
525     HWND hDlg = HWND_32(hDlg16);
526     PRINT_PTRA16 *PrintStructures;
527     BOOL16 res = FALSE;
528
529     if (uMsg!=WM_INITDIALOG) {
530         PrintStructures = (PRINT_PTRA16*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
531         if (!PrintStructures)
532             return FALSE;
533     } else {
534         PrintStructures = (PRINT_PTRA16*) lParam;
535         SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
536         res = PRINTDLG_WMInitDialog16(hDlg, wParam, PrintStructures);
537
538         if(PrintStructures->lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
539             res = CallWindowProc16(
540                 (WNDPROC16)PrintStructures->lpPrintDlg16->lpfnPrintHook,
541                 hDlg16, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg16
542             );
543         }
544         return res;
545     }
546
547     if(PrintStructures->lpPrintDlg16->Flags & PD_ENABLEPRINTHOOK) {
548         res = CallWindowProc16(
549                 (WNDPROC16)PrintStructures->lpPrintDlg16->lpfnPrintHook,
550                 hDlg16,uMsg, wParam, lParam
551         );
552         if(LOWORD(res)) return res;
553     }
554
555     switch (uMsg) {
556     case WM_COMMAND: {
557          /* We need to map those for the 32bit window procedure, compare
558           * with 32Ato16 mapper in winproc.c
559           */
560         return PRINTDLG_WMCommandA(
561                 hDlg,
562                 MAKEWPARAM(wParam,HIWORD(lParam)),
563                 LOWORD(lParam),
564                 &PrintStructures->print32
565         );
566     }
567     case WM_DESTROY:
568         DestroyIcon(PrintStructures->print32.hCollateIcon);
569         DestroyIcon(PrintStructures->print32.hNoCollateIcon);
570     /* FIXME: don't forget to delete the paper orientation icons here! */
571
572         return FALSE;
573     }
574     return res;
575 }
576
577 /***********************************************************************
578  *           PrintSetupDlgProc   (COMMDLG.22)
579  */
580 BOOL16 CALLBACK PrintSetupDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
581                                    LPARAM lParam)
582 {
583   HWND hWnd = HWND_32(hWnd16);
584   switch (wMsg)
585     {
586     case WM_INITDIALOG:
587       TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
588       ShowWindow(hWnd, SW_SHOWNORMAL);
589       return (TRUE);
590     case WM_COMMAND:
591       switch (wParam) {
592       case IDOK:
593         EndDialog(hWnd, TRUE);
594         return(TRUE);
595       case IDCANCEL:
596         EndDialog(hWnd, FALSE);
597         return(TRUE);
598       }
599       return(FALSE);
600     }
601   return FALSE;
602 }