advapi32: Add stub for UnregisterTraceGuids.
[wine] / dlls / oledlg / insobjdlg.c
1 /*
2  *      OLEDLG library
3  *
4  *      Copyright 2003  Ulrich Czekalla for CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winreg.h"
27 #include "winternl.h"
28 #include "winerror.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
33
34 #include "oledlg.h"
35 #include "resource.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(oledlg);
38
39 typedef struct
40 {
41     HWND hwndSelf;
42     BOOL bObjListInit; /* Object list has been initialized */
43     LPOLEUIINSERTOBJECTA lpOleUIInsertObject;
44
45     HWND hwndObjTypeLBL;
46     HWND hwndObjTypeLB;
47     HWND hwndFileLBL;
48     HWND hwndFileTB;
49     HWND hwndCreateCtrlCB;
50     HWND hwndCreateNewCB;
51     HWND hwndCreateFromFileCB;
52     HWND hwndDisplayIconCB;
53     HWND hwndAddCtrlBTN;
54     HWND hwndBrowseBTN;
55     HWND hwndResultDesc;
56
57 } InsertObjectDlgInfo;
58
59 static INT_PTR CALLBACK UIInsertObjectDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
60 static LRESULT UIINSOBJDLG_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
61 static void UIINSERTOBJECTDLG_InitDialog(InsertObjectDlgInfo* pdlgInfo);
62 static void UIINSERTOBJECTDLG_SelectCreateCtrl(InsertObjectDlgInfo* pdlgInfo);
63 static void UIINSERTOBJECTDLG_SelectCreateFromFile(InsertObjectDlgInfo* pdlgInfo);
64 static void UIINSERTOBJECTDLG_SelectCreateNew(InsertObjectDlgInfo* pdlgInfo);
65 static BOOL UIINSERTOBJECTDLG_PopulateObjectTypes(InsertObjectDlgInfo* pdlgInfo);
66 static void UIINSERTOBJECTDLG_FreeObjectTypes(InsertObjectDlgInfo* pdlgInfo);
67 static void UIINSERTOBJECTDLG_SelChange(InsertObjectDlgInfo* pdlgInfo);
68 static BOOL UIINSERTOBJECTDLG_OnOpen(InsertObjectDlgInfo* pdlgInfo);
69 static void UIINSERTOBJECTDLG_BrowseFile(InsertObjectDlgInfo* pdlgInfo);
70 static void UIINSERTOBJECTDLG_AddControl(InsertObjectDlgInfo* pdlgInfo);
71
72 typedef HRESULT (*DLLREGISTER)          (void);
73
74 extern HINSTANCE OLEDLG_hInstance;
75 static const char OleUIInsertObjectInfoStr[] = "OleUIInsertObjectInfoStr";
76
77 /***********************************************************************
78  *           OleUIInsertObjectA (OLEDLG.3)
79  */
80 UINT WINAPI OleUIInsertObjectA(LPOLEUIINSERTOBJECTA lpOleUIInsertObject)
81 {
82   LRESULT lRes;
83   LPCVOID template;
84   HRSRC hRes;
85   InsertObjectDlgInfo dlgInfo;
86   HANDLE hDlgTmpl = 0;
87
88   if (lpOleUIInsertObject->lpszTemplate || lpOleUIInsertObject->hResource)
89      FIXME("Customized template not supported\n");
90
91   /* Create the dialog from a template */
92   if(!(hRes = FindResourceA(OLEDLG_hInstance,MAKEINTRESOURCEA(UIINSERTOBJECT),
93       (LPSTR)RT_DIALOG)))
94   {
95       return OLEUI_ERR_FINDTEMPLATEFAILURE;
96   }
97
98   if (!(hDlgTmpl = LoadResource(OLEDLG_hInstance, hRes )) ||
99       !(template = LockResource( hDlgTmpl )))
100   {
101       return OLEUI_ERR_LOADTEMPLATEFAILURE;
102   }
103
104   /* Initialize InsertObjectDlgInfo structure */
105   dlgInfo.lpOleUIInsertObject = lpOleUIInsertObject;
106   dlgInfo.bObjListInit = FALSE;
107
108   lRes = DialogBoxIndirectParamA(OLEDLG_hInstance, (const DLGTEMPLATE*) template,
109       lpOleUIInsertObject->hWndOwner, UIInsertObjectDlgProc,
110       (LPARAM) &dlgInfo);
111
112     /* Unable to create the dialog */
113     if( lRes == -1)
114         return OLEUI_ERR_DIALOGFAILURE;
115
116     return lRes;
117 }
118
119
120 /***********************************************************************
121  *          UIInsertObjectDlgProc
122  *
123  * OLE UI Insert Object dialog procedure
124  */
125 INT_PTR CALLBACK UIInsertObjectDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
126 {
127   InsertObjectDlgInfo* pdlgInfo = GetPropA(hwnd,OleUIInsertObjectInfoStr);
128
129   switch(uMsg)
130   {
131     case WM_INITDIALOG:
132     {
133         InsertObjectDlgInfo* pdlgInfo = (InsertObjectDlgInfo*)lParam;
134
135         pdlgInfo->hwndSelf = hwnd;
136
137         SetPropA(hwnd, OleUIInsertObjectInfoStr, pdlgInfo);
138
139         UIINSERTOBJECTDLG_InitDialog(pdlgInfo);
140
141         return 0;
142     }
143
144     case WM_COMMAND:
145       return UIINSOBJDLG_OnWMCommand(hwnd, wParam, lParam);
146
147     case WM_DESTROY:
148       if (pdlgInfo)
149           UIINSERTOBJECTDLG_FreeObjectTypes(pdlgInfo);
150       RemovePropA(hwnd, OleUIInsertObjectInfoStr);
151       return FALSE;
152
153     default :
154       return FALSE;
155   }
156 }
157
158
159 /***********************************************************************
160  *      UIINSOBJDLG_OnWMCommand
161  *
162  * WM_COMMAND message handler
163  */
164 static LRESULT UIINSOBJDLG_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
165 {
166   WORD wNotifyCode = HIWORD(wParam);
167   WORD wID = LOWORD(wParam);
168   InsertObjectDlgInfo* pdlgInfo = GetPropA(hwnd,OleUIInsertObjectInfoStr);
169
170   switch(wID)
171   {
172     case IDOK:
173       EndDialog(hwnd, UIINSERTOBJECTDLG_OnOpen(pdlgInfo));
174       break;
175
176     case IDCANCEL:
177       EndDialog(hwnd, FALSE);
178       break;
179
180     case IDC_CREATECONTROL:
181       UIINSERTOBJECTDLG_SelectCreateCtrl(pdlgInfo);
182       break;
183
184     case IDC_CREATENEW:
185       UIINSERTOBJECTDLG_SelectCreateNew(pdlgInfo);
186       break;
187
188     case IDC_CREATEFROMFILE:
189       UIINSERTOBJECTDLG_SelectCreateFromFile(pdlgInfo);
190       break;
191
192     case IDC_BROWSE:
193       UIINSERTOBJECTDLG_BrowseFile(pdlgInfo);
194       break;
195
196     case IDC_ADDCONTROL:
197       UIINSERTOBJECTDLG_AddControl(pdlgInfo);
198
199     case IDC_OBJTYPELIST:
200     {
201       if (wNotifyCode == LBN_SELCHANGE)
202         UIINSERTOBJECTDLG_SelChange(pdlgInfo);
203       break;
204     }
205   }
206   return 0;
207 }
208
209
210 /***********************************************************************
211  *      UIINSERTOBJECTDLG_InitDialog
212  *
213  * Initialize dialog display
214  */
215 static void UIINSERTOBJECTDLG_InitDialog(InsertObjectDlgInfo* pdlgInfo)
216 {
217   /* Initialize InsertObjectDlgInfo data structure */
218   pdlgInfo->hwndObjTypeLB = GetDlgItem(pdlgInfo->hwndSelf, IDC_OBJTYPELIST);
219   pdlgInfo->hwndObjTypeLBL = GetDlgItem(pdlgInfo->hwndSelf, IDC_OBJTYPELBL);
220   pdlgInfo->hwndFileLBL = GetDlgItem(pdlgInfo->hwndSelf, IDC_FILELBL);
221   pdlgInfo->hwndFileTB = GetDlgItem(pdlgInfo->hwndSelf, IDC_FILE);
222   pdlgInfo->hwndCreateCtrlCB = GetDlgItem(pdlgInfo->hwndSelf, IDC_CREATECONTROL);
223   pdlgInfo->hwndCreateNewCB = GetDlgItem(pdlgInfo->hwndSelf, IDC_CREATENEW);
224   pdlgInfo->hwndCreateFromFileCB = GetDlgItem(pdlgInfo->hwndSelf, IDC_CREATEFROMFILE);
225   pdlgInfo->hwndDisplayIconCB = GetDlgItem(pdlgInfo->hwndSelf, IDC_ASICON);
226   pdlgInfo->hwndAddCtrlBTN = GetDlgItem(pdlgInfo->hwndSelf, IDC_ADDCONTROL);
227   pdlgInfo->hwndBrowseBTN = GetDlgItem(pdlgInfo->hwndSelf, IDC_BROWSE);
228   pdlgInfo->hwndResultDesc = GetDlgItem(pdlgInfo->hwndSelf, IDC_RESULTDESC);
229
230   /* Setup dialog controls based on flags */
231   if (pdlgInfo->lpOleUIInsertObject->lpszCaption)
232      SetWindowTextA(pdlgInfo->hwndSelf, pdlgInfo->lpOleUIInsertObject->lpszCaption);
233
234   ShowWindow(pdlgInfo->hwndCreateCtrlCB, (pdlgInfo->lpOleUIInsertObject->dwFlags &
235     IOF_SHOWINSERTCONTROL) ? SW_SHOW : SW_HIDE);
236   ShowWindow(pdlgInfo->hwndDisplayIconCB, (pdlgInfo->lpOleUIInsertObject->dwFlags &
237     IOF_CHECKDISPLAYASICON) ? SW_SHOW : SW_HIDE);
238   EnableWindow(pdlgInfo->hwndDisplayIconCB, (pdlgInfo->lpOleUIInsertObject->dwFlags &
239     IOF_DISABLEDISPLAYASICON) ? FALSE : TRUE);
240
241   if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_SELECTCREATECONTROL)
242     UIINSERTOBJECTDLG_SelectCreateCtrl(pdlgInfo);
243   else if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_SELECTCREATEFROMFILE)
244     UIINSERTOBJECTDLG_SelectCreateFromFile(pdlgInfo);
245   else /* (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_SELECTCREATENEW) */
246     UIINSERTOBJECTDLG_SelectCreateNew(pdlgInfo);
247 }
248
249
250 /***********************************************************************
251  *      UIINSERTOBJECTDLG_SelectCreateCtrl
252  *
253  * Select Create Control Radio Button
254  */
255 static void UIINSERTOBJECTDLG_SelectCreateCtrl(InsertObjectDlgInfo* pdlgInfo)
256 {
257   ShowWindow(pdlgInfo->hwndDisplayIconCB, SW_HIDE);
258   ShowWindow(pdlgInfo->hwndFileLBL, SW_HIDE);
259   ShowWindow(pdlgInfo->hwndFileTB, SW_HIDE);
260   ShowWindow(pdlgInfo->hwndBrowseBTN, SW_HIDE);
261
262   ShowWindow(pdlgInfo->hwndObjTypeLBL, SW_SHOW);
263   ShowWindow(pdlgInfo->hwndObjTypeLB, SW_SHOW);
264   ShowWindow(pdlgInfo->hwndAddCtrlBTN, SW_SHOW);
265
266   SendMessageA(pdlgInfo->hwndCreateCtrlCB, BM_SETCHECK, BST_CHECKED, 0);
267
268   /* Populate object type listbox */
269   if (!pdlgInfo->bObjListInit)
270      UIINSERTOBJECTDLG_PopulateObjectTypes(pdlgInfo);
271 }
272
273
274 /***********************************************************************
275  *      UIINSERTOBJECTDLG_SelectCreateNew
276  *
277  * Select Create New Radio Button
278  */
279 static void UIINSERTOBJECTDLG_SelectCreateNew(InsertObjectDlgInfo* pdlgInfo)
280 {
281   ShowWindow(pdlgInfo->hwndFileLBL, SW_HIDE);
282   ShowWindow(pdlgInfo->hwndFileTB, SW_HIDE);
283   ShowWindow(pdlgInfo->hwndAddCtrlBTN, SW_HIDE);
284   ShowWindow(pdlgInfo->hwndBrowseBTN, SW_HIDE);
285
286   if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CHECKDISPLAYASICON)
287     ShowWindow(pdlgInfo->hwndDisplayIconCB, SW_SHOW);
288
289   ShowWindow(pdlgInfo->hwndObjTypeLBL, SW_SHOW);
290   ShowWindow(pdlgInfo->hwndObjTypeLB, SW_SHOW);
291
292   SendMessageA(pdlgInfo->hwndCreateNewCB, BM_SETCHECK, BST_CHECKED, 0);
293
294   if (!pdlgInfo->bObjListInit)
295      UIINSERTOBJECTDLG_PopulateObjectTypes(pdlgInfo);
296
297   UIINSERTOBJECTDLG_SelChange(pdlgInfo);
298 }
299
300
301 /***********************************************************************
302  *      UIINSERTOBJECTDLG_SelectCreateFromFile
303  *
304  * Select Create From File Radio Button
305  */
306 static void UIINSERTOBJECTDLG_SelectCreateFromFile(InsertObjectDlgInfo* pdlgInfo)
307 {
308   WCHAR resstr[MAX_PATH];
309
310   ShowWindow(pdlgInfo->hwndAddCtrlBTN, SW_HIDE);
311   ShowWindow(pdlgInfo->hwndObjTypeLBL, SW_HIDE);
312   ShowWindow(pdlgInfo->hwndObjTypeLB, SW_HIDE);
313
314   if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CHECKDISPLAYASICON)
315     ShowWindow(pdlgInfo->hwndDisplayIconCB, SW_SHOW);
316
317   ShowWindow(pdlgInfo->hwndFileLBL, SW_SHOW);
318   ShowWindow(pdlgInfo->hwndFileTB, SW_SHOW);
319   ShowWindow(pdlgInfo->hwndBrowseBTN, SW_SHOW);
320
321   SendMessageW(pdlgInfo->hwndCreateFromFileCB, BM_SETCHECK, BST_CHECKED, 0);
322
323   if (LoadStringW(OLEDLG_hInstance, IDS_RESULTFILEOBJDESC, resstr, MAX_PATH))
324      SendMessageW(pdlgInfo->hwndResultDesc, WM_SETTEXT, 0, (LPARAM)resstr);
325 }
326
327
328 /***********************************************************************
329  *      UIINSERTOBJECTDLG_PopulateObjectTypes
330  *
331  * Populate Object Type listbox
332  */
333 static BOOL UIINSERTOBJECTDLG_PopulateObjectTypes(InsertObjectDlgInfo* pdlgInfo)
334 {
335   static const WCHAR szClsid[] = {'C','L','S','I','D',0};
336   static const WCHAR szInsertable[] = {'I','n','s','e','r','t','a','b','l','e',0};
337   static const WCHAR szNotInsertable[] = {'N','o','t','I','n','s','e','r','t','a','b','l','e',0};
338   DWORD i;
339   LONG len;
340   HKEY hkclsids;
341   HKEY hkey;
342   CLSID clsid;
343   LSTATUS ret;
344   WCHAR keydesc[MAX_PATH];
345   WCHAR keyname[MAX_PATH];
346   WCHAR szclsid[128];
347   DWORD index = 0;
348
349   UIINSERTOBJECTDLG_FreeObjectTypes(pdlgInfo);
350
351   RegOpenKeyExW(HKEY_CLASSES_ROOT, szClsid, 0, KEY_READ, &hkclsids);
352
353   while (ERROR_SUCCESS == (ret = RegEnumKeyW(hkclsids, index, szclsid, sizeof(szclsid)/sizeof(szclsid[0]))))
354   {
355     index++;
356
357     RegOpenKeyExW(hkclsids, szclsid, 0, KEY_READ, &hkey);
358
359     len = sizeof(keyname);
360     if (ERROR_SUCCESS != RegQueryValueW(hkey, szInsertable, keyname, &len))
361         continue;
362
363     len = sizeof(keyname);
364     if (ERROR_SUCCESS == RegQueryValueW(hkey, szNotInsertable, keyname, &len))
365         continue;
366
367     CLSIDFromString(szclsid, &clsid);
368
369     for (i = 0; i < pdlgInfo->lpOleUIInsertObject->cClsidExclude; i++)
370       if (IsEqualGUID(&pdlgInfo->lpOleUIInsertObject->lpClsidExclude[i], &clsid))
371         break;
372
373     if (i < pdlgInfo->lpOleUIInsertObject->cClsidExclude)
374       continue;
375
376     len = sizeof(keydesc);
377     if (ERROR_SUCCESS == RegQueryValueW(hkey, NULL, keydesc, &len))
378     {
379        CLSID* lpclsid = HeapAlloc(GetProcessHeap(), 0, sizeof(CLSID));
380        *lpclsid = clsid;
381
382        len = SendMessageW(pdlgInfo->hwndObjTypeLB, LB_ADDSTRING, 0, (LPARAM)keydesc);
383        SendMessageW(pdlgInfo->hwndObjTypeLB, LB_SETITEMDATA, (WPARAM)len, (LPARAM)lpclsid);
384     }
385   }
386
387   pdlgInfo->bObjListInit = (ret == ERROR_NO_MORE_ITEMS);
388
389   return pdlgInfo->bObjListInit;
390 }
391
392
393 /***********************************************************************
394  *      UIINSERTOBJECTDLG_FreeObjectTypes
395  *
396  * Free Object Types listbox
397  */
398 static void UIINSERTOBJECTDLG_FreeObjectTypes(InsertObjectDlgInfo* pdlgInfo)
399 {
400   UINT i, count;
401
402   count = SendMessageA(pdlgInfo->hwndObjTypeLB, LB_GETCOUNT, 0, 0);
403
404   for (i = 0; i < count; i++)
405   {
406       CLSID* lpclsid = (CLSID*) SendMessageA(pdlgInfo->hwndObjTypeLB, 
407          LB_GETITEMDATA, i, 0);
408       HeapFree(GetProcessHeap(), 0, lpclsid);
409   }
410 }
411
412
413 /***********************************************************************
414  *      UIINSERTOBJECTDLG_SelChange
415  *
416  * Handle object type selection change
417  */
418 static void UIINSERTOBJECTDLG_SelChange(InsertObjectDlgInfo* pdlgInfo)
419 {
420   INT index;
421   WCHAR objname[MAX_PATH];
422   WCHAR objdesc[MAX_PATH];
423   WCHAR resstr[MAX_PATH];
424
425   TRACE("\n");
426
427   if (LoadStringW(OLEDLG_hInstance, IDS_RESULTOBJDESC, resstr, MAX_PATH) &&
428      ((index = SendMessageW(pdlgInfo->hwndObjTypeLB, LB_GETCURSEL, 0, 0)) >= 0) &&
429      SendMessageW(pdlgInfo->hwndObjTypeLB, LB_GETTEXT, (WPARAM)index, (LPARAM)objname))
430        wsprintfW(objdesc, resstr, objname);
431   else
432     objdesc[0] = 0;
433
434   SendMessageW(pdlgInfo->hwndResultDesc, WM_SETTEXT, 0, (LPARAM)objdesc);
435 }
436
437
438 /***********************************************************************
439  *      UIINSERTOBJECTDLG_SelChange
440  *
441  * Handle OK Button
442  */
443 static BOOL UIINSERTOBJECTDLG_OnOpen(InsertObjectDlgInfo* pdlgInfo)
444 {
445   BOOL bret = FALSE;
446
447   if (BST_CHECKED == SendMessageA(pdlgInfo->hwndCreateCtrlCB, BM_GETCHECK, 0, 0) ||
448       BST_CHECKED == SendMessageA(pdlgInfo->hwndCreateNewCB, BM_GETCHECK, 0, 0))
449   {
450     INT index = SendMessageA(pdlgInfo->hwndObjTypeLB, LB_GETCURSEL, 0, 0);
451
452     if (index >= 0)
453     {
454        CLSID* clsid = (CLSID*) SendMessageA(pdlgInfo->hwndObjTypeLB, 
455           LB_GETITEMDATA, (WPARAM)index, 0);
456        pdlgInfo->lpOleUIInsertObject->clsid = *clsid;
457
458        if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CREATENEWOBJECT)
459        {
460           pdlgInfo->lpOleUIInsertObject->sc= OleCreate(
461              &pdlgInfo->lpOleUIInsertObject->clsid,
462              &pdlgInfo->lpOleUIInsertObject->iid,
463              pdlgInfo->lpOleUIInsertObject->oleRender,
464              pdlgInfo->lpOleUIInsertObject->lpFormatEtc,
465              pdlgInfo->lpOleUIInsertObject->lpIOleClientSite,
466              pdlgInfo->lpOleUIInsertObject->lpIStorage,
467              pdlgInfo->lpOleUIInsertObject->ppvObj);
468        }
469
470        bret = TRUE;
471     }
472   }
473   else if (BST_CHECKED == SendMessageA(pdlgInfo->hwndCreateFromFileCB, BM_GETCHECK, 0, 0))
474   {
475     if (pdlgInfo->lpOleUIInsertObject->lpszFile)
476     {
477       HRESULT hres;
478       WCHAR wcsFile[MAX_PATH];
479
480       if (SendMessageW(pdlgInfo->hwndFileTB, WM_GETTEXT, MAX_PATH, (LPARAM)wcsFile))
481           WideCharToMultiByte(CP_ACP, 0, wcsFile, -1,
482               pdlgInfo->lpOleUIInsertObject->lpszFile, pdlgInfo->lpOleUIInsertObject->cchFile, NULL, NULL);
483
484       if (ERROR_SUCCESS == (hres = GetClassFile(wcsFile, &pdlgInfo->lpOleUIInsertObject->clsid)))
485       {
486          if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CREATEFILEOBJECT)
487          {
488            hres = OleCreateFromFile(
489              &pdlgInfo->lpOleUIInsertObject->clsid,
490              wcsFile,
491              &pdlgInfo->lpOleUIInsertObject->iid,
492              pdlgInfo->lpOleUIInsertObject->oleRender,
493              pdlgInfo->lpOleUIInsertObject->lpFormatEtc,
494              pdlgInfo->lpOleUIInsertObject->lpIOleClientSite,
495              pdlgInfo->lpOleUIInsertObject->lpIStorage,
496              pdlgInfo->lpOleUIInsertObject->ppvObj);
497          }
498
499          bret = TRUE;
500       }
501       pdlgInfo->lpOleUIInsertObject->sc = hres;
502     }
503   }
504
505   return bret;
506 }
507
508
509 /***********************************************************************
510  *      UIINSERTOBJECTDLG_BrowseFile
511  *
512  * Browse for the file
513  */
514 static void UIINSERTOBJECTDLG_BrowseFile(InsertObjectDlgInfo* pdlgInfo)
515 {
516    OPENFILENAMEA fn;
517    char fname[MAX_PATH];
518    char title[32];
519
520    fn.lStructSize = sizeof(OPENFILENAMEA);
521    fn.hwndOwner = pdlgInfo->hwndSelf;
522    fn.hInstance = 0;
523    fn.lpstrFilter = "All Files\0*.*\0\0";
524    fn.lpstrCustomFilter = NULL;
525    fn.nMaxCustFilter = 0;
526    fn.nFilterIndex = 0;
527
528    SendMessageA(pdlgInfo->hwndFileTB, WM_GETTEXT, (WPARAM)MAX_PATH, (LPARAM)fname);
529    fn.lpstrFile = fname;
530    fn.nMaxFile = MAX_PATH;
531
532    fn.lpstrFileTitle = NULL;
533    fn.nMaxFileTitle = 0;
534    fn.lpstrInitialDir = NULL;
535
536    LoadStringA(OLEDLG_hInstance, IDS_BROWSE, title, 32);
537    fn.lpstrTitle = title;
538
539    fn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST |
540       OFN_HIDEREADONLY | OFN_LONGNAMES;
541    fn.nFileOffset = 0;
542    fn.nFileExtension = 0;
543    fn.lpstrDefExt = NULL;
544    fn.lCustData = 0;
545    fn.lpfnHook = NULL;
546    fn.lpTemplateName = NULL;
547
548    if (GetOpenFileNameA(&fn))
549       SendMessageA(pdlgInfo->hwndFileTB, WM_SETTEXT, 0, (LPARAM)fn.lpstrFile);
550 }
551
552
553 /***********************************************************************
554  *      UIINSERTOBJECTDLG_AddControl
555  *
556  * Add control to Object Type
557  */
558 static void UIINSERTOBJECTDLG_AddControl(InsertObjectDlgInfo* pdlgInfo)
559 {
560    OPENFILENAMEA fn;
561    char fname[MAX_PATH];
562    char title[32];
563
564    fn.lStructSize = sizeof(OPENFILENAMEA);
565    fn.hwndOwner = pdlgInfo->hwndSelf;
566    fn.hInstance = 0;
567    fn.lpstrFilter = "OLE Controls\0*.ocx\0Libraries\0*.dll\0All Files\0*.*\0\0";
568    fn.lpstrCustomFilter = NULL;
569    fn.nMaxCustFilter = 0;
570    fn.nFilterIndex = 0;
571
572    fname[0] = 0;
573    fn.lpstrFile = fname;
574    fn.nMaxFile = MAX_PATH;
575
576    fn.lpstrFileTitle = NULL;
577    fn.nMaxFileTitle = 0;
578    fn.lpstrInitialDir = NULL;
579
580    LoadStringA(OLEDLG_hInstance, IDS_BROWSE, title, 32);
581    fn.lpstrTitle = title;
582
583    fn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST |
584       OFN_HIDEREADONLY | OFN_LONGNAMES;
585    fn.nFileOffset = 0;
586    fn.nFileExtension = 0;
587    fn.lpstrDefExt = NULL;
588    fn.lCustData = 0;
589    fn.lpfnHook = NULL;
590    fn.lpTemplateName = NULL;
591
592    if (GetOpenFileNameA(&fn))
593    {
594       HMODULE hMod;
595       BOOL bValid = FALSE;
596
597       hMod = LoadLibraryA(fn.lpstrFile);
598
599       if (hMod)
600       {
601           DLLREGISTER regproc;
602
603           regproc = (DLLREGISTER) GetProcAddress(hMod, "DllRegisterServer");
604           if (regproc)
605           {
606              if (S_OK == regproc())
607              {
608                 UIINSERTOBJECTDLG_PopulateObjectTypes(pdlgInfo);
609                 bValid = TRUE;
610              }
611           }
612
613           FreeLibrary(hMod);
614       }
615
616       if (!bValid)
617       {
618           WCHAR title[32];
619           WCHAR msg[256];
620
621           LoadStringW(OLEDLG_hInstance, IDS_NOTOLEMODCAPTION, title, 32);
622           LoadStringW(OLEDLG_hInstance, IDS_NOTOLEMOD, msg, 256);
623
624           MessageBoxW(pdlgInfo->hwndSelf, msg, title, MB_ICONEXCLAMATION);
625       }
626    }
627 }