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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(msi);
50 extern HINSTANCE msi_hInstance;
52 struct msi_control_tag;
53 typedef struct msi_control_tag msi_control;
54 typedef UINT (*msi_handler)( msi_dialog *, msi_control *, WPARAM );
56 struct msi_control_tag
68 float progress_current;
74 typedef struct msi_font_tag
76 struct msi_font_tag *next;
86 msi_dialog_event_handler event_handler;
96 LPWSTR control_default;
97 LPWSTR control_cancel;
101 typedef UINT (*msi_dialog_control_func)( msi_dialog *dialog, MSIRECORD *rec );
102 struct control_handler
104 LPCWSTR control_type;
105 msi_dialog_control_func func;
114 } radio_button_group_descr;
116 static const WCHAR szMsiDialogClass[] = {
117 'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
119 static const WCHAR szMsiHiddenWindow[] = {
120 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0 };
121 static const WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
122 static const WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
123 static const WCHAR szButtonData[] = { 'M','S','I','D','A','T','A',0 };
124 static const WCHAR szProgress[] = { 'P','r','o','g','r','e','s','s',0 };
125 static const WCHAR szText[] = { 'T','e','x','t',0 };
126 static const WCHAR szPushButton[] = { 'P','u','s','h','B','u','t','t','o','n',0 };
127 static const WCHAR szLine[] = { 'L','i','n','e',0 };
128 static const WCHAR szBitmap[] = { 'B','i','t','m','a','p',0 };
129 static const WCHAR szCheckBox[] = { 'C','h','e','c','k','B','o','x',0 };
130 static const WCHAR szScrollableText[] = {
131 'S','c','r','o','l','l','a','b','l','e','T','e','x','t',0 };
132 static const WCHAR szComboBox[] = { 'C','o','m','b','o','B','o','x',0 };
133 static const WCHAR szEdit[] = { 'E','d','i','t',0 };
134 static const WCHAR szMaskedEdit[] = { 'M','a','s','k','e','d','E','d','i','t',0 };
135 static const WCHAR szPathEdit[] = { 'P','a','t','h','E','d','i','t',0 };
136 static const WCHAR szProgressBar[] = {
137 'P','r','o','g','r','e','s','s','B','a','r',0 };
138 static const WCHAR szRadioButtonGroup[] = {
139 'R','a','d','i','o','B','u','t','t','o','n','G','r','o','u','p',0 };
140 static const WCHAR szIcon[] = { 'I','c','o','n',0 };
141 static const WCHAR szSelectionTree[] = {
142 'S','e','l','e','c','t','i','o','n','T','r','e','e',0 };
143 static const WCHAR szGroupBox[] = { 'G','r','o','u','p','B','o','x',0 };
144 static const WCHAR szListBox[] = { 'L','i','s','t','B','o','x',0 };
145 static const WCHAR szDirectoryCombo[] = { 'D','i','r','e','c','t','o','r','y','C','o','m','b','o',0 };
146 static const WCHAR szDirectoryList[] = { 'D','i','r','e','c','t','o','r','y','L','i','s','t',0 };
147 static const WCHAR szVolumeCostList[] = { 'V','o','l','u','m','e','C','o','s','t','L','i','s','t',0 };
149 static UINT msi_dialog_checkbox_handler( msi_dialog *, msi_control *, WPARAM );
150 static void msi_dialog_checkbox_sync_state( msi_dialog *, msi_control * );
151 static UINT msi_dialog_button_handler( msi_dialog *, msi_control *, WPARAM );
152 static UINT msi_dialog_edit_handler( msi_dialog *, msi_control *, WPARAM );
153 static UINT msi_dialog_radiogroup_handler( msi_dialog *, msi_control *, WPARAM param );
154 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog );
155 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
158 /* dialog sequencing */
160 #define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
161 #define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
163 static DWORD uiThreadId;
164 static HWND hMsiHiddenWindow;
166 static INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
168 return (dialog->scale * val + 5) / 10;
171 static msi_control *msi_dialog_find_control( msi_dialog *dialog, LPCWSTR name )
173 msi_control *control;
177 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
178 if( !strcmpW( control->name, name ) ) /* FIXME: case sensitive? */
183 static msi_control *msi_dialog_find_control_by_type( msi_dialog *dialog, LPCWSTR type )
185 msi_control *control;
189 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
190 if( !strcmpW( control->type, type ) ) /* FIXME: case sensitive? */
195 static msi_control *msi_dialog_find_control_by_hwnd( msi_dialog *dialog, HWND hwnd )
197 msi_control *control;
199 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
200 if( hwnd == control->hwnd )
205 static LPWSTR msi_get_deformatted_field( MSIPACKAGE *package, MSIRECORD *rec, int field )
207 LPCWSTR str = MSI_RecordGetString( rec, field );
211 deformat_string( package, str, &ret );
215 static LPWSTR msi_dialog_dup_property( msi_dialog *dialog, LPCWSTR property, BOOL indirect )
221 return msi_dup_property( dialog->package, property );
223 return strdupW( property );
226 msi_dialog *msi_dialog_get_parent( msi_dialog *dialog )
228 return dialog->parent;
231 LPWSTR msi_dialog_get_name( msi_dialog *dialog )
237 * msi_dialog_get_style
239 * Extract the {\style} string from the front of the text to display and
240 * update the pointer.
242 static LPWSTR msi_dialog_get_style( LPCWSTR p, LPCWSTR *rest )
253 q = strchrW( p, '}' );
256 if( *p == '\\' || *p == '&' )
259 /* little bit of sanity checking to stop us getting confused with RTF */
261 if( *i == '}' || *i == '\\' )
267 ret = msi_alloc( len*sizeof(WCHAR) );
270 memcpy( ret, p, len*sizeof(WCHAR) );
275 static UINT msi_dialog_add_font( MSIRECORD *rec, LPVOID param )
277 msi_dialog *dialog = param;
284 /* create a font and add it to the list */
285 name = MSI_RecordGetString( rec, 1 );
286 font = msi_alloc( sizeof *font + strlenW( name )*sizeof (WCHAR) );
287 strcpyW( font->name, name );
288 font->next = dialog->font_list;
289 dialog->font_list = font;
291 font->color = MSI_RecordGetInteger( rec, 4 );
293 memset( &lf, 0, sizeof lf );
294 face = MSI_RecordGetString( rec, 2 );
295 lf.lfHeight = MSI_RecordGetInteger( rec, 3 );
296 style = MSI_RecordGetInteger( rec, 5 );
297 if( style & msidbTextStyleStyleBitsBold )
298 lf.lfWeight = FW_BOLD;
299 if( style & msidbTextStyleStyleBitsItalic )
301 if( style & msidbTextStyleStyleBitsUnderline )
302 lf.lfUnderline = TRUE;
303 if( style & msidbTextStyleStyleBitsStrike )
304 lf.lfStrikeOut = TRUE;
305 lstrcpynW( lf.lfFaceName, face, LF_FACESIZE );
307 /* adjust the height */
308 hdc = GetDC( dialog->hwnd );
311 lf.lfHeight = -MulDiv(lf.lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
312 ReleaseDC( dialog->hwnd, hdc );
315 font->hfont = CreateFontIndirectW( &lf );
317 TRACE("Adding font style %s\n", debugstr_w(font->name) );
319 return ERROR_SUCCESS;
322 static msi_font *msi_dialog_find_font( msi_dialog *dialog, LPCWSTR name )
326 for( font = dialog->font_list; font; font = font->next )
327 if( !strcmpW( font->name, name ) ) /* FIXME: case sensitive? */
333 static UINT msi_dialog_set_font( msi_dialog *dialog, HWND hwnd, LPCWSTR name )
337 font = msi_dialog_find_font( dialog, name );
339 SendMessageW( hwnd, WM_SETFONT, (WPARAM) font->hfont, TRUE );
341 ERR("No font entry for %s\n", debugstr_w(name));
342 return ERROR_SUCCESS;
345 static UINT msi_dialog_build_font_list( msi_dialog *dialog )
347 static const WCHAR query[] = {
348 'S','E','L','E','C','T',' ','*',' ',
349 'F','R','O','M',' ','`','T','e','x','t','S','t','y','l','e','`',' ',0
352 MSIQUERY *view = NULL;
354 TRACE("dialog %p\n", dialog );
356 r = MSI_OpenQuery( dialog->package->db, &view, query );
357 if( r != ERROR_SUCCESS )
360 r = MSI_IterateRecords( view, NULL, msi_dialog_add_font, dialog );
361 msiobj_release( &view->hdr );
366 static msi_control *msi_dialog_create_window( msi_dialog *dialog,
367 MSIRECORD *rec, DWORD exstyle, LPCWSTR szCls, LPCWSTR name, LPCWSTR text,
368 DWORD style, HWND parent )
370 DWORD x, y, width, height;
371 LPWSTR font = NULL, title_font = NULL;
372 LPCWSTR title = NULL;
373 msi_control *control;
377 control = msi_alloc( sizeof *control + strlenW(name)*sizeof(WCHAR) );
378 strcpyW( control->name, name );
379 list_add_head( &dialog->controls, &control->entry );
380 control->handler = NULL;
381 control->property = NULL;
382 control->value = NULL;
383 control->hBitmap = NULL;
384 control->hIcon = NULL;
385 control->hDll = NULL;
386 control->tabnext = strdupW( MSI_RecordGetString( rec, 11) );
387 control->type = strdupW( MSI_RecordGetString( rec, 3 ) );
388 control->progress_current = 0;
389 control->progress_max = 100;
391 x = MSI_RecordGetInteger( rec, 4 );
392 y = MSI_RecordGetInteger( rec, 5 );
393 width = MSI_RecordGetInteger( rec, 6 );
394 height = MSI_RecordGetInteger( rec, 7 );
396 x = msi_dialog_scale_unit( dialog, x );
397 y = msi_dialog_scale_unit( dialog, y );
398 width = msi_dialog_scale_unit( dialog, width );
399 height = msi_dialog_scale_unit( dialog, height );
403 deformat_string( dialog->package, text, &title_font );
404 font = msi_dialog_get_style( title_font, &title );
407 control->hwnd = CreateWindowExW( exstyle, szCls, title, style,
408 x, y, width, height, parent, NULL, NULL, NULL );
410 TRACE("Dialog %s control %s hwnd %p\n",
411 debugstr_w(dialog->name), debugstr_w(text), control->hwnd );
413 msi_dialog_set_font( dialog, control->hwnd,
414 font ? font : dialog->default_font );
416 msi_free( title_font );
422 static LPWSTR msi_dialog_get_uitext( msi_dialog *dialog, LPCWSTR key )
427 static const WCHAR query[] = {
428 's','e','l','e','c','t',' ','*',' ',
429 'f','r','o','m',' ','`','U','I','T','e','x','t','`',' ',
430 'w','h','e','r','e',' ','`','K','e','y','`',' ','=',' ','\'','%','s','\'',0
433 rec = MSI_QueryGetRecord( dialog->package->db, query, key );
434 if (!rec) return NULL;
435 text = strdupW( MSI_RecordGetString( rec, 2 ) );
436 msiobj_release( &rec->hdr );
440 static MSIRECORD *msi_get_binary_record( MSIDATABASE *db, LPCWSTR name )
442 static const WCHAR query[] = {
443 's','e','l','e','c','t',' ','*',' ',
444 'f','r','o','m',' ','B','i','n','a','r','y',' ',
445 'w','h','e','r','e',' ',
446 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0
449 return MSI_QueryGetRecord( db, query, name );
452 static LPWSTR msi_create_tmp_path(void)
456 static const WCHAR prefix[] = { 'm','s','i',0 };
459 r = GetTempPathW( MAX_PATH, tmp );
462 len = lstrlenW( tmp ) + 20;
463 path = msi_alloc( len * sizeof (WCHAR) );
466 r = GetTempFileNameW( tmp, prefix, 0, path );
477 static HANDLE msi_load_image( MSIDATABASE *db, LPCWSTR name, UINT type,
478 UINT cx, UINT cy, UINT flags )
480 MSIRECORD *rec = NULL;
481 HANDLE himage = NULL;
485 TRACE("%p %s %u %u %08x\n", db, debugstr_w(name), cx, cy, flags);
487 tmp = msi_create_tmp_path();
491 rec = msi_get_binary_record( db, name );
494 r = MSI_RecordStreamToFile( rec, 2, tmp );
495 if( r == ERROR_SUCCESS )
497 himage = LoadImageW( 0, tmp, type, cx, cy, flags );
500 msiobj_release( &rec->hdr );
507 static HICON msi_load_icon( MSIDATABASE *db, LPCWSTR text, UINT attributes )
509 DWORD cx = 0, cy = 0, flags;
511 flags = LR_LOADFROMFILE | LR_DEFAULTSIZE;
512 if( attributes & msidbControlAttributesFixedSize )
514 flags &= ~LR_DEFAULTSIZE;
515 if( attributes & msidbControlAttributesIconSize16 )
520 if( attributes & msidbControlAttributesIconSize32 )
525 /* msidbControlAttributesIconSize48 handled by above logic */
527 return msi_load_image( db, text, IMAGE_ICON, cx, cy, flags );
531 /* called from the Control Event subscription code */
532 void msi_dialog_handle_event( msi_dialog* dialog, LPCWSTR control,
533 LPCWSTR attribute, MSIRECORD *rec )
536 LPCWSTR font_text, text = NULL;
539 static const WCHAR empty[] = {0};
541 ctrl = msi_dialog_find_control( dialog, control );
544 if( !lstrcmpW(attribute, szText) )
546 font_text = MSI_RecordGetString( rec , 1 );
547 font = msi_dialog_get_style( font_text, &text );
548 if (!text) text = empty;
549 SetWindowTextW( ctrl->hwnd, text );
551 msi_dialog_check_messages( NULL );
553 else if( !lstrcmpW(attribute, szProgress) )
557 func = MSI_RecordGetInteger( rec , 1 );
558 val = MSI_RecordGetInteger( rec , 2 );
563 ctrl->progress_max = val;
564 ctrl->progress_current = 0;
565 SendMessageW(ctrl->hwnd, PBM_SETRANGE, 0, MAKELPARAM(0,100));
566 SendMessageW(ctrl->hwnd, PBM_SETPOS, 0, 0);
568 case 1: /* FIXME: not sure what this is supposed to do */
571 ctrl->progress_current += val;
572 SendMessageW(ctrl->hwnd, PBM_SETPOS, 100*(ctrl->progress_current/ctrl->progress_max), 0);
575 ERR("Unknown progress message %ld\n", func);
581 FIXME("Attribute %s not being set\n", debugstr_w(attribute));
586 static void msi_dialog_map_events(msi_dialog* dialog, LPCWSTR control)
588 static const WCHAR Query[] = {
589 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
590 '`','E','v','e','n','t','M','a','p','p','i','n','g','`',' ',
591 'W','H','E','R','E',' ',
592 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
594 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',0
597 LPCWSTR event, attribute;
599 row = MSI_QueryGetRecord( dialog->package->db, Query, dialog->name, control );
603 event = MSI_RecordGetString( row, 3 );
604 attribute = MSI_RecordGetString( row, 4 );
605 ControlEvent_SubscribeToEvent( dialog->package, event, control, attribute );
606 msiobj_release( &row->hdr );
609 /* everything except radio buttons */
610 static msi_control *msi_dialog_add_control( msi_dialog *dialog,
611 MSIRECORD *rec, LPCWSTR szCls, DWORD style )
617 name = MSI_RecordGetString( rec, 2 );
618 attributes = MSI_RecordGetInteger( rec, 8 );
619 text = MSI_RecordGetString( rec, 10 );
620 if( attributes & msidbControlAttributesVisible )
622 if( ~attributes & msidbControlAttributesEnabled )
623 style |= WS_DISABLED;
624 if( attributes & msidbControlAttributesSunken )
625 exstyle |= WS_EX_CLIENTEDGE;
627 msi_dialog_map_events(dialog, name);
629 return msi_dialog_create_window( dialog, rec, exstyle, szCls, name,
630 text, style, dialog->hwnd );
641 * we don't erase our own background,
642 * so we have to make sure that the parent window redraws first
644 static void msi_text_on_settext( HWND hWnd )
649 hParent = GetParent( hWnd );
650 GetWindowRect( hWnd, &rc );
651 MapWindowPoints( NULL, hParent, (LPPOINT) &rc, 2 );
652 InvalidateRect( hParent, &rc, TRUE );
655 static LRESULT WINAPI
656 MSIText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
658 struct msi_text_info *info;
661 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
663 info = GetPropW(hWnd, szButtonData);
666 SetTextColor( (HDC)wParam, info->font->color );
668 if( msg == WM_CTLCOLORSTATIC &&
669 ( info->attributes & msidbControlAttributesTransparent ) )
671 SetBkMode( (HDC)wParam, TRANSPARENT );
672 return (LRESULT) GetStockObject(NULL_BRUSH);
675 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
680 msi_text_on_settext( hWnd );
684 RemovePropW( hWnd, szButtonData );
691 static UINT msi_dialog_text_control( msi_dialog *dialog, MSIRECORD *rec )
693 msi_control *control;
694 struct msi_text_info *info;
698 TRACE("%p %p\n", dialog, rec);
700 control = msi_dialog_add_control( dialog, rec, szStatic, SS_LEFT | WS_GROUP );
702 return ERROR_FUNCTION_FAILED;
704 info = msi_alloc( sizeof *info );
706 return ERROR_SUCCESS;
708 text = MSI_RecordGetString( rec, 10 );
709 font_name = msi_dialog_get_style( text, &ptr );
710 info->font = ( font_name ) ? msi_dialog_find_font( dialog, font_name ) : NULL;
711 msi_free( font_name );
713 info->attributes = MSI_RecordGetInteger( rec, 8 );
714 if( info->attributes & msidbControlAttributesTransparent )
715 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT );
717 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
718 (LONG_PTR)MSIText_WndProc );
719 SetPropW( control->hwnd, szButtonData, info );
721 return ERROR_SUCCESS;
724 static UINT msi_dialog_button_control( msi_dialog *dialog, MSIRECORD *rec )
726 msi_control *control;
727 UINT attributes, style;
730 TRACE("%p %p\n", dialog, rec);
733 attributes = MSI_RecordGetInteger( rec, 8 );
734 if( attributes & msidbControlAttributesIcon )
737 control = msi_dialog_add_control( dialog, rec, szButton, style );
739 return ERROR_FUNCTION_FAILED;
741 control->handler = msi_dialog_button_handler;
744 text = msi_get_deformatted_field( dialog->package, rec, 10 );
745 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
746 if( attributes & msidbControlAttributesIcon )
747 SendMessageW( control->hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM) control->hIcon );
750 return ERROR_SUCCESS;
753 static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop )
755 static const WCHAR query[] = {
756 'S','E','L','E','C','T',' ','*',' ',
757 'F','R','O','M',' ','`','C','h','e','c','k','B','o','x',' ','`',
758 'W','H','E','R','E',' ',
759 '`','P','r','o','p','e','r','t','y','`',' ','=',' ',
762 MSIRECORD *rec = NULL;
765 /* find if there is a value associated with the checkbox */
766 rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
770 ret = msi_get_deformatted_field( dialog->package, rec, 2 );
776 msiobj_release( &rec->hdr );
780 ret = msi_dup_property( dialog->package, prop );
790 static UINT msi_dialog_checkbox_control( msi_dialog *dialog, MSIRECORD *rec )
792 msi_control *control;
795 TRACE("%p %p\n", dialog, rec);
797 control = msi_dialog_add_control( dialog, rec, szButton,
798 BS_CHECKBOX | BS_MULTILINE | WS_TABSTOP );
799 control->handler = msi_dialog_checkbox_handler;
800 prop = MSI_RecordGetString( rec, 9 );
803 control->property = strdupW( prop );
804 control->value = msi_get_checkbox_value( dialog, prop );
805 TRACE("control %s value %s\n", debugstr_w(control->property),
806 debugstr_w(control->value));
808 msi_dialog_checkbox_sync_state( dialog, control );
810 return ERROR_SUCCESS;
813 static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
815 TRACE("%p %p\n", dialog, rec);
817 /* line is exactly 2 units in height */
818 MSI_RecordSetInteger( rec, 7, 2 );
820 msi_dialog_add_control( dialog, rec, szStatic, SS_ETCHEDHORZ | SS_SUNKEN );
821 return ERROR_SUCCESS;
824 /******************** Scroll Text ********************************************/
826 struct msi_scrolltext_info
829 msi_control *control;
833 static LRESULT WINAPI
834 MSIScrollText_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
836 struct msi_scrolltext_info *info;
839 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
841 info = GetPropW( hWnd, szButtonData );
843 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
849 RemovePropW( hWnd, szButtonData );
852 /* native MSI sets a wait cursor here */
853 msi_dialog_button_handler( info->dialog, info->control, BN_CLICKED );
859 struct msi_streamin_info
866 static DWORD CALLBACK
867 msi_richedit_stream_in( DWORD_PTR arg, LPBYTE buffer, LONG count, LONG *pcb )
869 struct msi_streamin_info *info = (struct msi_streamin_info*) arg;
871 if( (count + info->offset) > info->length )
872 count = info->length - info->offset;
873 memcpy( buffer, &info->string[ info->offset ], count );
875 info->offset += count;
877 TRACE("%ld/%ld\n", info->offset, info->length);
882 static void msi_scrolltext_add_text( msi_control *control, LPCWSTR text )
884 struct msi_streamin_info info;
887 info.string = strdupWtoA( text );
889 info.length = lstrlenA( info.string ) + 1;
891 es.dwCookie = (DWORD_PTR) &info;
893 es.pfnCallback = msi_richedit_stream_in;
895 SendMessageW( control->hwnd, EM_STREAMIN, SF_RTF, (LPARAM) &es );
897 msi_free( info.string );
900 static UINT msi_dialog_scrolltext_control( msi_dialog *dialog, MSIRECORD *rec )
902 static const WCHAR szRichEdit20W[] = {
903 'R','i','c','h','E','d','i','t','2','0','W',0
905 struct msi_scrolltext_info *info;
906 msi_control *control;
910 info = msi_alloc( sizeof *info );
912 return ERROR_FUNCTION_FAILED;
914 hRichedit = LoadLibraryA("riched20");
916 style = WS_BORDER | ES_MULTILINE | WS_VSCROLL |
917 ES_READONLY | ES_AUTOVSCROLL | WS_TABSTOP;
918 control = msi_dialog_add_control( dialog, rec, szRichEdit20W, style );
921 FreeLibrary( hRichedit );
923 return ERROR_FUNCTION_FAILED;
926 control->hDll = hRichedit;
928 info->dialog = dialog;
929 info->control = control;
931 /* subclass the static control */
932 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
933 (LONG_PTR)MSIScrollText_WndProc );
934 SetPropW( control->hwnd, szButtonData, info );
936 /* add the text into the richedit */
937 msi_scrolltext_add_text( control, MSI_RecordGetString( rec, 10 ) );
939 return ERROR_SUCCESS;
942 static HBITMAP msi_load_picture( MSIDATABASE *db, LPCWSTR name,
943 INT cx, INT cy, DWORD flags )
945 HBITMAP hOleBitmap = 0, hBitmap = 0, hOldSrcBitmap, hOldDestBitmap;
946 MSIRECORD *rec = NULL;
948 IPicture *pic = NULL;
953 rec = msi_get_binary_record( db, name );
957 r = MSI_RecordGetIStream( rec, 2, &stm );
958 msiobj_release( &rec->hdr );
959 if( r != ERROR_SUCCESS )
962 r = OleLoadPicture( stm, 0, TRUE, &IID_IPicture, (LPVOID*) &pic );
963 IStream_Release( stm );
966 ERR("failed to load picture\n");
970 r = IPicture_get_Handle( pic, (OLE_HANDLE*) &hOleBitmap );
973 ERR("failed to get bitmap handle\n");
977 /* make the bitmap the desired size */
978 r = GetObjectW( hOleBitmap, sizeof bm, &bm );
981 ERR("failed to get bitmap size\n");
985 if (flags & LR_DEFAULTSIZE)
991 srcdc = CreateCompatibleDC( NULL );
992 hOldSrcBitmap = SelectObject( srcdc, hOleBitmap );
993 destdc = CreateCompatibleDC( NULL );
994 hBitmap = CreateCompatibleBitmap( srcdc, cx, cy );
995 hOldDestBitmap = SelectObject( destdc, hBitmap );
996 StretchBlt( destdc, 0, 0, cx, cy,
997 srcdc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
998 SelectObject( srcdc, hOldSrcBitmap );
999 SelectObject( destdc, hOldDestBitmap );
1005 IPicture_Release( pic );
1009 static UINT msi_dialog_bitmap_control( msi_dialog *dialog, MSIRECORD *rec )
1011 UINT cx, cy, flags, style, attributes;
1012 msi_control *control;
1015 flags = LR_LOADFROMFILE;
1016 style = SS_BITMAP | SS_LEFT | WS_GROUP;
1018 attributes = MSI_RecordGetInteger( rec, 8 );
1019 if( attributes & msidbControlAttributesFixedSize )
1021 flags |= LR_DEFAULTSIZE;
1022 style |= SS_CENTERIMAGE;
1025 control = msi_dialog_add_control( dialog, rec, szStatic, style );
1026 cx = MSI_RecordGetInteger( rec, 6 );
1027 cy = MSI_RecordGetInteger( rec, 7 );
1028 cx = msi_dialog_scale_unit( dialog, cx );
1029 cy = msi_dialog_scale_unit( dialog, cy );
1031 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1032 control->hBitmap = msi_load_picture( dialog->package->db, text, cx, cy, flags );
1033 if( control->hBitmap )
1034 SendMessageW( control->hwnd, STM_SETIMAGE,
1035 IMAGE_BITMAP, (LPARAM) control->hBitmap );
1037 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1041 return ERROR_SUCCESS;
1044 static UINT msi_dialog_icon_control( msi_dialog *dialog, MSIRECORD *rec )
1046 msi_control *control;
1052 control = msi_dialog_add_control( dialog, rec, szStatic,
1053 SS_ICON | SS_CENTERIMAGE | WS_GROUP );
1055 attributes = MSI_RecordGetInteger( rec, 8 );
1056 text = msi_get_deformatted_field( dialog->package, rec, 10 );
1057 control->hIcon = msi_load_icon( dialog->package->db, text, attributes );
1058 if( control->hIcon )
1059 SendMessageW( control->hwnd, STM_SETICON, (WPARAM) control->hIcon, 0 );
1061 ERR("Failed to load bitmap %s\n", debugstr_w(text));
1063 return ERROR_SUCCESS;
1066 static UINT msi_dialog_combo_control( msi_dialog *dialog, MSIRECORD *rec )
1068 static const WCHAR szCombo[] = { 'C','O','M','B','O','B','O','X',0 };
1070 msi_dialog_add_control( dialog, rec, szCombo,
1071 SS_BITMAP | SS_LEFT | SS_CENTERIMAGE );
1072 return ERROR_SUCCESS;
1075 static UINT msi_dialog_edit_control( msi_dialog *dialog, MSIRECORD *rec )
1077 msi_control *control;
1081 control = msi_dialog_add_control( dialog, rec, szEdit,
1082 WS_BORDER | WS_TABSTOP );
1083 control->handler = msi_dialog_edit_handler;
1084 prop = MSI_RecordGetString( rec, 9 );
1086 control->property = strdupW( prop );
1087 val = msi_dup_property( dialog->package, control->property );
1088 SetWindowTextW( control->hwnd, val );
1090 return ERROR_SUCCESS;
1093 /******************** Masked Edit ********************************************/
1095 #define MASK_MAX_GROUPS 20
1097 struct msi_mask_group
1105 struct msi_maskedit_info
1113 struct msi_mask_group group[MASK_MAX_GROUPS];
1116 static BOOL msi_mask_editable( WCHAR type )
1131 static void msi_mask_control_change( struct msi_maskedit_info *info )
1136 val = msi_alloc( (info->num_chars+1)*sizeof(WCHAR) );
1137 for( i=0, n=0; i<info->num_groups; i++ )
1139 if( (info->group[i].len + n) > info->num_chars )
1141 ERR("can't fit control %d text into template\n",i);
1144 if (!msi_mask_editable(info->group[i].type))
1146 for(r=0; r<info->group[i].len; r++)
1147 val[n+r] = info->group[i].type;
1152 r = GetWindowTextW( info->group[i].hwnd, &val[n], info->group[i].len+1 );
1153 if( r != info->group[i].len )
1159 TRACE("%d/%d controls were good\n", i, info->num_groups);
1161 if( i == info->num_groups )
1163 TRACE("Set property %s to %s\n",
1164 debugstr_w(info->prop), debugstr_w(val) );
1165 CharUpperBuffW( val, info->num_chars );
1166 MSI_SetPropertyW( info->dialog->package, info->prop, val );
1167 msi_dialog_evaluate_control_conditions( info->dialog );
1172 /* now move to the next control if necessary */
1173 static VOID msi_mask_next_control( struct msi_maskedit_info *info, HWND hWnd )
1178 for( i=0; i<info->num_groups; i++ )
1179 if( info->group[i].hwnd == hWnd )
1182 /* don't move from the last control */
1183 if( i >= (info->num_groups-1) )
1186 len = SendMessageW( hWnd, WM_GETTEXTLENGTH, 0, 0 );
1187 if( len < info->group[i].len )
1190 hWndNext = GetNextDlgTabItem( GetParent( hWnd ), hWnd, FALSE );
1191 SetFocus( hWndNext );
1194 static LRESULT WINAPI
1195 MSIMaskedEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1197 struct msi_maskedit_info *info;
1200 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1202 info = GetPropW(hWnd, szButtonData);
1204 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1209 if (HIWORD(wParam) == EN_CHANGE)
1211 msi_mask_control_change( info );
1212 msi_mask_next_control( info, (HWND) lParam );
1216 msi_free( info->prop );
1218 RemovePropW( hWnd, szButtonData );
1225 /* fish the various bits of the property out and put them in the control */
1227 msi_maskedit_set_text( struct msi_maskedit_info *info, LPCWSTR text )
1233 for( i = 0; i < info->num_groups; i++ )
1235 if( info->group[i].len < lstrlenW( p ) )
1237 LPWSTR chunk = strdupW( p );
1238 chunk[ info->group[i].len ] = 0;
1239 SetWindowTextW( info->group[i].hwnd, chunk );
1244 SetWindowTextW( info->group[i].hwnd, p );
1247 p += info->group[i].len;
1251 static struct msi_maskedit_info * msi_dialog_parse_groups( LPCWSTR mask )
1253 struct msi_maskedit_info * info = NULL;
1254 int i = 0, n = 0, total = 0;
1257 TRACE("masked control, template %s\n", debugstr_w(mask));
1262 info = msi_alloc_zero( sizeof *info );
1266 p = strchrW(mask, '<');
1272 for( i=0; i<MASK_MAX_GROUPS; i++ )
1274 /* stop at the end of the string */
1275 if( p[0] == 0 || p[0] == '>' )
1278 /* count the number of the same identifier */
1279 for( n=0; p[n] == p[0]; n++ )
1281 info->group[i].ofs = total;
1282 info->group[i].type = p[0];
1286 total++; /* an extra not part of the group */
1288 info->group[i].len = n;
1293 TRACE("%d characters in %d groups\n", total, i );
1294 if( i == MASK_MAX_GROUPS )
1295 ERR("too many groups in PIDTemplate %s\n", debugstr_w(mask));
1297 info->num_chars = total;
1298 info->num_groups = i;
1304 msi_maskedit_create_children( struct msi_maskedit_info *info, LPCWSTR font )
1306 DWORD width, height, style, wx, ww;
1311 style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL;
1313 GetClientRect( info->hwnd, &rect );
1315 width = rect.right - rect.left;
1316 height = rect.bottom - rect.top;
1318 for( i = 0; i < info->num_groups; i++ )
1320 if (!msi_mask_editable( info->group[i].type ))
1322 wx = (info->group[i].ofs * width) / info->num_chars;
1323 ww = (info->group[i].len * width) / info->num_chars;
1325 hwnd = CreateWindowW( szEdit, NULL, style, wx, 0, ww, height,
1326 info->hwnd, NULL, NULL, NULL );
1329 ERR("failed to create mask edit sub window\n");
1333 SendMessageW( hwnd, EM_LIMITTEXT, info->group[i].len, 0 );
1335 msi_dialog_set_font( info->dialog, hwnd,
1336 font?font:info->dialog->default_font );
1337 info->group[i].hwnd = hwnd;
1342 * office 2003 uses "73931<````=````=````=````=`````>@@@@@"
1343 * delphi 7 uses "<????-??????-??????-????>" and "<???-???>"
1344 * filemaker pro 7 uses "<^^^^=^^^^=^^^^=^^^^=^^^^=^^^^=^^^^^>"
1346 static UINT msi_dialog_maskedit_control( msi_dialog *dialog, MSIRECORD *rec )
1348 LPWSTR font_mask, val = NULL, font;
1349 struct msi_maskedit_info *info = NULL;
1350 UINT ret = ERROR_SUCCESS;
1351 msi_control *control;
1356 font_mask = msi_get_deformatted_field( dialog->package, rec, 10 );
1357 font = msi_dialog_get_style( font_mask, &mask );
1360 ERR("mask template is empty\n");
1364 info = msi_dialog_parse_groups( mask );
1367 ERR("template %s is invalid\n", debugstr_w(mask));
1371 info->dialog = dialog;
1373 control = msi_dialog_add_control( dialog, rec, szStatic,
1374 SS_OWNERDRAW | WS_GROUP | WS_VISIBLE );
1377 ERR("Failed to create maskedit container\n");
1378 ret = ERROR_FUNCTION_FAILED;
1381 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1383 info->hwnd = control->hwnd;
1385 /* subclass the static control */
1386 info->oldproc = (WNDPROC) SetWindowLongPtrW( info->hwnd, GWLP_WNDPROC,
1387 (LONG_PTR)MSIMaskedEdit_WndProc );
1388 SetPropW( control->hwnd, szButtonData, info );
1390 prop = MSI_RecordGetString( rec, 9 );
1392 info->prop = strdupW( prop );
1394 msi_maskedit_create_children( info, font );
1398 val = msi_dup_property( dialog->package, prop );
1401 msi_maskedit_set_text( info, val );
1407 if( ret != ERROR_SUCCESS )
1409 msi_free( font_mask );
1414 /******************** Progress Bar *****************************************/
1416 static UINT msi_dialog_progress_bar( msi_dialog *dialog, MSIRECORD *rec )
1418 msi_dialog_add_control( dialog, rec, PROGRESS_CLASSW, WS_VISIBLE );
1419 return ERROR_SUCCESS;
1422 /******************** Path Edit ********************************************/
1424 struct msi_pathedit_info
1427 msi_control *control;
1431 static LPWSTR msi_get_window_text( HWND hwnd )
1437 buf = msi_alloc( sz*sizeof(WCHAR) );
1440 r = GetWindowTextW( hwnd, buf, sz );
1444 buf = msi_realloc( buf, sz*sizeof(WCHAR) );
1450 static void msi_dialog_update_pathedit( msi_dialog *dialog, msi_control *control )
1455 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szPathEdit )))
1458 indirect = control->attributes & msidbControlAttributesIndirect;
1459 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1461 path = msi_dup_property( dialog->package, prop );
1465 SetWindowTextW( control->hwnd, path );
1466 SendMessageW( control->hwnd, EM_SETSEL, 0, -1 );
1472 /* FIXME: test when this should fail */
1473 static BOOL msi_dialog_verify_path( LPWSTR path )
1475 if ( !lstrlenW( path ) )
1478 if ( PathIsRelativeW( path ) )
1484 /* returns TRUE if the path is valid, FALSE otherwise */
1485 static BOOL msi_dialog_onkillfocus( msi_dialog *dialog, msi_control *control )
1491 indirect = control->attributes & msidbControlAttributesIndirect;
1492 prop = msi_dialog_dup_property( dialog, control->property, indirect );
1494 buf = msi_get_window_text( control->hwnd );
1496 if ( !msi_dialog_verify_path( buf ) )
1498 /* FIXME: display an error message box */
1499 ERR("Invalid path %s\n", debugstr_w( buf ));
1501 SetFocus( control->hwnd );
1506 MSI_SetPropertyW( dialog->package, prop, buf );
1509 msi_dialog_update_pathedit( dialog, control );
1511 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
1520 static LRESULT WINAPI MSIPathEdit_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1522 struct msi_pathedit_info *info = GetPropW(hWnd, szButtonData);
1525 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1527 if ( msg == WM_KILLFOCUS )
1529 /* if the path is invalid, don't handle this message */
1530 if ( !msi_dialog_onkillfocus( info->dialog, info->control ) )
1534 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1536 if ( msg == WM_NCDESTROY )
1539 RemovePropW( hWnd, szButtonData );
1545 static UINT msi_dialog_pathedit_control( msi_dialog *dialog, MSIRECORD *rec )
1547 struct msi_pathedit_info *info;
1548 msi_control *control;
1551 info = msi_alloc( sizeof *info );
1553 return ERROR_FUNCTION_FAILED;
1555 control = msi_dialog_add_control( dialog, rec, szEdit,
1556 WS_BORDER | WS_TABSTOP );
1557 control->attributes = MSI_RecordGetInteger( rec, 8 );
1558 prop = MSI_RecordGetString( rec, 9 );
1559 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
1561 info->dialog = dialog;
1562 info->control = control;
1563 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1564 (LONG_PTR)MSIPathEdit_WndProc );
1565 SetPropW( control->hwnd, szButtonData, info );
1567 msi_dialog_update_pathedit( dialog, control );
1569 return ERROR_SUCCESS;
1572 /* radio buttons are a bit different from normal controls */
1573 static UINT msi_dialog_create_radiobutton( MSIRECORD *rec, LPVOID param )
1575 radio_button_group_descr *group = (radio_button_group_descr *)param;
1576 msi_dialog *dialog = group->dialog;
1577 msi_control *control;
1578 LPCWSTR prop, text, name;
1579 DWORD style, attributes = group->attributes;
1581 style = WS_CHILD | BS_AUTORADIOBUTTON | BS_MULTILINE | WS_TABSTOP;
1582 name = MSI_RecordGetString( rec, 3 );
1583 text = MSI_RecordGetString( rec, 8 );
1584 if( attributes & 1 )
1585 style |= WS_VISIBLE;
1586 if( ~attributes & 2 )
1587 style |= WS_DISABLED;
1589 control = msi_dialog_create_window( dialog, rec, 0, szButton, name, text,
1590 style, group->parent->hwnd );
1592 return ERROR_FUNCTION_FAILED;
1593 control->handler = msi_dialog_radiogroup_handler;
1595 if (!lstrcmpW(control->name, group->propval))
1596 SendMessageW(control->hwnd, BM_SETCHECK, BST_CHECKED, 0);
1598 prop = MSI_RecordGetString( rec, 1 );
1600 control->property = strdupW( prop );
1602 return ERROR_SUCCESS;
1605 static UINT msi_dialog_radiogroup_control( msi_dialog *dialog, MSIRECORD *rec )
1607 static const WCHAR query[] = {
1608 'S','E','L','E','C','T',' ','*',' ',
1609 'F','R','O','M',' ','R','a','d','i','o','B','u','t','t','o','n',' ',
1610 'W','H','E','R','E',' ',
1611 '`','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1614 msi_control *control;
1615 MSIQUERY *view = NULL;
1616 radio_button_group_descr group;
1617 MSIPACKAGE *package = dialog->package;
1620 prop = MSI_RecordGetString( rec, 9 );
1622 TRACE("%p %p %s\n", dialog, rec, debugstr_w( prop ));
1624 /* Create parent group box to hold radio buttons */
1625 control = msi_dialog_add_control( dialog, rec, szButton, BS_OWNERDRAW|WS_GROUP );
1627 return ERROR_FUNCTION_FAILED;
1629 oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1630 (LONG_PTR)MSIRadioGroup_WndProc );
1631 SetPropW(control->hwnd, szButtonData, oldproc);
1632 SetWindowLongPtrW( control->hwnd, GWL_EXSTYLE, WS_EX_CONTROLPARENT );
1635 control->property = strdupW( prop );
1637 /* query the Radio Button table for all control in this group */
1638 r = MSI_OpenQuery( package->db, &view, query, prop );
1639 if( r != ERROR_SUCCESS )
1641 ERR("query failed for dialog %s radio group %s\n",
1642 debugstr_w(dialog->name), debugstr_w(prop));
1643 return ERROR_INVALID_PARAMETER;
1646 group.dialog = dialog;
1647 group.parent = control;
1648 group.attributes = MSI_RecordGetInteger( rec, 8 );
1649 group.propval = msi_dup_property( dialog->package, control->property );
1651 r = MSI_IterateRecords( view, 0, msi_dialog_create_radiobutton, &group );
1652 msiobj_release( &view->hdr );
1653 msi_free( group.propval );
1658 /******************** Selection Tree ***************************************/
1660 struct msi_selection_tree_info
1668 msi_seltree_sync_item_state( HWND hwnd, MSIFEATURE *feature, HTREEITEM hItem )
1671 DWORD index = feature->Action;
1673 TRACE("Feature %s -> %d %d %d\n", debugstr_w(feature->Title),
1674 feature->Installed, feature->Action, feature->ActionRequest);
1676 if (index == INSTALLSTATE_UNKNOWN)
1677 index = INSTALLSTATE_ABSENT;
1679 tvi.mask = TVIF_STATE;
1681 tvi.state = INDEXTOSTATEIMAGEMASK( index );
1682 tvi.stateMask = TVIS_STATEIMAGEMASK;
1684 SendMessageW( hwnd, TVM_SETITEMW, 0, (LPARAM) &tvi );
1688 msi_seltree_popup_menu( HWND hwnd, INT x, INT y )
1693 /* create a menu to display */
1694 hMenu = CreatePopupMenu();
1696 /* FIXME: load strings from resources */
1697 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_LOCAL, "Install feature locally");
1698 AppendMenuA( hMenu, MF_GRAYED, 0x1000, "Install entire feature");
1699 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ADVERTISED, "Install on demand");
1700 AppendMenuA( hMenu, MF_ENABLED, INSTALLSTATE_ABSENT, "Don't install");
1701 r = TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD,
1702 x, y, 0, hwnd, NULL );
1703 DestroyMenu( hMenu );
1708 msi_seltree_feature_from_item( HWND hwnd, HTREEITEM hItem )
1712 /* get the feature from the item */
1713 memset( &tvi, 0, sizeof tvi );
1715 tvi.mask = TVIF_PARAM | TVIF_HANDLE;
1716 SendMessageW( hwnd, TVM_GETITEMW, 0, (LPARAM) &tvi );
1718 return (MSIFEATURE*) tvi.lParam;
1722 msi_seltree_menu( HWND hwnd, HTREEITEM hItem )
1724 struct msi_selection_tree_info *info;
1725 MSIFEATURE *feature;
1726 MSIPACKAGE *package;
1734 info = GetPropW(hwnd, szButtonData);
1735 package = info->dialog->package;
1737 feature = msi_seltree_feature_from_item( hwnd, hItem );
1740 ERR("item %p feature was NULL\n", hItem);
1744 /* get the item's rectangle to put the menu just below it */
1746 SendMessageW( hwnd, TVM_GETITEMRECT, 0, (LPARAM) &u.rc );
1747 MapWindowPoints( hwnd, NULL, u.pt, 2 );
1749 r = msi_seltree_popup_menu( hwnd, u.rc.left, u.rc.top );
1753 case INSTALLSTATE_LOCAL:
1754 case INSTALLSTATE_ADVERTISED:
1755 case INSTALLSTATE_ABSENT:
1756 feature->ActionRequest = r;
1757 feature->Action = r;
1760 FIXME("select feature and all children\n");
1764 msi_seltree_sync_item_state( hwnd, feature, hItem );
1765 ACTION_UpdateComponentStates( package, feature->Feature );
1770 static LRESULT WINAPI
1771 MSISelectionTree_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1773 struct msi_selection_tree_info *info;
1774 TVHITTESTINFO tvhti;
1777 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1779 info = GetPropW(hWnd, szButtonData);
1783 case WM_LBUTTONDOWN:
1784 tvhti.pt.x = LOWORD( lParam );
1785 tvhti.pt.y = HIWORD( lParam );
1788 r = CallWindowProcW(info->oldproc, hWnd, TVM_HITTEST, 0, (LPARAM) &tvhti );
1789 if (tvhti.flags & TVHT_ONITEMSTATEICON)
1790 return msi_seltree_menu( hWnd, tvhti.hItem );
1794 r = CallWindowProcW(info->oldproc, hWnd, msg, wParam, lParam);
1800 RemovePropW( hWnd, szButtonData );
1807 msi_seltree_add_child_features( MSIPACKAGE *package, HWND hwnd,
1808 LPCWSTR parent, HTREEITEM hParent )
1810 MSIFEATURE *feature;
1811 TVINSERTSTRUCTW tvis;
1812 HTREEITEM hitem, hfirst = NULL;
1814 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
1816 if ( lstrcmpW( parent, feature->Feature_Parent ) )
1819 if ( !feature->Title )
1822 if ( !feature->Display )
1825 memset( &tvis, 0, sizeof tvis );
1826 tvis.hParent = hParent;
1827 tvis.hInsertAfter = TVI_LAST;
1828 tvis.u.item.mask = TVIF_TEXT | TVIF_PARAM;
1829 tvis.u.item.pszText = feature->Title;
1830 tvis.u.item.lParam = (LPARAM) feature;
1832 hitem = (HTREEITEM) SendMessageW( hwnd, TVM_INSERTITEMW, 0, (LPARAM) &tvis );
1839 msi_seltree_sync_item_state( hwnd, feature, hitem );
1840 msi_seltree_add_child_features( package, hwnd,
1841 feature->Feature, hitem );
1843 /* the node is expanded if Display is odd */
1844 if ( feature->Display % 2 != 0 )
1845 SendMessageW( hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) hitem );
1848 /* select the first item */
1849 SendMessageW( hwnd, TVM_SELECTITEM, TVGN_CARET | TVGN_DROPHILITE, (LPARAM) hfirst );
1852 static void msi_seltree_create_imagelist( HWND hwnd )
1854 const int bm_width = 32, bm_height = 16, bm_count = 3;
1855 const int bm_resource = 0x1001;
1860 himl = ImageList_Create( bm_width, bm_height, FALSE, 4, 0 );
1863 ERR("failed to create image list\n");
1867 for (i=0; i<bm_count; i++)
1869 hbmp = LoadBitmapW( msi_hInstance, MAKEINTRESOURCEW(i+bm_resource) );
1872 ERR("failed to load bitmap %d\n", i);
1877 * Add a dummy bitmap at offset zero because the treeview
1878 * can't use it as a state mask (zero means no user state).
1881 ImageList_Add( himl, hbmp, NULL );
1883 ImageList_Add( himl, hbmp, NULL );
1886 SendMessageW( hwnd, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl );
1889 static UINT msi_dialog_selection_tree( msi_dialog *dialog, MSIRECORD *rec )
1891 msi_control *control;
1893 MSIPACKAGE *package = dialog->package;
1895 struct msi_selection_tree_info *info;
1897 info = msi_alloc( sizeof *info );
1899 return ERROR_FUNCTION_FAILED;
1901 /* create the treeview control */
1902 prop = MSI_RecordGetString( rec, 9 );
1903 style = TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
1904 style |= WS_GROUP | WS_VSCROLL;
1905 control = msi_dialog_add_control( dialog, rec, WC_TREEVIEWW, style );
1909 return ERROR_FUNCTION_FAILED;
1913 info->dialog = dialog;
1914 info->hwnd = control->hwnd;
1915 info->oldproc = (WNDPROC) SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
1916 (LONG_PTR)MSISelectionTree_WndProc );
1917 SetPropW( control->hwnd, szButtonData, info );
1920 msi_seltree_create_imagelist( control->hwnd );
1921 msi_seltree_add_child_features( package, control->hwnd, NULL, NULL );
1923 return ERROR_SUCCESS;
1926 /******************** Group Box ***************************************/
1928 static UINT msi_dialog_group_box( msi_dialog *dialog, MSIRECORD *rec )
1930 msi_control *control;
1933 style = BS_GROUPBOX | WS_CHILD | WS_GROUP;
1934 control = msi_dialog_add_control( dialog, rec, WC_BUTTONW, style );
1936 return ERROR_FUNCTION_FAILED;
1938 return ERROR_SUCCESS;
1941 /******************** List Box ***************************************/
1943 struct msi_listbox_item
1949 struct msi_listbox_info
1955 struct msi_listbox_item *items;
1958 static LRESULT WINAPI MSIListBox_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1960 struct msi_listbox_info *info;
1964 TRACE("%p %04x %08x %08lx\n", hWnd, msg, wParam, lParam);
1966 info = GetPropW( hWnd, szButtonData );
1970 r = CallWindowProcW( info->oldproc, hWnd, msg, wParam, lParam );
1975 for (j = 0; j < info->num_items; j++)
1977 msi_free( info->items[j].property );
1978 msi_free( info->items[j].value );
1980 msi_free( info->items );
1982 RemovePropW( hWnd, szButtonData );
1989 static UINT msi_listbox_add_item( MSIRECORD *rec, LPVOID param )
1991 struct msi_listbox_info *info = param;
1992 struct msi_listbox_item *item;
1993 LPCWSTR property, value, text;
1994 static int index = 0;
1996 item = &info->items[index++];
1997 property = MSI_RecordGetString( rec, 1 );
1998 value = MSI_RecordGetString( rec, 3 );
1999 text = MSI_RecordGetString( rec, 4 );
2001 item->property = strdupW( property );
2002 item->value = strdupW( value );
2004 SendMessageW( info->hwnd, LB_ADDSTRING, 0, (LPARAM)text );
2006 return ERROR_SUCCESS;
2009 static UINT msi_listbox_add_items( struct msi_listbox_info *info )
2012 MSIQUERY *view = NULL;
2015 static const WCHAR query[] = {
2016 'S','E','L','E','C','T',' ','*',' ',
2017 'F','R','O','M',' ','`','L','i','s','t','B','o','x','`',' ',
2018 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','`',0
2021 r = MSI_OpenQuery( info->dialog->package->db, &view, query );
2022 if ( r != ERROR_SUCCESS )
2025 /* just get the number of records */
2026 r = MSI_IterateRecords( view, &count, NULL, NULL );
2028 info->num_items = count;
2029 info->items = msi_alloc( sizeof(*info->items) * count );
2031 r = MSI_IterateRecords( view, NULL, msi_listbox_add_item, info );
2032 msiobj_release( &view->hdr );
2037 static UINT msi_dialog_listbox_handler( msi_dialog *dialog,
2038 msi_control *control, WPARAM param )
2040 struct msi_listbox_info *info;
2043 if( HIWORD(param) != LBN_SELCHANGE )
2044 return ERROR_SUCCESS;
2046 info = GetPropW( control->hwnd, szButtonData );
2047 index = SendMessageW( control->hwnd, LB_GETCURSEL, 0, 0 );
2049 MSI_SetPropertyW( info->dialog->package,
2050 info->items[index].property, info->items[index].value );
2051 msi_dialog_evaluate_control_conditions( info->dialog );
2053 return ERROR_SUCCESS;
2056 static UINT msi_dialog_list_box( msi_dialog *dialog, MSIRECORD *rec )
2058 struct msi_listbox_info *info;
2059 msi_control *control;
2062 info = msi_alloc( sizeof *info );
2064 return ERROR_FUNCTION_FAILED;
2066 style = WS_TABSTOP | WS_GROUP | WS_CHILD | LBS_STANDARD;
2067 control = msi_dialog_add_control( dialog, rec, WC_LISTBOXW, style );
2069 return ERROR_FUNCTION_FAILED;
2071 control->handler = msi_dialog_listbox_handler;
2074 info->dialog = dialog;
2075 info->hwnd = control->hwnd;
2077 info->oldproc = (WNDPROC)SetWindowLongPtrW( control->hwnd, GWLP_WNDPROC,
2078 (LONG_PTR)MSIListBox_WndProc );
2079 SetPropW( control->hwnd, szButtonData, info );
2081 msi_listbox_add_items( info );
2083 return ERROR_SUCCESS;
2086 /******************** Directory Combo ***************************************/
2088 static void msi_dialog_update_directory_combo( msi_dialog *dialog, msi_control *control )
2093 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryCombo )))
2096 indirect = control->attributes & msidbControlAttributesIndirect;
2097 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2099 path = msi_dup_property( dialog->package, prop );
2103 PathStripPathW( path );
2104 PathRemoveBackslashW( path );
2106 SendMessageW( control->hwnd, CB_INSERTSTRING, 0, (LPARAM)path );
2107 SendMessageW( control->hwnd, CB_SETCURSEL, 0, 0 );
2113 static UINT msi_dialog_directory_combo( msi_dialog *dialog, MSIRECORD *rec )
2115 msi_control *control;
2119 /* FIXME: use CBS_OWNERDRAWFIXED and add owner draw code */
2120 style = CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
2121 WS_GROUP | WS_TABSTOP | WS_VSCROLL;
2122 control = msi_dialog_add_control( dialog, rec, WC_COMBOBOXW, style );
2124 return ERROR_FUNCTION_FAILED;
2126 control->attributes = MSI_RecordGetInteger( rec, 8 );
2127 prop = MSI_RecordGetString( rec, 9 );
2128 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2130 msi_dialog_update_directory_combo( dialog, control );
2132 return ERROR_SUCCESS;
2135 /******************** Directory List ***************************************/
2137 static void msi_dialog_update_directory_list( msi_dialog *dialog, msi_control *control )
2139 WCHAR dir_spec[MAX_PATH];
2140 WIN32_FIND_DATAW wfd;
2146 static const WCHAR asterisk[] = {'*',0};
2147 static const WCHAR dot[] = {'.',0};
2148 static const WCHAR dotdot[] = {'.','.',0};
2150 if (!control && !(control = msi_dialog_find_control_by_type( dialog, szDirectoryList )))
2153 /* clear the list-view */
2154 SendMessageW( control->hwnd, LVM_DELETEALLITEMS, 0, 0 );
2156 indirect = control->attributes & msidbControlAttributesIndirect;
2157 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2159 path = msi_dup_property( dialog->package, prop );
2163 lstrcpyW( dir_spec, path );
2164 lstrcatW( dir_spec, asterisk );
2166 file = FindFirstFileW( dir_spec, &wfd );
2167 if ( file == INVALID_HANDLE_VALUE )
2172 if ( wfd.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY )
2175 if ( !lstrcmpW( wfd.cFileName, dot ) || !lstrcmpW( wfd.cFileName, dotdot ) )
2178 item.mask = LVIF_TEXT;
2179 item.cchTextMax = MAX_PATH;
2182 item.pszText = wfd.cFileName;
2184 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&item );
2185 } while ( FindNextFileW( file, &wfd ) );
2192 UINT msi_dialog_directorylist_up( msi_dialog *dialog )
2194 msi_control *control;
2195 LPWSTR prop, path, ptr;
2198 control = msi_dialog_find_control_by_type( dialog, szDirectoryList );
2199 indirect = control->attributes & msidbControlAttributesIndirect;
2200 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2202 path = msi_dup_property( dialog->package, prop );
2206 /* strip off the last directory */
2207 ptr = PathFindFileNameW( path );
2208 if (ptr != path) *(ptr - 1) = '\0';
2209 PathAddBackslashW( path );
2211 MSI_SetPropertyW( dialog->package, prop, path );
2213 msi_dialog_update_directory_list( dialog, NULL );
2214 msi_dialog_update_directory_combo( dialog, NULL );
2215 msi_dialog_update_pathedit( dialog, NULL );
2220 return ERROR_SUCCESS;
2223 static UINT msi_dialog_dirlist_handler( msi_dialog *dialog,
2224 msi_control *control, WPARAM param )
2226 LPNMHDR nmhdr = (LPNMHDR)param;
2227 WCHAR new_path[MAX_PATH];
2228 WCHAR text[MAX_PATH];
2234 static const WCHAR backslash[] = {'\\',0};
2236 if (nmhdr->code != LVN_ITEMACTIVATE)
2237 return ERROR_SUCCESS;
2239 index = SendMessageW( control->hwnd, LVM_GETNEXTITEM, -1, LVNI_SELECTED );
2242 ERR("No list-view item selected!\n");
2243 return ERROR_FUNCTION_FAILED;
2247 item.pszText = text;
2248 item.cchTextMax = MAX_PATH;
2249 SendMessageW( control->hwnd, LVM_GETITEMTEXTW, index, (LPARAM)&item );
2251 indirect = control->attributes & msidbControlAttributesIndirect;
2252 prop = msi_dialog_dup_property( dialog, control->property, indirect );
2254 path = msi_dup_property( dialog->package, prop );
2258 lstrcpyW( new_path, path );
2259 lstrcatW( new_path, text );
2260 lstrcatW( new_path, backslash );
2262 MSI_SetPropertyW( dialog->package, prop, new_path );
2264 msi_dialog_update_directory_list( dialog, NULL );
2265 msi_dialog_update_directory_combo( dialog, NULL );
2266 msi_dialog_update_pathedit( dialog, NULL );
2270 return ERROR_SUCCESS;
2273 static UINT msi_dialog_directory_list( msi_dialog *dialog, MSIRECORD *rec )
2275 msi_control *control;
2279 style = LVS_LIST | WS_VSCROLL | LVS_SHAREIMAGELISTS |
2280 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2281 LVS_SORTASCENDING | WS_CHILD | WS_GROUP | WS_TABSTOP;
2282 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2284 return ERROR_FUNCTION_FAILED;
2286 control->attributes = MSI_RecordGetInteger( rec, 8 );
2287 control->handler = msi_dialog_dirlist_handler;
2288 prop = MSI_RecordGetString( rec, 9 );
2289 control->property = msi_dialog_dup_property( dialog, prop, FALSE );
2291 /* double click to activate an item in the list */
2292 SendMessageW( control->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
2293 0, LVS_EX_TWOCLICKACTIVATE );
2295 msi_dialog_update_directory_list( dialog, control );
2297 return ERROR_SUCCESS;
2300 /******************** VolumeCost List ***************************************/
2302 static BOOL str_is_number( LPCWSTR str )
2306 for (i = 0; i < lstrlenW( str ); i++)
2307 if (!isdigitW(str[i]))
2313 WCHAR column_keys[][80] =
2315 {'V','o','l','u','m','e','C','o','s','t','V','o','l','u','m','e',0},
2316 {'V','o','l','u','m','e','C','o','s','t','S','i','z','e',0},
2317 {'V','o','l','u','m','e','C','o','s','t','A','v','a','i','l','a','b','l','e',0},
2318 {'V','o','l','u','m','e','C','o','s','t','R','e','q','u','i','r','e','d',0},
2319 {'V','o','l','u','m','e','C','o','s','t','D','i','f','f','e','r','e','n','c','e',0}
2322 static void msi_dialog_vcl_add_columns( msi_dialog *dialog, msi_control *control, MSIRECORD *rec )
2324 LPCWSTR text = MSI_RecordGetString( rec, 10 );
2325 LPCWSTR begin = text, end;
2330 static const WCHAR zero[] = {'0',0};
2331 static const WCHAR negative[] = {'-',0};
2333 while ((begin = strchrW( begin, '{' )) && count < 5)
2335 if (!(end = strchrW( begin, '}' )))
2338 lstrcpynW( num, begin + 1, end - begin );
2339 begin += end - begin + 1;
2341 /* empty braces or '0' hides the column */
2342 if ( !num[0] || !lstrcmpW( num, zero ) )
2348 /* the width must be a positive number
2349 * if a width is invalid, all remaining columns are hidden
2351 if ( !strncmpW( num, negative, 1 ) || !str_is_number( num ) )
2354 ZeroMemory( &lvc, sizeof(lvc) );
2355 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
2356 lvc.cx = atolW( num );
2357 lvc.pszText = msi_dialog_get_uitext( dialog, column_keys[count] );
2359 SendMessageW( control->hwnd, LVM_INSERTCOLUMNW, count++, (LPARAM)&lvc );
2360 msi_free( lvc.pszText );
2364 static void msi_dialog_vcl_add_drives( msi_dialog *dialog, msi_control *control )
2366 ULARGE_INTEGER total, free;
2367 WCHAR size_text[MAX_PATH];
2373 size = GetLogicalDriveStringsW( 0, NULL );
2374 if ( !size ) return;
2376 drives = msi_alloc( (size + 1) * sizeof(WCHAR) );
2377 if ( !drives ) return;
2379 GetLogicalDriveStringsW( size, drives );
2384 lvitem.mask = LVIF_TEXT;
2386 lvitem.iSubItem = 0;
2387 lvitem.pszText = ptr;
2388 lvitem.cchTextMax = lstrlenW(ptr) + 1;
2389 SendMessageW( control->hwnd, LVM_INSERTITEMW, 0, (LPARAM)&lvitem );
2391 GetDiskFreeSpaceExW(ptr, &free, &total, NULL);
2393 StrFormatByteSizeW(total.QuadPart, size_text, MAX_PATH);
2394 lvitem.iSubItem = 1;
2395 lvitem.pszText = size_text;
2396 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2397 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2399 StrFormatByteSizeW(free.QuadPart, size_text, MAX_PATH);
2400 lvitem.iSubItem = 2;
2401 lvitem.pszText = size_text;
2402 lvitem.cchTextMax = lstrlenW(size_text) + 1;
2403 SendMessageW( control->hwnd, LVM_SETITEMW, 0, (LPARAM)&lvitem );
2405 ptr += lstrlenW(ptr) + 1;
2412 static UINT msi_dialog_volumecost_list( msi_dialog *dialog, MSIRECORD *rec )
2414 msi_control *control;
2417 style = LVS_REPORT | WS_VSCROLL | WS_HSCROLL | LVS_SHAREIMAGELISTS |
2418 LVS_AUTOARRANGE | LVS_SINGLESEL | WS_BORDER |
2419 WS_CHILD | WS_TABSTOP | WS_GROUP;
2420 control = msi_dialog_add_control( dialog, rec, WC_LISTVIEWW, style );
2422 return ERROR_FUNCTION_FAILED;
2424 msi_dialog_vcl_add_columns( dialog, control, rec );
2425 msi_dialog_vcl_add_drives( dialog, control );
2427 return ERROR_SUCCESS;
2430 static const struct control_handler msi_dialog_handler[] =
2432 { szText, msi_dialog_text_control },
2433 { szPushButton, msi_dialog_button_control },
2434 { szLine, msi_dialog_line_control },
2435 { szBitmap, msi_dialog_bitmap_control },
2436 { szCheckBox, msi_dialog_checkbox_control },
2437 { szScrollableText, msi_dialog_scrolltext_control },
2438 { szComboBox, msi_dialog_combo_control },
2439 { szEdit, msi_dialog_edit_control },
2440 { szMaskedEdit, msi_dialog_maskedit_control },
2441 { szPathEdit, msi_dialog_pathedit_control },
2442 { szProgressBar, msi_dialog_progress_bar },
2443 { szRadioButtonGroup, msi_dialog_radiogroup_control },
2444 { szIcon, msi_dialog_icon_control },
2445 { szSelectionTree, msi_dialog_selection_tree },
2446 { szGroupBox, msi_dialog_group_box },
2447 { szListBox, msi_dialog_list_box },
2448 { szDirectoryCombo, msi_dialog_directory_combo },
2449 { szDirectoryList, msi_dialog_directory_list },
2450 { szVolumeCostList, msi_dialog_volumecost_list },
2453 #define NUM_CONTROL_TYPES (sizeof msi_dialog_handler/sizeof msi_dialog_handler[0])
2455 static UINT msi_dialog_create_controls( MSIRECORD *rec, LPVOID param )
2457 msi_dialog *dialog = param;
2458 LPCWSTR control_type;
2461 /* find and call the function that can create this type of control */
2462 control_type = MSI_RecordGetString( rec, 3 );
2463 for( i=0; i<NUM_CONTROL_TYPES; i++ )
2464 if (!strcmpiW( msi_dialog_handler[i].control_type, control_type ))
2466 if( i != NUM_CONTROL_TYPES )
2467 msi_dialog_handler[i].func( dialog, rec );
2469 ERR("no handler for element type %s\n", debugstr_w(control_type));
2471 return ERROR_SUCCESS;
2474 static UINT msi_dialog_fill_controls( msi_dialog *dialog )
2476 static const WCHAR query[] = {
2477 'S','E','L','E','C','T',' ','*',' ',
2478 'F','R','O','M',' ','C','o','n','t','r','o','l',' ',
2479 'W','H','E','R','E',' ',
2480 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0};
2482 MSIQUERY *view = NULL;
2483 MSIPACKAGE *package = dialog->package;
2485 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2487 /* query the Control table for all the elements of the control */
2488 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2489 if( r != ERROR_SUCCESS )
2491 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2492 return ERROR_INVALID_PARAMETER;
2495 r = MSI_IterateRecords( view, 0, msi_dialog_create_controls, dialog );
2496 msiobj_release( &view->hdr );
2501 static UINT msi_dialog_set_control_condition( MSIRECORD *rec, LPVOID param )
2503 static const WCHAR szHide[] = { 'H','i','d','e',0 };
2504 static const WCHAR szShow[] = { 'S','h','o','w',0 };
2505 static const WCHAR szDisable[] = { 'D','i','s','a','b','l','e',0 };
2506 static const WCHAR szEnable[] = { 'E','n','a','b','l','e',0 };
2507 msi_dialog *dialog = param;
2508 msi_control *control;
2509 LPCWSTR name, action, condition;
2512 name = MSI_RecordGetString( rec, 2 );
2513 action = MSI_RecordGetString( rec, 3 );
2514 condition = MSI_RecordGetString( rec, 4 );
2515 r = MSI_EvaluateConditionW( dialog->package, condition );
2516 control = msi_dialog_find_control( dialog, name );
2517 if( r == MSICONDITION_TRUE && control )
2519 TRACE("%s control %s\n", debugstr_w(action), debugstr_w(name));
2521 /* FIXME: case sensitive? */
2522 if(!lstrcmpW(action, szHide))
2523 ShowWindow(control->hwnd, SW_HIDE);
2524 else if(!strcmpW(action, szShow))
2525 ShowWindow(control->hwnd, SW_SHOW);
2526 else if(!strcmpW(action, szDisable))
2527 EnableWindow(control->hwnd, FALSE);
2528 else if(!strcmpW(action, szEnable))
2529 EnableWindow(control->hwnd, TRUE);
2531 FIXME("Unhandled action %s\n", debugstr_w(action));
2534 return ERROR_SUCCESS;
2537 static UINT msi_dialog_evaluate_control_conditions( msi_dialog *dialog )
2539 static const WCHAR query[] = {
2540 'S','E','L','E','C','T',' ','*',' ',
2541 'F','R','O','M',' ',
2542 'C','o','n','t','r','o','l','C','o','n','d','i','t','i','o','n',' ',
2543 'W','H','E','R','E',' ',
2544 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',0
2547 MSIQUERY *view = NULL;
2548 MSIPACKAGE *package = dialog->package;
2550 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2552 /* query the Control table for all the elements of the control */
2553 r = MSI_OpenQuery( package->db, &view, query, dialog->name );
2554 if( r != ERROR_SUCCESS )
2555 return ERROR_SUCCESS;
2557 r = MSI_IterateRecords( view, 0, msi_dialog_set_control_condition, dialog );
2558 msiobj_release( &view->hdr );
2563 UINT msi_dialog_reset( msi_dialog *dialog )
2565 /* FIXME: should restore the original values of any properties we changed */
2566 return msi_dialog_evaluate_control_conditions( dialog );
2569 /* figure out the height of 10 point MS Sans Serif */
2570 static INT msi_dialog_get_sans_serif_height( HWND hwnd )
2572 static const WCHAR szSansSerif[] = {
2573 'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0 };
2578 HFONT hFont, hOldFont;
2581 hdc = GetDC( hwnd );
2584 memset( &lf, 0, sizeof lf );
2585 lf.lfHeight = MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
2586 strcpyW( lf.lfFaceName, szSansSerif );
2587 hFont = CreateFontIndirectW(&lf);
2590 hOldFont = SelectObject( hdc, hFont );
2591 r = GetTextMetricsW( hdc, &tm );
2593 height = tm.tmHeight;
2594 SelectObject( hdc, hOldFont );
2595 DeleteObject( hFont );
2597 ReleaseDC( hwnd, hdc );
2602 /* fetch the associated record from the Dialog table */
2603 static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
2605 static const WCHAR query[] = {
2606 'S','E','L','E','C','T',' ','*',' ',
2607 'F','R','O','M',' ','D','i','a','l','o','g',' ',
2608 'W','H','E','R','E',' ',
2609 '`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
2610 MSIPACKAGE *package = dialog->package;
2611 MSIRECORD *rec = NULL;
2613 TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
2615 rec = MSI_QueryGetRecord( package->db, query, dialog->name );
2617 ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
2622 static void msi_dialog_adjust_dialog_pos( msi_dialog *dialog, MSIRECORD *rec, LPRECT pos )
2624 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
2625 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
2632 center.x = MSI_RecordGetInteger( rec, 2 );
2633 center.y = MSI_RecordGetInteger( rec, 3 );
2635 sz.cx = MSI_RecordGetInteger( rec, 4 );
2636 sz.cy = MSI_RecordGetInteger( rec, 5 );
2638 sz.cx = msi_dialog_scale_unit( dialog, sz.cx );
2639 sz.cy = msi_dialog_scale_unit( dialog, sz.cy );
2641 xres = msi_get_property_int( dialog->package, szScreenX, 0 );
2642 yres = msi_get_property_int( dialog->package, szScreenY, 0 );
2644 center.x = MulDiv( center.x, xres, 100 );
2645 center.y = MulDiv( center.y, yres, 100 );
2647 /* turn the client pos into the window rectangle */
2648 if (dialog->package->center_x && dialog->package->center_y)
2650 pos->left = dialog->package->center_x - sz.cx / 2.0;
2651 pos->right = pos->left + sz.cx;
2652 pos->top = dialog->package->center_y - sz.cy / 2.0;
2653 pos->bottom = pos->top + sz.cy;
2657 pos->left = center.x - sz.cx/2;
2658 pos->right = pos->left + sz.cx;
2659 pos->top = center.y - sz.cy/2;
2660 pos->bottom = pos->top + sz.cy;
2662 /* save the center */
2663 dialog->package->center_x = center.x;
2664 dialog->package->center_y = center.y;
2667 dialog->size.cx = sz.cx;
2668 dialog->size.cy = sz.cy;
2670 TRACE("%lu %lu %lu %lu\n", pos->left, pos->top, pos->right, pos->bottom);
2672 style = GetWindowLongPtrW( dialog->hwnd, GWL_STYLE );
2673 AdjustWindowRect( pos, style, FALSE );
2676 static BOOL msi_control_set_next( msi_control *control, msi_control *next )
2678 return SetWindowPos( next->hwnd, control->hwnd, 0, 0, 0, 0,
2679 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW |
2680 SWP_NOREPOSITION | SWP_NOSENDCHANGING | SWP_NOSIZE );
2683 static UINT msi_dialog_set_tab_order( msi_dialog *dialog )
2685 msi_control *control, *tab_next;
2687 LIST_FOR_EACH_ENTRY( control, &dialog->controls, msi_control, entry )
2689 tab_next = msi_dialog_find_control( dialog, control->tabnext );
2692 msi_control_set_next( control, tab_next );
2695 return ERROR_SUCCESS;
2698 static void msi_dialog_set_first_control( msi_dialog* dialog, LPCWSTR name )
2700 msi_control *control;
2702 control = msi_dialog_find_control( dialog, name );
2704 dialog->hWndFocus = control->hwnd;
2706 dialog->hWndFocus = NULL;
2709 static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
2711 static const WCHAR df[] = {
2712 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
2713 static const WCHAR dfv[] = {
2714 'M','S',' ','S','h','e','l','l',' ','D','l','g',0 };
2715 msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
2716 MSIRECORD *rec = NULL;
2717 LPWSTR title = NULL;
2720 TRACE("%p %p\n", dialog, dialog->package);
2722 dialog->hwnd = hwnd;
2723 SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
2725 rec = msi_get_dialog_record( dialog );
2728 TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
2732 dialog->scale = msi_dialog_get_sans_serif_height(dialog->hwnd);
2734 msi_dialog_adjust_dialog_pos( dialog, rec, &pos );
2736 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
2738 dialog->default_font = msi_dup_property( dialog->package, df );
2739 if (!dialog->default_font)
2741 dialog->default_font = strdupW(dfv);
2742 if (!dialog->default_font) return -1;
2745 title = msi_get_deformatted_field( dialog->package, rec, 7 );
2746 SetWindowTextW( hwnd, title );
2749 SetWindowPos( hwnd, 0, pos.left, pos.top,
2750 pos.right - pos.left, pos.bottom - pos.top,
2751 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW );
2753 msi_dialog_build_font_list( dialog );
2754 msi_dialog_fill_controls( dialog );
2755 msi_dialog_evaluate_control_conditions( dialog );
2756 msi_dialog_set_tab_order( dialog );
2757 msi_dialog_set_first_control( dialog, MSI_RecordGetString( rec, 8 ) );
2758 msiobj_release( &rec->hdr );
2763 static UINT msi_dialog_send_event( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2765 LPWSTR event_fmt = NULL, arg_fmt = NULL;
2767 TRACE("Sending control event %s %s\n", debugstr_w(event), debugstr_w(arg));
2769 deformat_string( dialog->package, event, &event_fmt );
2770 deformat_string( dialog->package, arg, &arg_fmt );
2772 dialog->event_handler( dialog->package, event_fmt, arg_fmt, dialog );
2774 msi_free( event_fmt );
2775 msi_free( arg_fmt );
2777 return ERROR_SUCCESS;
2780 static UINT msi_dialog_set_property( msi_dialog *dialog, LPCWSTR event, LPCWSTR arg )
2782 static const WCHAR szNullArg[] = { '{','}',0 };
2783 LPWSTR p, prop, arg_fmt = NULL;
2786 len = strlenW(event);
2787 prop = msi_alloc( len*sizeof(WCHAR));
2788 strcpyW( prop, &event[1] );
2789 p = strchrW( prop, ']' );
2790 if( p && p[1] == 0 )
2793 if( strcmpW( szNullArg, arg ) )
2794 deformat_string( dialog->package, arg, &arg_fmt );
2795 MSI_SetPropertyW( dialog->package, prop, arg_fmt );
2796 msi_free( arg_fmt );
2799 ERR("Badly formatted property string - what happens?\n");
2801 return ERROR_SUCCESS;
2804 static UINT msi_dialog_control_event( MSIRECORD *rec, LPVOID param )
2806 msi_dialog *dialog = param;
2807 LPCWSTR condition, event, arg;
2810 condition = MSI_RecordGetString( rec, 5 );
2811 r = MSI_EvaluateConditionW( dialog->package, condition );
2812 if( r == MSICONDITION_TRUE || r == MSICONDITION_NONE )
2814 event = MSI_RecordGetString( rec, 3 );
2815 arg = MSI_RecordGetString( rec, 4 );
2816 if( event[0] == '[' )
2817 msi_dialog_set_property( dialog, event, arg );
2819 msi_dialog_send_event( dialog, event, arg );
2822 return ERROR_SUCCESS;
2825 static UINT msi_dialog_button_handler( msi_dialog *dialog,
2826 msi_control *control, WPARAM param )
2828 static const WCHAR query[] = {
2829 'S','E','L','E','C','T',' ','*',' ',
2830 'F','R','O','M',' ','C','o','n','t','r','o','l','E','v','e','n','t',' ',
2831 'W','H','E','R','E',' ',
2832 '`','D','i','a','l','o','g','_','`',' ','=',' ','\'','%','s','\'',' ',
2834 '`','C','o','n','t','r','o','l','_','`',' ','=',' ','\'','%','s','\'',' ',
2835 'O','R','D','E','R',' ','B','Y',' ','`','O','r','d','e','r','i','n','g','`',0
2837 MSIQUERY *view = NULL;
2840 if( HIWORD(param) != BN_CLICKED )
2841 return ERROR_SUCCESS;
2843 r = MSI_OpenQuery( dialog->package->db, &view, query,
2844 dialog->name, control->name );
2845 if( r != ERROR_SUCCESS )
2847 ERR("query failed\n");
2851 r = MSI_IterateRecords( view, 0, msi_dialog_control_event, dialog );
2852 msiobj_release( &view->hdr );
2857 static UINT msi_dialog_get_checkbox_state( msi_dialog *dialog,
2858 msi_control *control )
2860 WCHAR state[2] = { 0 };
2863 MSI_GetPropertyW( dialog->package, control->property, state, &sz );
2864 return state[0] ? 1 : 0;
2867 static void msi_dialog_set_checkbox_state( msi_dialog *dialog,
2868 msi_control *control, UINT state )
2870 static const WCHAR szState[] = { '1', 0 };
2873 /* if uncheck then the property is set to NULL */
2876 MSI_SetPropertyW( dialog->package, control->property, NULL );
2880 /* check for a custom state */
2881 if (control->value && control->value[0])
2882 val = control->value;
2886 MSI_SetPropertyW( dialog->package, control->property, val );
2889 static void msi_dialog_checkbox_sync_state( msi_dialog *dialog,
2890 msi_control *control )
2894 state = msi_dialog_get_checkbox_state( dialog, control );
2895 SendMessageW( control->hwnd, BM_SETCHECK,
2896 state ? BST_CHECKED : BST_UNCHECKED, 0 );
2899 static UINT msi_dialog_checkbox_handler( msi_dialog *dialog,
2900 msi_control *control, WPARAM param )
2904 if( HIWORD(param) != BN_CLICKED )
2905 return ERROR_SUCCESS;
2907 TRACE("clicked checkbox %s, set %s\n", debugstr_w(control->name),
2908 debugstr_w(control->property));
2910 state = msi_dialog_get_checkbox_state( dialog, control );
2911 state = state ? 0 : 1;
2912 msi_dialog_set_checkbox_state( dialog, control, state );
2913 msi_dialog_checkbox_sync_state( dialog, control );
2915 return msi_dialog_button_handler( dialog, control, param );
2918 static UINT msi_dialog_edit_handler( msi_dialog *dialog,
2919 msi_control *control, WPARAM param )
2923 if( HIWORD(param) != EN_CHANGE )
2924 return ERROR_SUCCESS;
2926 TRACE("edit %s contents changed, set %s\n", debugstr_w(control->name),
2927 debugstr_w(control->property));
2929 buf = msi_get_window_text( control->hwnd );
2930 MSI_SetPropertyW( dialog->package, control->property, buf );
2934 return ERROR_SUCCESS;
2937 static UINT msi_dialog_radiogroup_handler( msi_dialog *dialog,
2938 msi_control *control, WPARAM param )
2940 if( HIWORD(param) != BN_CLICKED )
2941 return ERROR_SUCCESS;
2943 TRACE("clicked radio button %s, set %s\n", debugstr_w(control->name),
2944 debugstr_w(control->property));
2946 MSI_SetPropertyW( dialog->package, control->property, control->name );
2948 return msi_dialog_button_handler( dialog, control, param );
2951 static LRESULT msi_dialog_oncommand( msi_dialog *dialog, WPARAM param, HWND hwnd )
2953 msi_control *control = NULL;
2955 TRACE("%p %p %08x\n", dialog, hwnd, param);
2960 control = msi_dialog_find_control( dialog, dialog->control_default );
2962 case 2: /* escape */
2963 control = msi_dialog_find_control( dialog, dialog->control_cancel );
2966 control = msi_dialog_find_control_by_hwnd( dialog, hwnd );
2971 if( control->handler )
2973 control->handler( dialog, control, param );
2974 msi_dialog_evaluate_control_conditions( dialog );
2978 ERR("button click from nowhere %p %d %p\n", dialog, param, hwnd);
2982 static LRESULT msi_dialog_onnotify( msi_dialog *dialog, LPARAM param )
2984 LPNMHDR nmhdr = (LPNMHDR) param;
2985 msi_control *control = msi_dialog_find_control_by_hwnd( dialog, nmhdr->hwndFrom );
2987 TRACE("%p %p\n", dialog, nmhdr->hwndFrom);
2989 if ( control && control->handler )
2990 control->handler( dialog, control, param );
2995 static void msi_dialog_setfocus( msi_dialog *dialog )
2997 HWND hwnd = dialog->hWndFocus;
2999 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, TRUE);
3000 hwnd = GetNextDlgTabItem( dialog->hwnd, hwnd, FALSE);
3002 dialog->hWndFocus = hwnd;
3005 static LRESULT WINAPI MSIDialog_WndProc( HWND hwnd, UINT msg,
3006 WPARAM wParam, LPARAM lParam )
3008 msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
3010 TRACE("0x%04x\n", msg);
3015 dialog->package->center_x = LOWORD(lParam) + dialog->size.cx / 2.0;
3016 dialog->package->center_y = HIWORD(lParam) + dialog->size.cy / 2.0;
3020 return msi_dialog_oncreate( hwnd, (LPCREATESTRUCTW)lParam );
3023 return msi_dialog_oncommand( dialog, wParam, (HWND)lParam );
3026 if( LOWORD(wParam) == WA_INACTIVE )
3027 dialog->hWndFocus = GetFocus();
3029 msi_dialog_setfocus( dialog );
3033 msi_dialog_setfocus( dialog );
3036 /* bounce back to our subclassed static control */
3037 case WM_CTLCOLORSTATIC:
3038 return SendMessageW( (HWND) lParam, WM_CTLCOLORSTATIC, wParam, lParam );
3041 dialog->hwnd = NULL;
3044 return msi_dialog_onnotify( dialog, lParam );
3046 return DefWindowProcW(hwnd, msg, wParam, lParam);
3049 static BOOL CALLBACK msi_radioground_child_enum( HWND hWnd, LPARAM lParam )
3051 EnableWindow( hWnd, lParam );
3055 static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3057 WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
3060 TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
3062 if (msg == WM_COMMAND) /* Forward notifications to dialog */
3063 SendMessageW(GetParent(hWnd), msg, wParam, lParam);
3065 r = CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
3067 /* make sure the radio buttons show as disabled if the parent is disabled */
3068 if (msg == WM_ENABLE)
3069 EnumChildWindows( hWnd, msi_radioground_child_enum, wParam );
3074 static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
3075 WPARAM wParam, LPARAM lParam )
3077 msi_dialog *dialog = (msi_dialog*) lParam;
3079 TRACE("%d %p\n", msg, dialog);
3083 case WM_MSI_DIALOG_CREATE:
3084 return msi_dialog_run_message_loop( dialog );
3085 case WM_MSI_DIALOG_DESTROY:
3086 msi_dialog_destroy( dialog );
3089 return DefWindowProcW( hwnd, msg, wParam, lParam );
3092 /* functions that interface to other modules within MSI */
3094 msi_dialog *msi_dialog_create( MSIPACKAGE* package,
3095 LPCWSTR szDialogName, msi_dialog *parent,
3096 msi_dialog_event_handler event_handler )
3098 MSIRECORD *rec = NULL;
3101 TRACE("%p %s\n", package, debugstr_w(szDialogName));
3103 /* allocate the structure for the dialog to use */
3104 dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
3107 strcpyW( dialog->name, szDialogName );
3108 dialog->parent = parent;
3109 msiobj_addref( &package->hdr );
3110 dialog->package = package;
3111 dialog->event_handler = event_handler;
3112 dialog->finished = 0;
3113 list_init( &dialog->controls );
3115 /* verify that the dialog exists */
3116 rec = msi_get_dialog_record( dialog );
3119 msiobj_release( &package->hdr );
3123 dialog->attributes = MSI_RecordGetInteger( rec, 6 );
3124 dialog->control_default = strdupW( MSI_RecordGetString( rec, 9 ) );
3125 dialog->control_cancel = strdupW( MSI_RecordGetString( rec, 10 ) );
3126 msiobj_release( &rec->hdr );
3131 static void msi_process_pending_messages( HWND hdlg )
3135 while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
3137 if( hdlg && IsDialogMessageW( hdlg, &msg ))
3139 TranslateMessage( &msg );
3140 DispatchMessageW( &msg );
3144 void msi_dialog_end_dialog( msi_dialog *dialog )
3146 TRACE("%p\n", dialog);
3147 dialog->finished = 1;
3148 PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
3151 void msi_dialog_check_messages( HANDLE handle )
3155 /* in threads other than the UI thread, block */
3156 if( uiThreadId != GetCurrentThreadId() )
3159 WaitForSingleObject( handle, INFINITE );
3163 /* there's two choices for the UI thread */
3166 msi_process_pending_messages( NULL );
3172 * block here until somebody creates a new dialog or
3173 * the handle we're waiting on becomes ready
3175 r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
3176 if( r == WAIT_OBJECT_0 )
3181 UINT msi_dialog_run_message_loop( msi_dialog *dialog )
3186 if( uiThreadId != GetCurrentThreadId() )
3187 return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
3189 /* create the dialog window, don't show it yet */
3190 style = WS_OVERLAPPED;
3191 if( dialog->attributes & msidbDialogAttributesVisible )
3192 style |= WS_VISIBLE;
3194 hwnd = CreateWindowW( szMsiDialogClass, dialog->name, style,
3195 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
3196 NULL, NULL, NULL, dialog );
3199 ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
3200 return ERROR_FUNCTION_FAILED;
3203 ShowWindow( hwnd, SW_SHOW );
3204 /* UpdateWindow( hwnd ); - and causes the transparent static controls not to paint */
3206 if( dialog->attributes & msidbDialogAttributesModal )
3208 while( !dialog->finished )
3210 MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLINPUT );
3211 msi_process_pending_messages( dialog->hwnd );
3215 return ERROR_IO_PENDING;
3217 return ERROR_SUCCESS;
3220 void msi_dialog_do_preview( msi_dialog *dialog )
3223 dialog->attributes |= msidbDialogAttributesVisible;
3224 dialog->attributes &= ~msidbDialogAttributesModal;
3225 msi_dialog_run_message_loop( dialog );
3228 void msi_dialog_destroy( msi_dialog *dialog )
3230 if( uiThreadId != GetCurrentThreadId() )
3232 SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
3237 ShowWindow( dialog->hwnd, SW_HIDE );
3240 DestroyWindow( dialog->hwnd );
3242 /* destroy the list of controls */
3243 while( !list_empty( &dialog->controls ) )
3245 msi_control *t = LIST_ENTRY( list_head( &dialog->controls ),
3246 msi_control, entry );
3247 list_remove( &t->entry );
3248 /* leave dialog->hwnd - destroying parent destroys child windows */
3249 msi_free( t->property );
3250 msi_free( t->value );
3252 DeleteObject( t->hBitmap );
3254 DestroyIcon( t->hIcon );
3255 msi_free( t->tabnext );
3256 msi_free( t->type );
3259 FreeLibrary( t->hDll );
3262 /* destroy the list of fonts */
3263 while( dialog->font_list )
3265 msi_font *t = dialog->font_list;
3266 dialog->font_list = t->next;
3267 DeleteObject( t->hfont );
3270 msi_free( dialog->default_font );
3272 msi_free( dialog->control_default );
3273 msi_free( dialog->control_cancel );
3274 msiobj_release( &dialog->package->hdr );
3275 dialog->package = NULL;
3279 BOOL msi_dialog_register_class( void )
3283 ZeroMemory( &cls, sizeof cls );
3284 cls.lpfnWndProc = MSIDialog_WndProc;
3285 cls.hInstance = NULL;
3286 cls.hIcon = LoadIconW(0, (LPWSTR)IDI_APPLICATION);
3287 cls.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3288 cls.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
3289 cls.lpszMenuName = NULL;
3290 cls.lpszClassName = szMsiDialogClass;
3292 if( !RegisterClassW( &cls ) )
3295 cls.lpfnWndProc = MSIHiddenWindowProc;
3296 cls.lpszClassName = szMsiHiddenWindow;
3298 if( !RegisterClassW( &cls ) )
3301 uiThreadId = GetCurrentThreadId();
3303 hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
3304 0, 0, 100, 100, NULL, NULL, NULL, NULL );
3305 if( !hMsiHiddenWindow )
3311 void msi_dialog_unregister_class( void )
3313 DestroyWindow( hMsiHiddenWindow );
3314 hMsiHiddenWindow = NULL;
3315 UnregisterClassW( szMsiDialogClass, NULL );
3316 UnregisterClassW( szMsiHiddenWindow, NULL );