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