setupapi: Fix InstallCatalog()'s calling convention.
[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 #include "winerror.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
46
47 #include "cdlg.h"
48 #include "cdlg16.h"
49 #include "printdlg.h"
50
51 typedef struct
52 {
53     PRINT_PTRA   print32;
54     LPPRINTDLG16 lpPrintDlg16;
55 } PRINT_PTRA16;
56
57 /* Internal Functions */
58
59 static BOOL PRINTDLG_CreateDevNames16(HGLOBAL16 *hmem, char* DeviceDriverName,
60                                       char* DeviceName, char* OutputPort)
61 {
62     long size;
63     char*   pDevNamesSpace;
64     char*   pTempPtr;
65     LPDEVNAMES lpDevNames;
66     char buf[260];
67     DWORD dwBufLen = sizeof(buf);
68
69     size = strlen(DeviceDriverName) + 1
70             + strlen(DeviceName) + 1
71             + strlen(OutputPort) + 1
72             + sizeof(DEVNAMES);
73
74     if(*hmem)
75         *hmem = GlobalReAlloc16(*hmem, size, GMEM_MOVEABLE);
76     else
77         *hmem = GlobalAlloc16(GMEM_MOVEABLE, size);
78     if (*hmem == 0)
79         return FALSE;
80
81     pDevNamesSpace = GlobalLock16(*hmem);
82     lpDevNames = (LPDEVNAMES) pDevNamesSpace;
83
84     pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
85     strcpy(pTempPtr, DeviceDriverName);
86     lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
87
88     pTempPtr += strlen(DeviceDriverName) + 1;
89     strcpy(pTempPtr, DeviceName);
90     lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
91
92     pTempPtr += strlen(DeviceName) + 1;
93     strcpy(pTempPtr, OutputPort);
94     lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
95
96     GetDefaultPrinterA(buf, &dwBufLen);
97     lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
98     GlobalUnlock16(*hmem);
99     return TRUE;
100 }
101
102
103 /***********************************************************************
104  *           PRINTDLG_WMInitDialog                      [internal]
105  */
106 static LRESULT PRINTDLG_WMInitDialog16(HWND hDlg, WPARAM wParam, PRINT_PTRA16* ptr16)
107 {
108     PRINT_PTRA *PrintStructures = &ptr16->print32;
109     LPPRINTDLG16 lppd = ptr16->lpPrintDlg16;
110     DEVNAMES *pdn;
111     DEVMODEA *pdm;
112     char *name = NULL;
113     UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
114
115     /* load Collate ICONs */
116     PrintStructures->hCollateIcon =
117       LoadIconA(COMDLG32_hInstance, "PD32_COLLATE");
118     PrintStructures->hNoCollateIcon =
119       LoadIconA(COMDLG32_hInstance, "PD32_NOCOLLATE");
120     if(PrintStructures->hCollateIcon == 0 ||
121        PrintStructures->hNoCollateIcon == 0) {
122         ERR("no icon in resourcefile\n");
123         COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
124         EndDialog(hDlg, FALSE);
125     }
126
127     /* load Paper Orientation ICON */
128     /* FIXME: not implemented yet */
129
130     /*
131      * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
132      * must be registered and the Help button must be shown.
133      */
134     if (lppd->Flags & PD_SHOWHELP) {
135         if((PrintStructures->HelpMessageID =
136             RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
137             COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
138             return FALSE;
139         }
140     } else
141         PrintStructures->HelpMessageID = 0;
142
143     if (!(lppd->Flags & PD_PRINTSETUP)) {
144         /* We have a print quality combo box. What shall we do? */
145         if (GetDlgItem(hDlg,cmb1)) {
146             char buf [20];
147
148             FIXME("Print quality only displaying currently.\n");
149
150             pdm = GlobalLock16(lppd->hDevMode);
151             if(pdm) {
152                 switch (pdm->dmPrintQuality) {
153                 case DMRES_HIGH         : strcpy(buf,"High");break;
154                 case DMRES_MEDIUM       : strcpy(buf,"Medium");break;
155                 case DMRES_LOW          : strcpy(buf,"Low");break;
156                 case DMRES_DRAFT        : strcpy(buf,"Draft");break;
157                 case 0                  : strcpy(buf,"Default");break;
158                 default                 : sprintf(buf,"%ddpi",pdm->dmPrintQuality);break;
159                 }
160                 GlobalUnlock16(lppd->hDevMode);
161             } else
162                 strcpy(buf,"Default");
163             SendDlgItemMessageA(hDlg,cmb1,CB_ADDSTRING,0,(LPARAM)buf);
164             SendDlgItemMessageA(hDlg,cmb1,CB_SETCURSEL,0,0);
165             EnableWindow(GetDlgItem(hDlg,cmb1),FALSE);
166         }
167     }
168
169     /* FIXME: I allow more freedom than either Win95 or WinNT,
170      *        which do not agree to what errors should be thrown or not
171      *        in case nToPage or nFromPage is out-of-range.
172      */
173     if (lppd->nMaxPage < lppd->nMinPage)
174         lppd->nMaxPage = lppd->nMinPage;
175     if (lppd->nMinPage == lppd->nMaxPage)
176         lppd->Flags |= PD_NOPAGENUMS;
177     if (lppd->nToPage < lppd->nMinPage)
178         lppd->nToPage = lppd->nMinPage;
179     if (lppd->nToPage > lppd->nMaxPage)
180         lppd->nToPage = lppd->nMaxPage;
181     if (lppd->nFromPage < lppd->nMinPage)
182         lppd->nFromPage = lppd->nMinPage;
183     if (lppd->nFromPage > lppd->nMaxPage)
184         lppd->nFromPage = lppd->nMaxPage;
185
186     /* If the printer combo box is in the dialog, fill it */
187     if (GetDlgItem(hDlg,comboID)) {
188         /* Fill Combobox
189          */
190         pdn = GlobalLock16(lppd->hDevNames);
191         pdm = GlobalLock16(lppd->hDevMode);
192         if(pdn)
193             name = (char*)pdn + pdn->wDeviceOffset;
194         else if(pdm)
195             name = (char*)pdm->dmDeviceName;
196         PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
197         if(pdm) GlobalUnlock16(lppd->hDevMode);
198         if(pdn) GlobalUnlock16(lppd->hDevNames);
199
200         /* Now find selected printer and update rest of dlg */
201         name = HeapAlloc(GetProcessHeap(),0,256);
202         if (GetDlgItemTextA(hDlg, comboID, name, 255))
203             PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
204     } else {
205         /* else just use default printer */
206         char name[200];
207         DWORD dwBufLen = sizeof(name);
208         BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
209
210         if (ret)
211             PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
212         else
213             FIXME("No default printer found, expect problems!\n");
214     }
215     HeapFree(GetProcessHeap(),0,name);
216
217     return TRUE;
218 }
219
220 /************************************************************
221  *
222  *      PRINTDLG_Get16TemplateFrom32             [Internal]
223  *      Generates a 16 bits template from the Wine 32 bits resource
224  *
225  */
226 static HGLOBAL16 PRINTDLG_Get16TemplateFrom32(LPCSTR PrintResourceName)
227 {
228         HRSRC hResInfo;
229         HGLOBAL hDlgTmpl32;
230         LPCVOID template32;
231         DWORD size;
232         HGLOBAL16 hGlobal16;
233         LPVOID template;
234
235         if (!(hResInfo = FindResourceA(COMDLG32_hInstance,
236                PrintResourceName, (LPSTR)RT_DIALOG)))
237         {
238             COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
239             return 0;
240         }
241         if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo )) ||
242             !(template32 = LockResource( hDlgTmpl32 )))
243         {
244             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
245             return 0;
246         }
247         size = SizeofResource(COMDLG32_hInstance, hResInfo);
248         hGlobal16 = GlobalAlloc16(0, size);
249         if (!hGlobal16)
250         {
251             COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
252             ERR("alloc failure for %d bytes\n", size);
253             return 0;
254         }
255         template = GlobalLock16(hGlobal16);
256         if (!template)
257         {
258             COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
259             ERR("global lock failure for %x handle\n", hGlobal16);
260             GlobalFree16(hGlobal16);
261             return 0;
262         }
263         ConvertDialog32To16(template32, size, template);
264         GlobalUnlock16(hGlobal16);
265         return hGlobal16;
266 }
267
268 static BOOL PRINTDLG_CreateDC16(LPPRINTDLG16 lppd)
269 {
270     DEVNAMES *pdn = GlobalLock16(lppd->hDevNames);
271     DEVMODEA *pdm = GlobalLock16(lppd->hDevMode);
272
273     if(lppd->Flags & PD_RETURNDC) {
274         lppd->hDC = HDC_16(CreateDCA((char*)pdn + pdn->wDriverOffset,
275                               (char*)pdn + pdn->wDeviceOffset,
276                               (char*)pdn + pdn->wOutputOffset,
277                               pdm ));
278     } else if(lppd->Flags & PD_RETURNIC) {
279         lppd->hDC = HDC_16(CreateICA((char*)pdn + pdn->wDriverOffset,
280                               (char*)pdn + pdn->wDeviceOffset,
281                               (char*)pdn + pdn->wOutputOffset,
282                               pdm ));
283     }
284     GlobalUnlock16(lppd->hDevNames);
285     GlobalUnlock16(lppd->hDevMode);
286     return lppd->hDC ? TRUE : FALSE;
287 }
288
289 /************************************************************
290  *
291  *      PRINTDLG_GetDlgTemplate
292  *
293  */
294 static HGLOBAL16 PRINTDLG_GetDlgTemplate16(PRINTDLG16 *lppd)
295 {
296     HGLOBAL16 hDlgTmpl, hResInfo;
297
298     if (lppd->Flags & PD_PRINTSETUP) {
299         if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
300             hDlgTmpl = lppd->hSetupTemplate;
301         } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
302             hResInfo = FindResource16(lppd->hInstance,
303                                      MapSL(lppd->lpSetupTemplateName), (LPSTR)RT_DIALOG);
304             hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
305         } else {
306             hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32_SETUP");
307         }
308     } else {
309         if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
310             hDlgTmpl = lppd->hPrintTemplate;
311         } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
312             hResInfo = FindResource16(lppd->hInstance,
313                                      MapSL(lppd->lpPrintTemplateName),
314                                      (LPSTR)RT_DIALOG);
315             hDlgTmpl = LoadResource16(lppd->hInstance, hResInfo);
316         } else {
317             hDlgTmpl = PRINTDLG_Get16TemplateFrom32("PRINT32");
318         }
319     }
320     return hDlgTmpl;
321 }
322
323 /**********************************************************************
324  *
325  *      16 bit commdlg
326  */
327
328 /***********************************************************************
329  *           PrintDlg   (COMMDLG.20)
330  *
331  *  Displays the the PRINT dialog box, which enables the user to specify
332  *  specific properties of the print job.
333  *
334  * RETURNS
335  *  nonzero if the user pressed the OK button
336  *  zero    if the user cancelled the window or an error occurred
337  *
338  * BUGS
339  *  * calls up to the 32-bit versions of the Dialogs, which look different
340  *  * Customizing is *not* implemented.
341  */
342
343 BOOL16 WINAPI PrintDlg16(
344               LPPRINTDLG16 lppd /* [in/out] ptr to PRINTDLG struct */
345 ) {
346     BOOL      bRet = FALSE;
347     LPVOID   ptr;
348     HINSTANCE16 hInst = GetWindowLongPtrW( HWND_32(lppd->hwndOwner), GWLP_HINSTANCE );
349
350     if(TRACE_ON(commdlg)) {
351         char flagstr[1000] = "";
352         const struct pd_flags *pflag = pd_flags;
353         for( ; pflag->name; pflag++) {
354             if(lppd->Flags & pflag->flag)
355                 strcat(flagstr, pflag->name);
356         }
357         TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
358               "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
359               "flags %08x (%s)\n",
360               lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
361               lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
362               lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
363     }
364
365     if(lppd->lStructSize != sizeof(PRINTDLG16)) {
366         ERR("structure size %d\n",lppd->lStructSize);
367         COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
368         return FALSE;
369     }
370
371     if(lppd->Flags & PD_RETURNDEFAULT) {
372         PRINTER_INFO_2A *pbuf;
373         DRIVER_INFO_3A  *dbuf;
374         HANDLE hprn;
375         DWORD needed;
376
377         if(lppd->hDevMode || lppd->hDevNames) {
378             WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
379             COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
380             return FALSE;
381         }
382         if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
383             WARN("Can't find default printer\n");
384             COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
385             return FALSE;
386         }
387
388         GetPrinterA(hprn, 2, NULL, 0, &needed);
389         pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
390         GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
391         GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
392         dbuf = HeapAlloc(GetProcessHeap(),0,needed);
393         if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
394             ERR("GetPrinterDriverA failed for %s, le %d, fix your config!\n",
395                     pbuf->pPrinterName,GetLastError());
396             HeapFree(GetProcessHeap(), 0, dbuf);
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, PrintStructures);
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 }