Added support for doing SetBitmapBits on a DIB section.
[wine/dcerpc.git] / dlls / msi / dialog.c
blob87e14e87f35711ea4b3f5926ae9f4a8303a867e0
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define COBJMACROS
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "wingdi.h"
32 #include "msi.h"
33 #include "msipriv.h"
34 #include "msidefs.h"
35 #include "ocidl.h"
36 #include "olectl.h"
37 #include "richedit.h"
38 #include "commctrl.h"
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
43 #include "action.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi);
48 struct msi_control_tag;
49 typedef struct msi_control_tag msi_control;
50 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
52 struct msi_control_tag
54 struct list entry;
55 HWND hwnd;
56 msi_handler handler;
57 LPWSTR property;
58 LPWSTR value;
59 HBITMAP hBitmap;
60 HICON hIcon;
61 LPWSTR tabnext;
62 HMODULE hDll;
63 WCHAR name[1];
66 typedef struct msi_font_tag
68 struct msi_font_tag *next;
69 HFONT hfont;
70 WCHAR name[1];
71 } msi_font;
73 struct msi_dialog_tag
75 MSIPACKAGE *package;
76 msi_dialog_event_handler event_handler;
77 BOOL finished;
78 INT scale;
79 DWORD attributes;
80 HWND hwnd;
81 LPWSTR default_font;
82 msi_font *font_list;
83 struct list controls;
84 HWND hWndFocus;
85 LPWSTR control_default;
86 LPWSTR control_cancel;
87 WCHAR name[1];
90 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
91 struct control_handler
93 LPCWSTR control_type;
94 msi_dialog_control_func func;
97 typedef struct
99 msi_dialog* dialog;
100 msi_control *parent;
101 DWORD attributes;
102 } radio_button_group_descr;
104 const WCHAR szMsiDialogClass[] = {
105 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
107 const WCHAR szMsiHiddenWindow[] = {
108 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
109 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
110 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
111 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
112 static const WCHAR szText[] = { 'T','e','x','t',0 };
113 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
114 static const WCHAR szLine[] = { 'L','i','n','e',0 };
115 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
116 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
117 static const WCHAR szScrollableText[] = {
118 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
119 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
120 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
121 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
122 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
123 static const WCHAR szProgressBar[] = {
124 'P','r','o','g','r','e','s','s','B','a','r',0 };
125 static const WCHAR szRadioButtonGroup[] = {
126 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
127 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
128 static const WCHAR szSelectionTree[] = {
129 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
131 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
132 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
133 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
134 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
135 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
136 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
137 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
140 /* dialog sequencing */
142 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
143 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
145 static DWORD uiThreadId;
146 static HWND hMsiHiddenWindow;
148 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
150 return (dialog->scale * val + 5) / 10;
153 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
155 msi_control *control;
157 if( !name )
158 return NULL;
159 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
160 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
161 return control;
162 return NULL;
165 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
167 msi_control *control;
169 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
170 if( hwnd == control->hwnd )
171 return control;
172 return NULL;
175 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
177 LPCWSTR str = MSI_RecordGetString( rec, field );
178 LPWSTR ret = NULL;
180 if (str)
181 deformat_string( package, str, &ret );
182 return ret;
186 * msi_dialog_get_style
188 * Extract the {\style} string from the front of the text to display and
189 * update the pointer.
191 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
193 LPWSTR ret = NULL;
194 LPCWSTR q, i;
195 DWORD len;
197 *rest = p;
198 if( !p )
199 return ret;
200 if( *p++ != '{' )
201 return ret;
202 q = strchrW( p, '}' );
203 if( !q )
204 return ret;
205 if( *p == '\\' || *p == '&' )
206 p++;
208 /* little bit of sanity checking to stop us getting confused with RTF */
209 for( i=p; i<q; i++ )
210 if( *i == '}' || *i == '\\' )
211 return ret;
213 *rest = ++q;
214 len = q - p;
216 ret = msi_alloc( len*sizeof(WCHAR) );
217 if( !ret )
218 return ret;
219 memcpy( ret, p, len*sizeof(WCHAR) );
220 ret[len-1] = 0;
221 return ret;
224 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
226 msi_dialog *dialog = param;
227 msi_font *font;
228 LPCWSTR face, name;
229 LOGFONTW lf;
230 INT style;
231 HDC hdc;
233 /* create a font and add it to the list */
234 name = MSI_RecordGetString( rec, 1 );
235 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
236 strcpyW( font->name, name );
237 font->next = dialog->font_list;
238 dialog->font_list = font;
240 memset( &lf, 0, sizeof lf );
241 face = MSI_RecordGetString( rec, 2 );
242 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
243 style = MSI_RecordGetInteger( rec, 5 );
244 if( style & msidbTextStyleStyleBitsBold )
245 lf.lfWeight = FW_BOLD;
246 if( style & msidbTextStyleStyleBitsItalic )
247 lf.lfItalic = TRUE;
248 if( style & msidbTextStyleStyleBitsUnderline )
249 lf.lfUnderline = TRUE;
250 if( style & msidbTextStyleStyleBitsStrike )
251 lf.lfStrikeOut = TRUE;
252 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
254 /* adjust the height */
255 hdc = GetDC( dialog->hwnd );
256 if (hdc)
258 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
259 ReleaseDC( dialog->hwnd, hdc );
262 font->hfont = CreateFontIndirectW( &lf );
264 TRACE("Adding font style %s\n", debugstr_w(font->name) );
266 return ERROR_SUCCESS;
269 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
271 msi_font *font;
273 for( font = dialog->font_list; font; font = font->next )
274 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
275 break;
277 return font;
280 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
282 msi_font *font;
284 font = msi_dialog_find_font( dialog, name );
285 if( font )
286 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
287 else
288 ERR("No font entry for %s\n", debugstr_w(name));
289 return ERROR_SUCCESS;
292 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
294 static const WCHAR query[] = {
295 'S','E','L','E','C','T',' ','*',' ',
296 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
298 UINT r;
299 MSIQUERY *view = NULL;
301 TRACE("dialog %p\n", dialog );
303 r = MSI_OpenQuery( dialog->package->db, &view, query );
304 if( r != ERROR_SUCCESS )
305 return r;
307 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
308 msiobj_release( &view->hdr );
310 return r;
313 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
314 MSIRECORD *rec, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
315 DWORD style, HWND parent )
317 DWORD x, y, width, height;
318 LPWSTR font = NULL, title_font = NULL;
319 LPCWSTR title = NULL;
320 msi_control *control;
322 style |= WS_CHILD;
324 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
325 strcpyW( control->name, name );
326 list_add_head( &dialog->controls, &control->entry );
327 control->handler = NULL;
328 control->property = NULL;
329 control->value = NULL;
330 control->hBitmap = NULL;
331 control->hIcon = NULL;
332 control->hDll = NULL;
333 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
335 x = MSI_RecordGetInteger( rec, 4 );
336 y = MSI_RecordGetInteger( rec, 5 );
337 width = MSI_RecordGetInteger( rec, 6 );
338 height = MSI_RecordGetInteger( rec, 7 );
340 x = msi_dialog_scale_unit( dialog, x );
341 y = msi_dialog_scale_unit( dialog, y );
342 width = msi_dialog_scale_unit( dialog, width );
343 height = msi_dialog_scale_unit( dialog, height );
345 if( text )
347 deformat_string( dialog->package, text, &title_font );
348 font = msi_dialog_get_style( title_font, &title );
351 control->hwnd = CreateWindowW( szCls, title, style,
352 x, y, width, height, parent, NULL, NULL, NULL );
354 TRACE("Dialog %s control %s hwnd %p\n",
355 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
357 msi_dialog_set_font( dialog, control->hwnd,
358 font ? font : dialog->default_font );
360 msi_free( title_font );
361 msi_free( font );
363 return control;
366 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
368 static const WCHAR query[] = {
369 's','e','l','e','c','t',' ','*',' ',
370 'f','r','o','m',' ','B','i','n','a','r','y',' ',
371 'w','h','e','r','e',' ',
372 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
375 return MSI_QueryGetRecord( db, query, name );
378 static LPWSTR msi_create_tmp_path(void)
380 WCHAR tmp[MAX_PATH];
381 LPWSTR path = NULL;
382 static const WCHAR prefix[] = { 'm','s','i',0 };
383 DWORD len, r;
385 r = GetTempPathW( MAX_PATH, tmp );
386 if( !r )
387 return path;
388 len = lstrlenW( tmp ) + 20;
389 path = msi_alloc( len * sizeof (WCHAR) );
390 if( path )
392 r = GetTempFileNameW( tmp, prefix, 0, path );
393 if (!r)
395 msi_free( path );
396 path = NULL;
399 return path;
403 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
404 UINT cx, UINT cy, UINT flags )
406 MSIRECORD *rec = NULL;
407 HANDLE himage = NULL;
408 LPWSTR tmp;
409 UINT r;
411 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
413 tmp = msi_create_tmp_path();
414 if( !tmp )
415 return himage;
417 rec = msi_get_binary_record( db, name );
418 if( rec )
420 r = MSI_RecordStreamToFile( rec, 2, tmp );
421 if( r == ERROR_SUCCESS )
423 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
424 DeleteFileW( tmp );
426 msiobj_release( &rec->hdr );
429 msi_free( tmp );
430 return himage;
433 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
435 DWORD cx = 0, cy = 0, flags;
437 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
438 if( attributes & msidbControlAttributesFixedSize )
440 flags &= ~LR_DEFAULTSIZE;
441 if( attributes & msidbControlAttributesIconSize16 )
443 cx += 16;
444 cy += 16;
446 if( attributes & msidbControlAttributesIconSize32 )
448 cx += 32;
449 cy += 32;
451 /* msidbControlAttributesIconSize48 handled by above logic */
453 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
457 /* called from the Control Event subscription code */
458 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
459 LPCWSTR attribute, MSIRECORD *rec )
461 msi_control* ctrl;
462 LPCWSTR text;
464 ctrl = msi_dialog_find_control( dialog, control );
465 if (!ctrl)
466 return;
467 if( lstrcmpW(attribute, szText) )
469 ERR("Attribute %s\n", debugstr_w(attribute));
470 return;
472 text = MSI_RecordGetString( rec , 1 );
473 SetWindowTextW( ctrl->hwnd, text );
474 msi_dialog_check_messages( NULL );
477 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
479 static WCHAR Query[] = {
480 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
481 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
482 'W','H','E','R','E',' ',
483 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
484 'A','N','D',' ',
485 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
487 MSIRECORD *row;
488 LPCWSTR event, attribute;
490 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
491 if (!row)
492 return;
494 event = MSI_RecordGetString( row, 3 );
495 attribute = MSI_RecordGetString( row, 4 );
496 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
497 msiobj_release( &row->hdr );
500 /* everything except radio buttons */
501 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
502 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
504 DWORD attributes;
505 LPCWSTR text, name;
507 name = MSI_RecordGetString( rec, 2 );
508 attributes = MSI_RecordGetInteger( rec, 8 );
509 text = MSI_RecordGetString( rec, 10 );
510 if( attributes & msidbControlAttributesVisible )
511 style |= WS_VISIBLE;
512 if( ~attributes & msidbControlAttributesEnabled )
513 style |= WS_DISABLED;
515 msi_dialog_map_events(dialog, name);
517 return msi_dialog_create_window( dialog, rec, szCls, name, text,
518 style, dialog->hwnd );
521 struct msi_text_info
523 WNDPROC oldproc;
524 DWORD attributes;
528 * we don't erase our own background,
529 * so we have to make sure that the parent window redraws first
531 static void msi_text_on_settext( HWND hWnd )
533 HWND hParent;
534 RECT rc;
536 hParent = GetParent( hWnd );
537 GetWindowRect( hWnd, &rc );
538 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
539 InvalidateRect( hParent, &rc, TRUE );
542 static LRESULT WINAPI
543 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
545 struct msi_text_info *info;
546 LRESULT r = 0;
548 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
550 info = GetPropW(hWnd, szButtonData);
552 if( msg == WM_CTLCOLORSTATIC &&
553 ( info->attributes & msidbControlAttributesTransparent ) )
555 SetBkMode( (HDC)wParam, TRANSPARENT );
556 return (LRESULT) GetStockObject(NULL_BRUSH);
559 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
561 switch( msg )
563 case WM_SETTEXT:
564 msi_text_on_settext( hWnd );
565 break;
566 case WM_NCDESTROY:
567 msi_free( info );
568 RemovePropW( hWnd, szButtonData );
569 break;
572 return r;
575 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
577 msi_control *control;
578 struct msi_text_info *info;
580 TRACE("%p %p\n", dialog, rec);
582 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
583 if( !control )
584 return ERROR_FUNCTION_FAILED;
586 info = msi_alloc( sizeof *info );
587 if( !info )
588 return ERROR_SUCCESS;
590 info->attributes = MSI_RecordGetInteger( rec, 8 );
591 if( info->attributes & msidbControlAttributesTransparent )
592 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
594 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
595 (LONG_PTR)MSIText_WndProc );
596 SetPropW( control->hwnd, szButtonData, info );
598 return ERROR_SUCCESS;
601 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
603 msi_control *control;
604 UINT attributes, style;
605 LPWSTR text;
607 TRACE("%p %p\n", dialog, rec);
609 style = WS_TABSTOP;
610 attributes = MSI_RecordGetInteger( rec, 8 );
611 if( attributes & msidbControlAttributesIcon )
612 style |= BS_ICON;
614 control = msi_dialog_add_control( dialog, rec, szButton, style );
615 if( !control )
616 return ERROR_FUNCTION_FAILED;
618 control->handler = msi_dialog_button_handler;
620 /* set the icon */
621 text = msi_get_deformatted_field( dialog->package, rec, 10 );
622 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
623 if( attributes & msidbControlAttributesIcon )
624 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
625 msi_free( text );
627 return ERROR_SUCCESS;
630 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
632 static const WCHAR query[] = {
633 'S','E','L','E','C','T',' ','*',' ',
634 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
635 'W','H','E','R','E',' ',
636 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
637 '\'','%','s','\'',0
639 MSIRECORD *rec = NULL;
640 LPWSTR ret = NULL;
642 /* find if there is a value associated with the checkbox */
643 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
644 if (!rec)
645 return ret;
647 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
648 if( ret && !ret[0] )
650 msi_free( ret );
651 ret = NULL;
653 msiobj_release( &rec->hdr );
654 if (ret)
655 return ret;
657 ret = msi_dup_property( dialog->package, prop );
658 if( ret && !ret[0] )
660 msi_free( ret );
661 ret = NULL;
664 return ret;
667 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
669 msi_control *control;
670 LPCWSTR prop;
672 TRACE("%p %p\n", dialog, rec);
674 control = msi_dialog_add_control( dialog, rec, szButton,
675 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
676 control->handler = msi_dialog_checkbox_handler;
677 prop = MSI_RecordGetString( rec, 9 );
678 if( prop )
680 control->property = strdupW( prop );
681 control->value = msi_get_checkbox_value( dialog, prop );
682 TRACE("control %s value %s\n", debugstr_w(control->property),
683 debugstr_w(control->value));
685 msi_dialog_checkbox_sync_state( dialog, control );
687 return ERROR_SUCCESS;
690 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
692 TRACE("%p %p\n", dialog, rec);
694 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
695 return ERROR_SUCCESS;
698 struct msi_streamin_info
700 LPSTR string;
701 DWORD offset;
702 DWORD length;
705 static DWORD CALLBACK
706 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
708 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
710 if( (count + info->offset) > info->length )
711 count = info->length - info->offset;
712 memcpy( buffer, &info->string[ info->offset ], count );
713 *pcb = count;
714 info->offset += count;
716 TRACE("%ld/%ld\n", info->offset, info->length);
718 return 0;
721 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
723 static const WCHAR szRichEdit20W[] = {
724 'R','i','c','h','E','d','i','t','2','0','W',0
726 struct msi_streamin_info info;
727 msi_control *control;
728 LPCWSTR text;
729 EDITSTREAM es;
730 DWORD style;
731 HMODULE hRichedit;
733 hRichedit = LoadLibraryA("riched20");
735 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
736 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
737 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
738 if (!control)
739 return ERROR_FUNCTION_FAILED;
741 control->hDll = hRichedit;
743 text = MSI_RecordGetString( rec, 10 );
744 info.string = strdupWtoA( text );
745 info.offset = 0;
746 info.length = lstrlenA( info.string ) + 1;
748 es.dwCookie = (DWORD_PTR) &info;
749 es.dwError = 0;
750 es.pfnCallback = msi_richedit_stream_in;
752 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
754 msi_free( info.string );
756 return ERROR_SUCCESS;
759 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
760 INT cx, INT cy, DWORD flags )
762 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
763 MSIRECORD *rec = NULL;
764 IStream *stm = NULL;
765 IPicture *pic = NULL;
766 HDC srcdc, destdc;
767 BITMAP bm;
768 UINT r;
770 rec = msi_get_binary_record( db, name );
771 if( !rec )
772 goto end;
774 r = MSI_RecordGetIStream( rec, 2, &stm );
775 msiobj_release( &rec->hdr );
776 if( r != ERROR_SUCCESS )
777 goto end;
779 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
780 IStream_Release( stm );
781 if( FAILED( r ) )
783 ERR("failed to load picture\n");
784 goto end;
787 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
788 if( FAILED( r ) )
790 ERR("failed to get bitmap handle\n");
791 goto end;
794 /* make the bitmap the desired size */
795 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
796 if (r != sizeof bm )
798 ERR("failed to get bitmap size\n");
799 goto end;
802 if (flags & LR_DEFAULTSIZE)
804 cx = bm.bmWidth;
805 cy = bm.bmHeight;
808 srcdc = CreateCompatibleDC( NULL );
809 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
810 destdc = CreateCompatibleDC( NULL );
811 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
812 hOldDestBitmap = SelectObject( destdc, hBitmap );
813 StretchBlt( destdc, 0, 0, cx, cy,
814 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
815 SelectObject( srcdc, hOldSrcBitmap );
816 SelectObject( destdc, hOldDestBitmap );
817 DeleteDC( srcdc );
818 DeleteDC( destdc );
820 end:
821 if ( pic )
822 IPicture_Release( pic );
823 return hBitmap;
826 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
828 UINT cx, cy, flags, style, attributes;
829 msi_control *control;
830 LPWSTR text;
832 flags = LR_LOADFROMFILE;
833 style = SS_BITMAP | SS_LEFT | WS_GROUP;
835 attributes = MSI_RecordGetInteger( rec, 8 );
836 if( attributes & msidbControlAttributesFixedSize )
838 flags |= LR_DEFAULTSIZE;
839 style |= SS_CENTERIMAGE;
842 control = msi_dialog_add_control( dialog, rec, szStatic, style );
843 cx = MSI_RecordGetInteger( rec, 6 );
844 cy = MSI_RecordGetInteger( rec, 7 );
845 cx = msi_dialog_scale_unit( dialog, cx );
846 cy = msi_dialog_scale_unit( dialog, cy );
848 text = msi_get_deformatted_field( dialog->package, rec, 10 );
849 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
850 if( control->hBitmap )
851 SendMessageW( control->hwnd, STM_SETIMAGE,
852 IMAGE_BITMAP, (LPARAM) control->hBitmap );
853 else
854 ERR("Failed to load bitmap %s\n", debugstr_w(text));
856 msi_free( text );
858 return ERROR_SUCCESS;
861 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
863 msi_control *control;
864 DWORD attributes;
865 LPWSTR text;
867 TRACE("\n");
869 control = msi_dialog_add_control( dialog, rec, szStatic,
870 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
872 attributes = MSI_RecordGetInteger( rec, 8 );
873 text = msi_get_deformatted_field( dialog->package, rec, 10 );
874 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
875 if( control->hIcon )
876 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
877 else
878 ERR("Failed to load bitmap %s\n", debugstr_w(text));
879 msi_free( text );
880 return ERROR_SUCCESS;
883 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
885 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
887 msi_dialog_add_control( dialog, rec, szCombo,
888 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
889 return ERROR_SUCCESS;
892 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
894 msi_control *control;
895 LPCWSTR prop;
896 LPWSTR val;
898 control = msi_dialog_add_control( dialog, rec, szEdit,
899 WS_BORDER | WS_TABSTOP );
900 control->handler = msi_dialog_edit_handler;
901 prop = MSI_RecordGetString( rec, 9 );
902 if( prop )
903 control->property = strdupW( prop );
904 val = msi_dup_property( dialog->package, control->property );
905 SetWindowTextW( control->hwnd, val );
906 msi_free( val );
907 return ERROR_SUCCESS;
910 /******************** Masked Edit ********************************************/
912 #define MASK_MAX_GROUPS 10
914 struct msi_mask_group
916 UINT len;
917 UINT ofs;
918 WCHAR type;
919 HWND hwnd;
922 struct msi_maskedit_info
924 msi_dialog *dialog;
925 WNDPROC oldproc;
926 HWND hwnd;
927 LPWSTR prop;
928 UINT num_chars;
929 UINT num_groups;
930 struct msi_mask_group group[MASK_MAX_GROUPS];
933 static BOOL msi_mask_editable( WCHAR type )
935 switch (type)
937 case '%':
938 case '#':
939 case '&':
940 case '`':
941 case '?':
942 case '^':
943 return TRUE;
945 return FALSE;
948 static void msi_mask_control_change( struct msi_maskedit_info *info )
950 LPWSTR val;
951 UINT i, n, r;
953 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
954 for( i=0, n=0; i<info->num_groups; i++ )
956 if( (info->group[i].len + n) > info->num_chars )
958 ERR("can't fit control %d text into template\n",i);
959 break;
961 if (!msi_mask_editable(info->group[i].type))
963 for(r=0; r<info->group[i].len; r++)
964 val[n+r] = info->group[i].type;
965 val[n+r] = 0;
967 else
969 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
970 if( r != info->group[i].len )
971 break;
973 n += r;
976 TRACE("%d/%d controls were good\n", i, info->num_groups);
978 if( i == info->num_groups )
980 TRACE("Set property %s to %s\n",
981 debugstr_w(info->prop), debugstr_w(val) );
982 CharUpperBuffW( val, info->num_chars );
983 MSI_SetPropertyW( info->dialog->package, info->prop, val );
984 msi_dialog_evaluate_control_conditions( info->dialog );
986 msi_free( val );
989 /* now move to the next control if necessary */
990 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
992 HWND hWndNext;
993 UINT len, i;
995 for( i=0; i<info->num_groups; i++ )
996 if( info->group[i].hwnd == hWnd )
997 break;
999 /* don't move from the last control */
1000 if( i >= (info->num_groups-1) )
1001 return;
1003 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1004 if( len < info->group[i].len )
1005 return;
1007 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1008 SetFocus( hWndNext );
1011 static LRESULT WINAPI
1012 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1014 struct msi_maskedit_info *info;
1015 HRESULT r;
1017 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1019 info = GetPropW(hWnd, szButtonData);
1021 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1023 switch( msg )
1025 case WM_COMMAND:
1026 if (HIWORD(wParam) == EN_CHANGE)
1028 msi_mask_control_change( info );
1029 msi_mask_next_control( info, (HWND) lParam );
1031 break;
1032 case WM_NCDESTROY:
1033 msi_free( info->prop );
1034 msi_free( info );
1035 RemovePropW( hWnd, szButtonData );
1036 break;
1039 return r;
1042 /* fish the various bits of the property out and put them in the control */
1043 static void
1044 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1046 LPCWSTR p;
1047 UINT i;
1049 p = text;
1050 for( i = 0; i < info->num_groups; i++ )
1052 if( info->group[i].len < lstrlenW( p ) )
1054 LPWSTR chunk = strdupW( p );
1055 chunk[ info->group[i].len ] = 0;
1056 SetWindowTextW( info->group[i].hwnd, chunk );
1057 msi_free( chunk );
1059 else
1061 SetWindowTextW( info->group[i].hwnd, p );
1062 break;
1064 p += info->group[i].len;
1068 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1070 struct msi_maskedit_info * info = NULL;
1071 int i = 0, n = 0, total = 0;
1072 LPCWSTR p;
1074 TRACE("masked control, template %s\n", debugstr_w(mask));
1076 if( !mask )
1077 return info;
1079 p = strchrW(mask, '<');
1080 if( !p )
1081 return info;
1083 info = msi_alloc_zero( sizeof *info );
1084 if( !info )
1085 return info;
1087 p++;
1088 for( i=0; i<MASK_MAX_GROUPS; i++ )
1090 /* stop at the end of the string */
1091 if( p[0] == 0 || p[0] == '>' )
1092 break;
1094 /* count the number of the same identifier */
1095 for( n=0; p[n] == p[0]; n++ )
1097 info->group[i].ofs = total;
1098 info->group[i].type = p[0];
1099 if( p[n] == '=' )
1101 n++;
1102 total++; /* an extra not part of the group */
1104 info->group[i].len = n;
1105 total += n;
1106 p += n;
1109 TRACE("%d characters in %d groups\n", total, i );
1110 if( i == MASK_MAX_GROUPS )
1111 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1113 info->num_chars = total;
1114 info->num_groups = i;
1116 return info;
1119 static void
1120 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1122 DWORD width, height, style, wx, ww;
1123 RECT rect;
1124 HWND hwnd;
1125 UINT i;
1127 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP;
1129 GetClientRect( info->hwnd, &rect );
1131 width = rect.right - rect.left;
1132 height = rect.bottom - rect.top;
1134 for( i = 0; i < info->num_groups; i++ )
1136 if (!msi_mask_editable( info->group[i].type ))
1137 continue;
1138 wx = (info->group[i].ofs * width) / info->num_chars;
1139 ww = (info->group[i].len * width) / info->num_chars;
1141 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1142 info->hwnd, NULL, NULL, NULL );
1143 if( !hwnd )
1145 ERR("failed to create mask edit sub window\n");
1146 break;
1149 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1151 msi_dialog_set_font( info->dialog, hwnd,
1152 font?font:info->dialog->default_font );
1153 info->group[i].hwnd = hwnd;
1158 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1159 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1160 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1162 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1164 LPWSTR font_mask, val = NULL, font;
1165 struct msi_maskedit_info *info = NULL;
1166 UINT ret = ERROR_SUCCESS;
1167 msi_control *control;
1168 LPCWSTR prop, mask;
1170 TRACE("\n");
1172 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1173 font = msi_dialog_get_style( font_mask, &mask );
1174 if( !mask )
1176 ERR("mask template is empty\n");
1177 goto end;
1180 info = msi_dialog_parse_groups( mask );
1181 if( !info )
1183 ERR("template %s is invalid\n", debugstr_w(mask));
1184 goto end;
1187 info->dialog = dialog;
1189 control = msi_dialog_add_control( dialog, rec, szStatic,
1190 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1191 if( !control )
1193 ERR("Failed to create maskedit container\n");
1194 ret = ERROR_FUNCTION_FAILED;
1195 goto end;
1197 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1199 info->hwnd = control->hwnd;
1201 /* subclass the static control */
1202 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1203 (LONG_PTR)MSIMaskedEdit_WndProc );
1204 SetPropW( control->hwnd, szButtonData, info );
1206 prop = MSI_RecordGetString( rec, 9 );
1207 if( prop )
1208 info->prop = strdupW( prop );
1210 msi_maskedit_create_children( info, font );
1212 if( prop )
1214 val = msi_dup_property( dialog->package, prop );
1215 if( val )
1217 msi_maskedit_set_text( info, val );
1218 msi_free( val );
1222 end:
1223 if( ret != ERROR_SUCCESS )
1224 msi_free( info );
1225 msi_free( font_mask );
1226 msi_free( font );
1227 return ret;
1230 /******************** Progress Bar *****************************************/
1232 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1234 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1235 return ERROR_SUCCESS;
1238 /******************** Path Edit ********************************************/
1240 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1242 FIXME("not implemented properly\n");
1243 return msi_dialog_edit_control( dialog, rec );
1246 /* radio buttons are a bit different from normal controls */
1247 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1249 radio_button_group_descr *group = (radio_button_group_descr *)param;
1250 msi_dialog *dialog = group->dialog;
1251 msi_control *control;
1252 LPCWSTR prop, text, name;
1253 DWORD style, attributes = group->attributes;
1255 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1256 name = MSI_RecordGetString( rec, 3 );
1257 text = MSI_RecordGetString( rec, 8 );
1258 if( attributes & 1 )
1259 style |= WS_VISIBLE;
1260 if( ~attributes & 2 )
1261 style |= WS_DISABLED;
1263 control = msi_dialog_create_window( dialog, rec, szButton, name, text,
1264 style, group->parent->hwnd );
1265 if (!control)
1266 return ERROR_FUNCTION_FAILED;
1267 control->handler = msi_dialog_radiogroup_handler;
1269 prop = MSI_RecordGetString( rec, 1 );
1270 if( prop )
1271 control->property = strdupW( prop );
1273 return ERROR_SUCCESS;
1276 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1278 static const WCHAR query[] = {
1279 'S','E','L','E','C','T',' ','*',' ',
1280 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1281 'W','H','E','R','E',' ',
1282 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1283 UINT r;
1284 LPCWSTR prop;
1285 msi_control *control;
1286 MSIQUERY *view = NULL;
1287 radio_button_group_descr group;
1288 MSIPACKAGE *package = dialog->package;
1289 WNDPROC oldproc;
1291 prop = MSI_RecordGetString( rec, 9 );
1293 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1295 /* Create parent group box to hold radio buttons */
1296 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1297 if( !control )
1298 return ERROR_FUNCTION_FAILED;
1300 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1301 (LONG_PTR)MSIRadioGroup_WndProc );
1302 SetPropW(control->hwnd, szButtonData, oldproc);
1303 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1305 if( prop )
1306 control->property = strdupW( prop );
1308 /* query the Radio Button table for all control in this group */
1309 r = MSI_OpenQuery( package->db, &view, query, prop );
1310 if( r != ERROR_SUCCESS )
1312 ERR("query failed for dialog %s radio group %s\n",
1313 debugstr_w(dialog->name), debugstr_w(prop));
1314 return ERROR_INVALID_PARAMETER;
1317 group.dialog = dialog;
1318 group.parent = control;
1319 group.attributes = MSI_RecordGetInteger( rec, 8 );
1321 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1322 msiobj_release( &view->hdr );
1324 return r;
1327 /******************** Selection Tree ***************************************/
1329 static void
1330 msi_dialog_tv_add_child_features( MSIPACKAGE *package, HWND hwnd,
1331 LPCWSTR parent, HTREEITEM hParent )
1333 MSIFEATURE *feature;
1334 TVINSERTSTRUCTW tvis;
1335 HTREEITEM hitem;
1337 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1339 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1340 continue;
1342 if ( !feature->Title )
1343 continue;
1345 memset( &tvis, 0, sizeof tvis );
1346 tvis.hParent = hParent;
1347 tvis.hInsertAfter = TVI_SORT;
1348 if (feature->Title)
1350 tvis.u.item.mask = TVIF_TEXT;
1351 tvis.u.item.pszText = feature->Title;
1353 tvis.u.item.lParam = (LPARAM) feature;
1354 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1355 if (!hitem)
1356 continue;
1358 msi_dialog_tv_add_child_features( package, hwnd,
1359 feature->Feature, hitem );
1363 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1365 msi_control *control;
1366 LPCWSTR prop;
1367 LPWSTR val;
1368 MSIPACKAGE *package = dialog->package;
1370 prop = MSI_RecordGetString( rec, 9 );
1371 val = msi_dup_property( package, prop );
1372 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW,
1373 TVS_HASBUTTONS | WS_GROUP | WS_VSCROLL );
1374 if (!control)
1375 return ERROR_FUNCTION_FAILED;
1377 msi_dialog_tv_add_child_features( package, control->hwnd, NULL, NULL );
1379 msi_free( val );
1381 return ERROR_SUCCESS;
1384 struct control_handler msi_dialog_handler[] =
1386 { szText, msi_dialog_text_control },
1387 { szPushButton, msi_dialog_button_control },
1388 { szLine, msi_dialog_line_control },
1389 { szBitmap, msi_dialog_bitmap_control },
1390 { szCheckBox, msi_dialog_checkbox_control },
1391 { szScrollableText, msi_dialog_scrolltext_control },
1392 { szComboBox, msi_dialog_combo_control },
1393 { szEdit, msi_dialog_edit_control },
1394 { szMaskedEdit, msi_dialog_maskedit_control },
1395 { szPathEdit, msi_dialog_pathedit_control },
1396 { szProgressBar, msi_dialog_progress_bar },
1397 { szRadioButtonGroup, msi_dialog_radiogroup_control },
1398 { szIcon, msi_dialog_icon_control },
1399 { szSelectionTree, msi_dialog_selection_tree },
1402 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
1404 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
1406 msi_dialog *dialog = param;
1407 LPCWSTR control_type;
1408 UINT i;
1410 /* find and call the function that can create this type of control */
1411 control_type = MSI_RecordGetString( rec, 3 );
1412 for( i=0; i<NUM_CONTROL_TYPES; i++ )
1413 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
1414 break;
1415 if( i != NUM_CONTROL_TYPES )
1416 msi_dialog_handler[i].func( dialog, rec );
1417 else
1418 ERR("no handler for element type %s\n", debugstr_w(control_type));
1420 return ERROR_SUCCESS;
1423 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
1425 static const WCHAR query[] = {
1426 'S','E','L','E','C','T',' ','*',' ',
1427 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
1428 'W','H','E','R','E',' ',
1429 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
1430 UINT r;
1431 MSIQUERY *view = NULL;
1432 MSIPACKAGE *package = dialog->package;
1434 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1436 /* query the Control table for all the elements of the control */
1437 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1438 if( r != ERROR_SUCCESS )
1440 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1441 return ERROR_INVALID_PARAMETER;
1444 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
1445 msiobj_release( &view->hdr );
1447 return r;
1450 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
1452 static const WCHAR szHide[] = { 'H','i','d','e',0 };
1453 static const WCHAR szShow[] = { 'S','h','o','w',0 };
1454 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
1455 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
1456 msi_dialog *dialog = param;
1457 msi_control *control;
1458 LPCWSTR name, action, condition;
1459 UINT r;
1461 name = MSI_RecordGetString( rec, 2 );
1462 action = MSI_RecordGetString( rec, 3 );
1463 condition = MSI_RecordGetString( rec, 4 );
1464 r = MSI_EvaluateConditionW( dialog->package, condition );
1465 control = msi_dialog_find_control( dialog, name );
1466 if( r == MSICONDITION_TRUE && control )
1468 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
1470 /* FIXME: case sensitive? */
1471 if(!lstrcmpW(action, szHide))
1472 ShowWindow(control->hwnd, SW_HIDE);
1473 else if(!strcmpW(action, szShow))
1474 ShowWindow(control->hwnd, SW_SHOW);
1475 else if(!strcmpW(action, szDisable))
1476 EnableWindow(control->hwnd, FALSE);
1477 else if(!strcmpW(action, szEnable))
1478 EnableWindow(control->hwnd, TRUE);
1479 else
1480 FIXME("Unhandled action %s\n", debugstr_w(action));
1483 return ERROR_SUCCESS;
1486 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
1488 static const WCHAR query[] = {
1489 'S','E','L','E','C','T',' ','*',' ',
1490 'F','R','O','M',' ',
1491 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
1492 'W','H','E','R','E',' ',
1493 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
1495 UINT r;
1496 MSIQUERY *view = NULL;
1497 MSIPACKAGE *package = dialog->package;
1499 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1501 /* query the Control table for all the elements of the control */
1502 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
1503 if( r != ERROR_SUCCESS )
1505 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1506 return ERROR_INVALID_PARAMETER;
1509 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
1510 msiobj_release( &view->hdr );
1512 return r;
1515 /* figure out the height of 10 point MS Sans Serif */
1516 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
1518 static const WCHAR szSansSerif[] = {
1519 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
1520 LOGFONTW lf;
1521 TEXTMETRICW tm;
1522 BOOL r;
1523 LONG height = 0;
1524 HFONT hFont, hOldFont;
1525 HDC hdc;
1527 hdc = GetDC( hwnd );
1528 if (hdc)
1530 memset( &lf, 0, sizeof lf );
1531 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1532 strcpyW( lf.lfFaceName, szSansSerif );
1533 hFont = CreateFontIndirectW(&lf);
1534 if (hFont)
1536 hOldFont = SelectObject( hdc, hFont );
1537 r = GetTextMetricsW( hdc, &tm );
1538 if (r)
1539 height = tm.tmHeight;
1540 SelectObject( hdc, hOldFont );
1541 DeleteObject( hFont );
1543 ReleaseDC( hwnd, hdc );
1545 return height;
1548 /* fetch the associated record from the Dialog table */
1549 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
1551 static const WCHAR query[] = {
1552 'S','E','L','E','C','T',' ','*',' ',
1553 'F','R','O','M',' ','D','i','a','l','o','g',' ',
1554 'W','H','E','R','E',' ',
1555 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
1556 MSIPACKAGE *package = dialog->package;
1557 MSIRECORD *rec = NULL;
1559 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
1561 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
1562 if( !rec )
1563 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
1565 return rec;
1568 static void msi_dialog_adjust_dialog_size( msi_dialog *dialog, LPSIZE sz )
1570 RECT rect;
1571 LONG style;
1573 /* turn the client size into the window rectangle */
1574 rect.left = 0;
1575 rect.top = 0;
1576 rect.right = msi_dialog_scale_unit( dialog, sz->cx );
1577 rect.bottom = msi_dialog_scale_unit( dialog, sz->cy );
1578 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
1579 AdjustWindowRect( &rect, style, FALSE );
1580 sz->cx = rect.right - rect.left;
1581 sz->cy = rect.bottom - rect.top;
1584 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
1586 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
1587 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
1588 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
1591 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
1593 msi_control *control, *tab_next;
1595 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
1597 tab_next = msi_dialog_find_control( dialog, control->tabnext );
1598 if( !tab_next )
1599 continue;
1600 msi_control_set_next( control, tab_next );
1603 return ERROR_SUCCESS;
1606 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
1608 msi_control *control;
1610 control = msi_dialog_find_control( dialog, name );
1611 if( control )
1612 dialog->hWndFocus = control->hwnd;
1613 else
1614 dialog->hWndFocus = NULL;
1617 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
1619 static const WCHAR df[] = {
1620 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
1621 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
1622 MSIRECORD *rec = NULL;
1623 LPWSTR title = NULL;
1624 SIZE size;
1626 TRACE("%p %p\n", dialog, dialog->package);
1628 dialog->hwnd = hwnd;
1629 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
1631 rec = msi_get_dialog_record( dialog );
1632 if( !rec )
1634 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
1635 return -1;
1638 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
1640 size.cx = MSI_RecordGetInteger( rec, 4 );
1641 size.cy = MSI_RecordGetInteger( rec, 5 );
1642 msi_dialog_adjust_dialog_size( dialog, &size );
1644 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
1646 dialog->default_font = msi_dup_property( dialog->package, df );
1648 title = msi_get_deformatted_field( dialog->package, rec, 7 );
1649 SetWindowTextW( hwnd, title );
1650 msi_free( title );
1652 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy,
1653 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
1656 msi_dialog_build_font_list( dialog );
1657 msi_dialog_fill_controls( dialog );
1658 msi_dialog_evaluate_control_conditions( dialog );
1659 msi_dialog_set_tab_order( dialog );
1660 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
1661 msiobj_release( &rec->hdr );
1663 return 0;
1666 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1668 LPWSTR event_fmt = NULL, arg_fmt = NULL;
1670 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
1672 deformat_string( dialog->package, event, &event_fmt );
1673 deformat_string( dialog->package, arg, &arg_fmt );
1675 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
1677 msi_free( event_fmt );
1678 msi_free( arg_fmt );
1680 return ERROR_SUCCESS;
1683 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
1685 static const WCHAR szNullArg[] = { '{','}',0 };
1686 LPWSTR p, prop, arg_fmt = NULL;
1687 UINT len;
1689 len = strlenW(event);
1690 prop = msi_alloc( len*sizeof(WCHAR));
1691 strcpyW( prop, &event[1] );
1692 p = strchrW( prop, ']' );
1693 if( p && p[1] == 0 )
1695 *p = 0;
1696 if( strcmpW( szNullArg, arg ) )
1697 deformat_string( dialog->package, arg, &arg_fmt );
1698 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
1699 msi_free( arg_fmt );
1701 else
1702 ERR("Badly formatted property string - what happens?\n");
1703 msi_free( prop );
1704 return ERROR_SUCCESS;
1707 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
1709 msi_dialog *dialog = param;
1710 LPCWSTR condition, event, arg;
1711 UINT r;
1713 condition = MSI_RecordGetString( rec, 5 );
1714 r = MSI_EvaluateConditionW( dialog->package, condition );
1715 if( r == MSICONDITION_TRUE )
1717 event = MSI_RecordGetString( rec, 3 );
1718 arg = MSI_RecordGetString( rec, 4 );
1719 if( event[0] == '[' )
1720 msi_dialog_set_property( dialog, event, arg );
1721 else
1722 msi_dialog_send_event( dialog, event, arg );
1725 return ERROR_SUCCESS;
1728 static UINT msi_dialog_button_handler( msi_dialog *dialog,
1729 msi_control *control, WPARAM param )
1731 static const WCHAR query[] = {
1732 'S','E','L','E','C','T',' ','*',' ',
1733 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
1734 'W','H','E','R','E',' ',
1735 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
1736 'A','N','D',' ',
1737 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
1738 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
1740 MSIQUERY *view = NULL;
1741 UINT r;
1743 if( HIWORD(param) != BN_CLICKED )
1744 return ERROR_SUCCESS;
1746 r = MSI_OpenQuery( dialog->package->db, &view, query,
1747 dialog->name, control->name );
1748 if( r != ERROR_SUCCESS )
1750 ERR("query failed\n");
1751 return 0;
1754 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
1755 msiobj_release( &view->hdr );
1757 return r;
1760 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
1761 msi_control *control )
1763 WCHAR state[2] = { 0 };
1764 DWORD sz = 2;
1766 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
1767 return state[0] ? 1 : 0;
1770 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
1771 msi_control *control, UINT state )
1773 static const WCHAR szState[] = { '1', 0 };
1774 LPCWSTR val;
1776 /* if uncheck then the property is set to NULL */
1777 if (!state)
1779 MSI_SetPropertyW( dialog->package, control->property, NULL );
1780 return;
1783 /* check for a custom state */
1784 if (control->value && control->value[0])
1785 val = control->value;
1786 else
1787 val = szState;
1789 MSI_SetPropertyW( dialog->package, control->property, val );
1792 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
1793 msi_control *control )
1795 UINT state;
1797 state = msi_dialog_get_checkbox_state( dialog, control );
1798 SendMessageW( control->hwnd, BM_SETCHECK,
1799 state ? BST_CHECKED : BST_UNCHECKED, 0 );
1802 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
1803 msi_control *control, WPARAM param )
1805 UINT state;
1807 if( HIWORD(param) != BN_CLICKED )
1808 return ERROR_SUCCESS;
1810 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
1811 debugstr_w(control->property));
1813 state = msi_dialog_get_checkbox_state( dialog, control );
1814 state = state ? 0 : 1;
1815 msi_dialog_set_checkbox_state( dialog, control, state );
1816 msi_dialog_checkbox_sync_state( dialog, control );
1818 return msi_dialog_button_handler( dialog, control, param );
1821 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
1822 msi_control *control, WPARAM param )
1824 UINT sz, r;
1825 LPWSTR buf;
1827 if( HIWORD(param) != EN_CHANGE )
1828 return ERROR_SUCCESS;
1830 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1831 debugstr_w(control->property));
1833 sz = 0x20;
1834 buf = msi_alloc( sz*sizeof(WCHAR) );
1835 while( buf )
1837 r = GetWindowTextW( control->hwnd, buf, sz );
1838 if( r < (sz-1) )
1839 break;
1840 sz *= 2;
1841 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1844 MSI_SetPropertyW( dialog->package, control->property, buf );
1846 msi_free( buf );
1848 return ERROR_SUCCESS;
1851 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
1852 msi_control *control, WPARAM param )
1854 if( HIWORD(param) != BN_CLICKED )
1855 return ERROR_SUCCESS;
1857 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
1858 debugstr_w(control->property));
1860 MSI_SetPropertyW( dialog->package, control->property, control->name );
1862 return msi_dialog_button_handler( dialog, control, param );
1865 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
1867 msi_control *control = NULL;
1869 TRACE("%p %p %08x\n", dialog, hwnd, param);
1871 switch (param)
1873 case 1: /* enter */
1874 control = msi_dialog_find_control( dialog, dialog->control_default );
1875 break;
1876 case 2: /* escape */
1877 control = msi_dialog_find_control( dialog, dialog->control_cancel );
1878 break;
1879 default:
1880 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
1883 if( control )
1885 if( control->handler )
1887 control->handler( dialog, control, param );
1888 msi_dialog_evaluate_control_conditions( dialog );
1891 else
1892 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
1893 return 0;
1896 static void msi_dialog_setfocus( msi_dialog *dialog )
1898 HWND hwnd = dialog->hWndFocus;
1900 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
1901 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
1902 SetFocus( hwnd );
1903 dialog->hWndFocus = hwnd;
1906 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
1907 WPARAM wParam, LPARAM lParam )
1909 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
1911 TRACE("0x%04x\n", msg);
1913 switch (msg)
1915 case WM_CREATE:
1916 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
1918 case WM_COMMAND:
1919 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
1921 case WM_ACTIVATE:
1922 if( LOWORD(wParam) == WA_INACTIVE )
1923 dialog->hWndFocus = GetFocus();
1924 else
1925 msi_dialog_setfocus( dialog );
1926 return 0;
1928 case WM_SETFOCUS:
1929 msi_dialog_setfocus( dialog );
1930 return 0;
1932 /* bounce back to our subclassed static control */
1933 case WM_CTLCOLORSTATIC:
1934 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
1936 case WM_DESTROY:
1937 dialog->hwnd = NULL;
1938 return 0;
1940 return DefWindowProcW(hwnd, msg, wParam, lParam);
1943 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1945 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
1947 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
1949 if (msg == WM_COMMAND) /* Forward notifications to dialog */
1950 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
1952 return CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
1955 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
1956 WPARAM wParam, LPARAM lParam )
1958 msi_dialog *dialog = (msi_dialog*) lParam;
1960 TRACE("%d %p\n", msg, dialog);
1962 switch (msg)
1964 case WM_MSI_DIALOG_CREATE:
1965 return msi_dialog_run_message_loop( dialog );
1966 case WM_MSI_DIALOG_DESTROY:
1967 msi_dialog_destroy( dialog );
1968 return 0;
1970 return DefWindowProcW( hwnd, msg, wParam, lParam );
1973 /* functions that interface to other modules within MSI */
1975 msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
1976 msi_dialog_event_handler event_handler )
1978 MSIRECORD *rec = NULL;
1979 msi_dialog *dialog;
1981 TRACE("%p %s\n", package, debugstr_w(szDialogName));
1983 /* allocate the structure for the dialog to use */
1984 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
1985 if( !dialog )
1986 return NULL;
1987 strcpyW( dialog->name, szDialogName );
1988 msiobj_addref( &package->hdr );
1989 dialog->package = package;
1990 dialog->event_handler = event_handler;
1991 dialog->finished = 0;
1992 list_init( &dialog->controls );
1994 /* verify that the dialog exists */
1995 rec = msi_get_dialog_record( dialog );
1996 if( !rec )
1998 msiobj_release( &package->hdr );
1999 msi_free( dialog );
2000 return NULL;
2002 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2003 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
2004 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
2005 msiobj_release( &rec->hdr );
2007 return dialog;
2010 static void msi_process_pending_messages( HWND hdlg )
2012 MSG msg;
2014 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
2016 if( hdlg && IsDialogMessageW( hdlg, &msg ))
2017 continue;
2018 TranslateMessage( &msg );
2019 DispatchMessageW( &msg );
2023 void msi_dialog_end_dialog( msi_dialog *dialog )
2025 TRACE("%p\n", dialog);
2026 dialog->finished = 1;
2027 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
2030 void msi_dialog_check_messages( HANDLE handle )
2032 DWORD r;
2034 /* in threads other than the UI thread, block */
2035 if( uiThreadId != GetCurrentThreadId() )
2037 if( handle )
2038 WaitForSingleObject( handle, INFINITE );
2039 return;
2042 /* there's two choices for the UI thread */
2043 while (1)
2045 msi_process_pending_messages( NULL );
2047 if( !handle )
2048 break;
2051 * block here until somebody creates a new dialog or
2052 * the handle we're waiting on becomes ready
2054 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
2055 if( r == WAIT_OBJECT_0 )
2056 break;
2060 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
2062 HWND hwnd;
2064 if( !(dialog->attributes & msidbDialogAttributesVisible) )
2065 return ERROR_SUCCESS;
2067 if( uiThreadId != GetCurrentThreadId() )
2068 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
2070 /* create the dialog window, don't show it yet */
2071 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, WS_OVERLAPPEDWINDOW,
2072 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2073 NULL, NULL, NULL, dialog );
2074 if( !hwnd )
2076 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
2077 return ERROR_FUNCTION_FAILED;
2080 ShowWindow( hwnd, SW_SHOW );
2081 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
2083 if( dialog->attributes & msidbDialogAttributesModal )
2085 while( !dialog->finished )
2087 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
2088 msi_process_pending_messages( dialog->hwnd );
2091 else
2092 return ERROR_IO_PENDING;
2094 return ERROR_SUCCESS;
2097 void msi_dialog_do_preview( msi_dialog *dialog )
2099 TRACE("\n");
2100 dialog->attributes |= msidbDialogAttributesVisible;
2101 dialog->attributes &= ~msidbDialogAttributesModal;
2102 msi_dialog_run_message_loop( dialog );
2105 void msi_dialog_destroy( msi_dialog *dialog )
2107 if( uiThreadId != GetCurrentThreadId() )
2109 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
2110 return;
2113 if( dialog->hwnd )
2114 ShowWindow( dialog->hwnd, SW_HIDE );
2116 if( dialog->hwnd )
2117 DestroyWindow( dialog->hwnd );
2119 /* destroy the list of controls */
2120 while( !list_empty( &dialog->controls ) )
2122 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
2123 msi_control, entry );
2124 list_remove( &t->entry );
2125 /* leave dialog->hwnd - destroying parent destroys child windows */
2126 msi_free( t->property );
2127 msi_free( t->value );
2128 if( t->hBitmap )
2129 DeleteObject( t->hBitmap );
2130 if( t->hIcon )
2131 DestroyIcon( t->hIcon );
2132 msi_free( t->tabnext );
2133 msi_free( t );
2134 if (t->hDll)
2135 FreeLibrary( t->hDll );
2138 /* destroy the list of fonts */
2139 while( dialog->font_list )
2141 msi_font *t = dialog->font_list;
2142 dialog->font_list = t->next;
2143 DeleteObject( t->hfont );
2144 msi_free( t );
2146 msi_free( dialog->default_font );
2148 msi_free( dialog->control_default );
2149 msi_free( dialog->control_cancel );
2150 msiobj_release( &dialog->package->hdr );
2151 dialog->package = NULL;
2152 msi_free( dialog );
2155 BOOL msi_dialog_register_class( void )
2157 WNDCLASSW cls;
2159 ZeroMemory( &cls, sizeof cls );
2160 cls.lpfnWndProc = MSIDialog_WndProc;
2161 cls.hInstance = NULL;
2162 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
2163 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
2164 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
2165 cls.lpszMenuName = NULL;
2166 cls.lpszClassName = szMsiDialogClass;
2168 if( !RegisterClassW( &cls ) )
2169 return FALSE;
2171 cls.lpfnWndProc = MSIHiddenWindowProc;
2172 cls.lpszClassName = szMsiHiddenWindow;
2174 if( !RegisterClassW( &cls ) )
2175 return FALSE;
2177 uiThreadId = GetCurrentThreadId();
2179 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
2180 0, 0, 100, 100, NULL, NULL, NULL, NULL );
2181 if( !hMsiHiddenWindow )
2182 return FALSE;
2184 return TRUE;
2187 void msi_dialog_unregister_class( void )
2189 DestroyWindow( hMsiHiddenWindow );
2190 hMsiHiddenWindow = NULL;
2191 UnregisterClassW( szMsiDialogClass, NULL );
2192 UnregisterClassW( szMsiHiddenWindow, NULL );
2193 uiThreadId = 0;