push 6ad4febc802779d39881ae7cccabf16fa19e6741
[wine/hacks.git] / programs / oleview / tree.c
blob70391d7166d3a6637d82a4f8ef69f77f66f63f0b
1 /*
2 * OleView (tree.c)
4 * Copyright 2006 Piotr Caban
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
21 #include "main.h"
23 TREE tree;
24 static const WCHAR wszCLSID[] = { 'C','L','S','I','D','\\','\0' };
25 static const WCHAR wszInProcServer32[] =
26 { 'I','n','P','r','o','c','S','e','r','v','e','r','3','2','\0' };
27 static const WCHAR wszOle32dll[] = { 'o','l','e','3','2','.','d','l','l','\0' };
28 static const WCHAR wszOleAut32dll[] =
29 { 'o','l','e','a','u','t','3','2','.','d','l','l','\0' };
30 static const WCHAR wszImplementedCategories[] =
31 { 'I','m','p','l','e','m','e','n','t','e','d',' ',
32 'C','a','t','e','g','o','r','i','e','s','\0' };
33 static const WCHAR wszAppID[] = { 'A','p','p','I','D','\\','\0' };
34 static const WCHAR wszTypeLib[] = { 'T','y','p','e','L','i','b','\\','\0' };
35 static const WCHAR wszInterface[] = { 'I','n','t','e','r','f','a','c','e','\\','\0' };
36 static const WCHAR wszComponentCategories[] = { 'C','o','m','p','o','n','e','n','t',
37 ' ','C','a','t','e','g','o','r','i','e','s','\\','\0' };
38 static const WCHAR wszGetPath[] = { '0','\\','w','i','n','3','2','\0' };
40 static LPARAM CreateITEM_INFO(INT flag, const WCHAR *info, const WCHAR *clsid, const WCHAR *path)
42 ITEM_INFO *reg;
44 reg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ITEM_INFO));
46 reg->cFlag = flag;
47 lstrcpyW(reg->info, info);
48 if(clsid) lstrcpyW(reg->clsid, clsid);
49 if(path) lstrcpyW(reg->path, path);
51 return (LPARAM)reg;
54 void CreateInst(HTREEITEM item, WCHAR *wszMachineName)
56 TVITEM tvi;
57 HTREEITEM hCur;
58 TVINSERTSTRUCT tvis;
59 WCHAR wszTitle[MAX_LOAD_STRING];
60 WCHAR wszMessage[MAX_LOAD_STRING];
61 WCHAR wszFlagName[MAX_LOAD_STRING];
62 WCHAR wszTreeName[MAX_LOAD_STRING];
63 WCHAR wszRegPath[MAX_LOAD_STRING];
64 const WCHAR wszFormat[] = { '\n','%','s',' ','(','$','%','x',')','\n','\0' };
65 CLSID clsid;
66 COSERVERINFO remoteInfo;
67 MULTI_QI qi;
68 IUnknown *obj, *unk;
69 HRESULT hRes;
71 memset(&tvi, 0, sizeof(TVITEM));
72 tvi.mask = TVIF_TEXT;
73 tvi.hItem = item;
74 tvi.cchTextMax = MAX_LOAD_STRING;
75 tvi.pszText = wszTreeName;
77 memset(&tvis, 0, sizeof(TVINSERTSTRUCT));
78 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
79 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
80 tvis.hInsertAfter = (HTREEITEM)TVI_FIRST;
81 U(tvis).item.pszText = tvi.pszText;
82 tvis.hParent = item;
83 tvis.hInsertAfter = TVI_LAST;
85 SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
87 if(!tvi.lParam || ((ITEM_INFO *)tvi.lParam)->loaded
88 || !(((ITEM_INFO *)tvi.lParam)->cFlag&SHOWALL)) return;
90 if(FAILED(CLSIDFromString(((ITEM_INFO *)tvi.lParam)->clsid, &clsid))) return;
92 if(wszMachineName)
94 remoteInfo.dwReserved1 = 0;
95 remoteInfo.dwReserved2 = 0;
96 remoteInfo.pAuthInfo = NULL;
97 remoteInfo.pwszName = wszMachineName;
99 qi.pIID = &IID_IUnknown;
101 CoCreateInstanceEx(&clsid, NULL, globals.dwClsCtx|CLSCTX_REMOTE_SERVER,
102 &remoteInfo, 1, &qi);
103 hRes = qi.hr;
104 obj = qi.pItf;
106 else hRes = CoCreateInstance(&clsid, NULL, globals.dwClsCtx,
107 &IID_IUnknown, (void **)&obj);
109 if(FAILED(hRes))
111 LoadString(globals.hMainInst, IDS_CGCOFAIL, wszMessage,
112 sizeof(wszMessage)/sizeof(wszMessage[0]));
113 LoadString(globals.hMainInst, IDS_ABOUT, wszTitle,
114 sizeof(wszTitle)/sizeof(wszTitle[0]));
116 #define CASE_ERR(i) case i: \
117 MultiByteToWideChar(CP_ACP, 0, #i, -1, wszFlagName, MAX_LOAD_STRING); \
118 break
120 switch(hRes)
122 CASE_ERR(REGDB_E_CLASSNOTREG);
123 CASE_ERR(E_NOINTERFACE);
124 CASE_ERR(REGDB_E_READREGDB);
125 CASE_ERR(REGDB_E_KEYMISSING);
126 CASE_ERR(CO_E_DLLNOTFOUND);
127 CASE_ERR(CO_E_APPNOTFOUND);
128 CASE_ERR(E_ACCESSDENIED);
129 CASE_ERR(CO_E_ERRORINDLL);
130 CASE_ERR(CO_E_APPDIDNTREG);
131 CASE_ERR(CLASS_E_CLASSNOTAVAILABLE);
132 default:
133 LoadString(globals.hMainInst, IDS_ERROR_UNKN, wszFlagName, sizeof(wszFlagName)/sizeof(wszFlagName[0]));
136 wsprintfW(&wszMessage[lstrlenW(wszMessage)], wszFormat,
137 wszFlagName, (unsigned)hRes);
138 MessageBox(globals.hMainWnd, wszMessage, wszTitle, MB_OK|MB_ICONEXCLAMATION);
139 return;
142 ((ITEM_INFO *)tvi.lParam)->loaded = 1;
143 ((ITEM_INFO *)tvi.lParam)->pU = obj;
145 tvi.mask = TVIF_STATE;
146 tvi.state = TVIS_BOLD;
147 tvi.stateMask = TVIS_BOLD;
148 SendMessage(globals.hTree, TVM_SETITEM, 0, (LPARAM)&tvi);
150 tvi.mask = TVIF_TEXT;
151 hCur = TreeView_GetChild(globals.hTree, tree.hI);
153 while(hCur)
155 tvi.hItem = hCur;
156 SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
158 if(!tvi.lParam)
160 hCur = TreeView_GetNextSibling(globals.hTree, hCur);
161 continue;
164 CLSIDFromString(((ITEM_INFO *)tvi.lParam)->clsid, &clsid);
165 hRes = IUnknown_QueryInterface(obj, &clsid, (void *)&unk);
167 if(SUCCEEDED(hRes))
169 IUnknown_Release(unk);
171 lstrcpyW(wszRegPath, wszInterface);
172 lstrcpyW(&wszRegPath[lstrlenW(wszRegPath)], ((ITEM_INFO *)tvi.lParam)->clsid);
173 U(tvis).item.lParam = CreateITEM_INFO(REGTOP|INTERFACE|REGPATH,
174 wszRegPath, ((ITEM_INFO *)tvi.lParam)->clsid, NULL);
175 SendMessage(globals.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
177 hCur = TreeView_GetNextSibling(globals.hTree, hCur);
180 RefreshMenu(item);
181 RefreshDetails(item);
184 void ReleaseInst(HTREEITEM item)
186 TVITEM tvi;
187 HTREEITEM cur;
188 IUnknown *pU;
190 memset(&tvi, 0, sizeof(TVITEM));
191 tvi.hItem = item;
192 SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
194 if(!tvi.lParam) return;
196 pU = ((ITEM_INFO *)tvi.lParam)->pU;
198 if(pU) IUnknown_Release(pU);
199 ((ITEM_INFO *)tvi.lParam)->loaded = 0;
201 SendMessage(globals.hTree, TVM_EXPAND, TVE_COLLAPSE, (LPARAM)item);
203 cur = TreeView_GetChild(globals.hTree, item);
204 while(cur)
206 SendMessage(globals.hTree, TVM_DELETEITEM, 0, (LPARAM)cur);
207 cur = TreeView_GetChild(globals.hTree, item);
210 tvi.mask = TVIF_CHILDREN|TVIF_STATE;
211 tvi.state = 0;
212 tvi.stateMask = TVIS_BOLD;
213 tvi.cChildren = 1;
214 SendMessage(globals.hTree, TVM_SETITEM, 0, (LPARAM)&tvi);
217 BOOL CreateRegPath(HTREEITEM item, WCHAR *buffer, int bufSize)
219 TVITEM tvi;
220 int bufLen;
221 BOOL ret;
223 memset(buffer, 0, sizeof(WCHAR[bufSize]));
224 memset(&tvi, 0, sizeof(TVITEM));
225 tvi.hItem = item;
227 SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
228 ret = (tvi.lParam && ((ITEM_INFO *)tvi.lParam)->cFlag & REGPATH);
230 while(TRUE)
232 SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
234 if(tvi.lParam && (((ITEM_INFO *)tvi.lParam)->cFlag & (REGPATH|REGTOP)))
236 bufLen = lstrlenW(((ITEM_INFO *)tvi.lParam)->info);
237 memmove(&buffer[bufLen], buffer, sizeof(WCHAR[bufSize-bufLen]));
238 memcpy(buffer, ((ITEM_INFO *)tvi.lParam)->info, sizeof(WCHAR[bufLen]));
241 if(tvi.lParam && ((ITEM_INFO *)tvi.lParam)->cFlag & REGTOP) break;
243 if(!tvi.lParam) return FALSE;
245 tvi.hItem = TreeView_GetParent(globals.hTree, tvi.hItem);
247 return ret;
250 static void AddCOMandAll(void)
252 TVINSERTSTRUCT tvis;
253 TVITEM tvi;
254 HTREEITEM curSearch;
255 HKEY hKey, hCurKey, hInfo;
256 WCHAR valName[MAX_LOAD_STRING];
257 WCHAR buffer[MAX_LOAD_STRING];
258 WCHAR wszComp[MAX_LOAD_STRING];
259 LONG lenBuffer;
260 int i=-1;
262 memset(&tvi, 0, sizeof(TVITEM));
263 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM|TVIF_CHILDREN;
264 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
265 U(tvis).item.cChildren = 1;
266 tvis.hInsertAfter = (HTREEITEM)TVI_FIRST;
268 if(RegOpenKey(HKEY_CLASSES_ROOT, wszCLSID, &hKey) != ERROR_SUCCESS) return;
270 while(TRUE)
272 i++;
274 if(RegEnumKey(hKey, i, valName, sizeof(valName)/sizeof(valName[0])) != ERROR_SUCCESS) break;
276 if(RegOpenKey(hKey, valName, &hCurKey) != ERROR_SUCCESS) continue;
278 lenBuffer = sizeof(WCHAR[MAX_LOAD_STRING]);
279 tvis.hParent = tree.hAO;
281 if(RegOpenKey(hCurKey, wszInProcServer32, &hInfo) == ERROR_SUCCESS)
283 if(RegQueryValue(hInfo, NULL, buffer, &lenBuffer) == ERROR_SUCCESS
284 && *buffer)
285 if(!memcmp(buffer, wszOle32dll, sizeof(WCHAR[9]))
286 ||!memcmp(buffer, wszOleAut32dll, sizeof(WCHAR[12])))
287 tvis.hParent = tree.hCLO;
289 RegCloseKey(hInfo);
292 lenBuffer = sizeof(WCHAR[MAX_LOAD_STRING]);
294 if(RegQueryValue(hCurKey, NULL, buffer, &lenBuffer) == ERROR_SUCCESS && *buffer)
295 U(tvis).item.pszText = buffer;
296 else U(tvis).item.pszText = valName;
298 U(tvis).item.lParam = CreateITEM_INFO(REGPATH|SHOWALL, valName, valName, NULL);
299 if(tvis.hParent) SendMessage(globals.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
301 if(RegOpenKey(hCurKey, wszImplementedCategories, &hInfo) == ERROR_SUCCESS)
303 if(RegEnumKey(hInfo, 0, wszComp, sizeof(wszComp)/sizeof(wszComp[0])) != ERROR_SUCCESS) break;
305 RegCloseKey(hInfo);
307 if(tree.hGBCC) curSearch = TreeView_GetChild(globals.hTree, tree.hGBCC);
308 else curSearch = TreeView_GetChild(globals.hTree, TVI_ROOT);
310 while(curSearch)
312 tvi.hItem = curSearch;
313 SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
315 if(tvi.lParam && !lstrcmpW(((ITEM_INFO *)tvi.lParam)->info, wszComp))
317 tvis.hParent = curSearch;
319 memmove(&valName[6], valName, sizeof(WCHAR[MAX_LOAD_STRING-6]));
320 memmove(valName, wszCLSID, sizeof(WCHAR[6]));
321 U(tvis).item.lParam = CreateITEM_INFO(REGTOP|REGPATH|SHOWALL,
322 valName, &valName[6], NULL);
324 SendMessage(globals.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
325 break;
327 curSearch = TreeView_GetNextSibling(globals.hTree, curSearch);
330 RegCloseKey(hCurKey);
332 RegCloseKey(hKey);
334 SendMessage(globals.hTree, TVM_SORTCHILDREN, FALSE, (LPARAM)tree.hCLO);
335 SendMessage(globals.hTree, TVM_SORTCHILDREN, FALSE, (LPARAM)tree.hAO);
338 static void AddApplicationID(void)
340 TVINSERTSTRUCT tvis;
341 HKEY hKey, hCurKey;
342 WCHAR valName[MAX_LOAD_STRING];
343 WCHAR buffer[MAX_LOAD_STRING];
344 LONG lenBuffer;
345 int i=-1;
347 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
348 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
349 tvis.hInsertAfter = (HTREEITEM)TVI_FIRST;
350 tvis.hParent = tree.hAID;
352 if(RegOpenKey(HKEY_CLASSES_ROOT, wszAppID, &hKey) != ERROR_SUCCESS) return;
354 while(TRUE)
356 i++;
358 if(RegEnumKey(hKey, i, valName, sizeof(valName)/sizeof(valName[0])) != ERROR_SUCCESS) break;
360 if(RegOpenKey(hKey, valName, &hCurKey) != ERROR_SUCCESS) continue;
362 lenBuffer = sizeof(WCHAR[MAX_LOAD_STRING]);
364 if(RegQueryValue(hCurKey, NULL, buffer, &lenBuffer) == ERROR_SUCCESS && *buffer)
365 U(tvis).item.pszText = buffer;
366 else U(tvis).item.pszText = valName;
368 RegCloseKey(hCurKey);
370 U(tvis).item.lParam = CreateITEM_INFO(REGPATH, valName, valName, NULL);
371 SendMessage(globals.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
373 RegCloseKey(hKey);
375 SendMessage(globals.hTree, TVM_SORTCHILDREN, FALSE, (LPARAM)tree.hAID);
378 static void AddTypeLib(void)
380 TVINSERTSTRUCT tvis;
381 HKEY hKey, hCurKey, hInfoKey, hPath;
382 WCHAR valName[MAX_LOAD_STRING];
383 WCHAR valParent[MAX_LOAD_STRING];
384 WCHAR buffer[MAX_LOAD_STRING];
385 WCHAR wszVer[MAX_LOAD_STRING];
386 WCHAR wszPath[MAX_LOAD_STRING];
387 const WCHAR wszFormat[] = { ' ','(','%','s',' ','%','s',')','\0' };
388 const WCHAR wszFormat2[] = { '%','s','\\','%','s','\0' };
389 LONG lenBuffer;
390 int i=-1, j;
392 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
393 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
394 tvis.hInsertAfter = (HTREEITEM)TVI_FIRST;
395 tvis.hParent = tree.hTL;
397 if(RegOpenKey(HKEY_CLASSES_ROOT, wszTypeLib, &hKey) != ERROR_SUCCESS) return;
399 while(TRUE)
401 i++;
403 if(RegEnumKey(hKey, i, valParent, sizeof(valParent)/sizeof(valParent[0])) != ERROR_SUCCESS) break;
405 if(RegOpenKey(hKey, valParent, &hCurKey) != ERROR_SUCCESS) continue;
407 j = -1;
408 while(TRUE)
410 j++;
412 if(RegEnumKey(hCurKey, j, valName, sizeof(valName)/sizeof(valName[0])) != ERROR_SUCCESS) break;
414 if(RegOpenKey(hCurKey, valName, &hInfoKey) != ERROR_SUCCESS) continue;
416 lenBuffer = sizeof(WCHAR[MAX_LOAD_STRING]);
418 if(RegQueryValue(hInfoKey, NULL, buffer, &lenBuffer) == ERROR_SUCCESS
419 && *buffer)
421 LoadString(globals.hMainInst, IDS_TL_VER, wszVer,
422 sizeof(wszVer)/sizeof(wszVer[0]));
424 wsprintfW(&buffer[lstrlenW(buffer)], wszFormat, wszVer, valName);
425 U(tvis).item.pszText = buffer;
427 lenBuffer = MAX_LOAD_STRING;
428 RegOpenKey(hInfoKey, wszGetPath, &hPath);
429 RegQueryValue(hPath, NULL, wszPath, &lenBuffer);
430 RegCloseKey(hPath);
432 else U(tvis).item.pszText = valName;
434 RegCloseKey(hInfoKey);
436 wsprintfW(wszVer, wszFormat2, valParent, valName);
437 U(tvis).item.lParam = CreateITEM_INFO(REGPATH, wszVer, valParent, wszPath);
439 SendMessage(globals.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
441 RegCloseKey(hCurKey);
444 RegCloseKey(hKey);
446 SendMessage(globals.hTree, TVM_SORTCHILDREN, FALSE, (LPARAM)tree.hTL);
449 static void AddInterfaces(void)
451 TVINSERTSTRUCT tvis;
452 HKEY hKey, hCurKey;
453 WCHAR valName[MAX_LOAD_STRING];
454 WCHAR buffer[MAX_LOAD_STRING];
455 LONG lenBuffer;
456 int i=-1;
458 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
459 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
460 tvis.hInsertAfter = (HTREEITEM)TVI_FIRST;
461 tvis.hParent = tree.hI;
463 if(RegOpenKey(HKEY_CLASSES_ROOT, wszInterface, &hKey) != ERROR_SUCCESS) return;
465 while(TRUE)
467 i++;
469 if(RegEnumKey(hKey, i, valName, sizeof(valName)/sizeof(valName[0])) != ERROR_SUCCESS) break;
471 if(RegOpenKey(hKey, valName, &hCurKey) != ERROR_SUCCESS) continue;
473 lenBuffer = sizeof(WCHAR[MAX_LOAD_STRING]);
475 if(RegQueryValue(hCurKey, NULL, buffer, &lenBuffer) == ERROR_SUCCESS && *buffer)
476 U(tvis).item.pszText = buffer;
477 else U(tvis).item.pszText = valName;
479 RegCloseKey(hCurKey);
481 U(tvis).item.lParam = CreateITEM_INFO(REGPATH|INTERFACE, valName, valName, NULL);
482 SendMessage(globals.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
485 RegCloseKey(hKey);
487 SendMessage(globals.hTree, TVM_SORTCHILDREN, FALSE, (LPARAM)tree.hI);
490 static void AddComponentCategories(void)
492 TVINSERTSTRUCT tvis;
493 HKEY hKey, hCurKey;
494 WCHAR valName[MAX_LOAD_STRING];
495 WCHAR buffer[MAX_LOAD_STRING];
496 LONG lenBuffer;
497 DWORD lenBufferHlp;
498 int i=-1;
500 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM|TVIF_CHILDREN;
501 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
502 tvis.hInsertAfter = (HTREEITEM)TVI_FIRST;
503 if(tree.hGBCC) tvis.hParent = tree.hGBCC;
504 else tvis.hParent = TVI_ROOT;
505 U(tvis).item.cChildren = 1;
507 if(RegOpenKey(HKEY_CLASSES_ROOT, wszComponentCategories, &hKey) != ERROR_SUCCESS)
508 return;
510 while(TRUE)
512 i++;
514 if(RegEnumKey(hKey, i, valName, sizeof(valName)/sizeof(valName[0])) != ERROR_SUCCESS) break;
516 if(RegOpenKey(hKey, valName, &hCurKey) != ERROR_SUCCESS) continue;
518 lenBuffer = sizeof(WCHAR[MAX_LOAD_STRING]);
519 lenBufferHlp = sizeof(WCHAR[MAX_LOAD_STRING]);
521 if(RegQueryValue(hCurKey, NULL, buffer, &lenBuffer) == ERROR_SUCCESS && *buffer)
522 U(tvis).item.pszText = buffer;
523 else if(RegEnumValue(hCurKey, 0, NULL, NULL, NULL, NULL,
524 (LPBYTE)buffer, &lenBufferHlp) == ERROR_SUCCESS && *buffer)
525 U(tvis).item.pszText = buffer;
526 else continue;
528 RegCloseKey(hCurKey);
530 U(tvis).item.lParam = CreateITEM_INFO(REGTOP, valName, valName, NULL);
531 SendMessage(globals.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
534 RegCloseKey(hKey);
536 SendMessage(globals.hTree, TVM_SORTCHILDREN, FALSE, (LPARAM)tree.hGBCC);
539 static void AddBaseEntries(void)
541 TVINSERTSTRUCT tvis;
542 WCHAR name[MAX_LOAD_STRING];
544 U(tvis).item.mask = TVIF_TEXT|TVIF_CHILDREN|TVIF_PARAM;
545 /* FIXME add TVIF_IMAGE */
546 U(tvis).item.pszText = name;
547 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
548 U(tvis).item.cChildren = 1;
549 tvis.hInsertAfter = (HTREEITEM)TVI_FIRST;
550 tvis.hParent = TVI_ROOT;
552 LoadString(globals.hMainInst, IDS_TREE_I, U(tvis).item.pszText,
553 MAX_LOAD_STRING);
554 U(tvis).item.lParam = CreateITEM_INFO(REGTOP, wszInterface, NULL, NULL);
555 tree.hI = TreeView_InsertItem(globals.hTree, &tvis);
557 LoadString(globals.hMainInst, IDS_TREE_TL, U(tvis).item.pszText,
558 MAX_LOAD_STRING);
559 U(tvis).item.lParam = CreateITEM_INFO(REGTOP, wszTypeLib, NULL, NULL);
560 tree.hTL = TreeView_InsertItem(globals.hTree, &tvis);
562 LoadString(globals.hMainInst, IDS_TREE_AID, U(tvis).item.pszText,
563 MAX_LOAD_STRING);
564 U(tvis).item.lParam = CreateITEM_INFO(REGTOP|REGPATH, wszAppID, NULL, NULL);
565 tree.hAID = TreeView_InsertItem(globals.hTree, &tvis);
567 LoadString(globals.hMainInst, IDS_TREE_OC, U(tvis).item.pszText,
568 MAX_LOAD_STRING);
569 U(tvis).item.lParam = (LPARAM)NULL;
570 tree.hOC = TreeView_InsertItem(globals.hTree, &tvis);
573 tvis.hParent = tree.hOC;
574 LoadString(globals.hMainInst, IDS_TREE_AO, U(tvis).item.pszText,
575 MAX_LOAD_STRING);
576 U(tvis).item.lParam = CreateITEM_INFO(REGTOP, wszCLSID, NULL, NULL);
577 tree.hAO = TreeView_InsertItem(globals.hTree, &tvis);
579 LoadString(globals.hMainInst, IDS_TREE_CLO, U(tvis).item.pszText,
580 MAX_LOAD_STRING);
581 tree.hCLO = TreeView_InsertItem(globals.hTree, &tvis);
583 LoadString(globals.hMainInst, IDS_TREE_O1O, U(tvis).item.pszText,
584 MAX_LOAD_STRING);
585 U(tvis).item.lParam = (LPARAM)NULL;
586 tree.hO1O = TreeView_InsertItem(globals.hTree, &tvis);
588 LoadString(globals.hMainInst, IDS_TREE_GBCC, U(tvis).item.pszText,
589 MAX_LOAD_STRING);
590 U(tvis).item.lParam = CreateITEM_INFO(REGTOP|REGPATH,
591 wszComponentCategories, NULL, NULL);
592 tree.hGBCC = TreeView_InsertItem(globals.hTree, &tvis);
594 SendMessage(globals.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)tree.hOC);
597 void EmptyTree(void)
599 HTREEITEM cur, del;
600 TVITEM tvi;
602 tvi.mask = TVIF_PARAM;
603 cur = TreeView_GetChild(globals.hTree, TVI_ROOT);
605 while(TRUE)
607 del = cur;
608 cur = TreeView_GetChild(globals.hTree, del);
610 if(!cur) cur = TreeView_GetNextSibling(globals.hTree, del);
611 if(!cur)
613 cur = TreeView_GetPrevSibling(globals.hTree, del);
614 if(!cur) cur = TreeView_GetParent(globals.hTree, del);
616 tvi.hItem = del;
617 SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
619 if(tvi.lParam)
621 if(((ITEM_INFO *)tvi.lParam)->loaded) ReleaseInst(del);
622 HeapFree(GetProcessHeap(), 0, (ITEM_INFO *)tvi.lParam);
625 SendMessage(globals.hTree, TVM_DELETEITEM, 0, (LPARAM)del);
627 if(!cur) break;
632 void AddTreeEx(void)
634 AddBaseEntries();
635 AddComponentCategories();
636 AddCOMandAll();
637 AddApplicationID();
638 AddTypeLib();
639 AddInterfaces();
642 void AddTree(void)
644 memset(&tree, 0, sizeof(TREE));
645 AddComponentCategories();
646 AddCOMandAll();
649 LRESULT CALLBACK TreeProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
651 switch(uMsg)
653 case WM_CREATE:
654 globals.hTree = CreateWindow(WC_TREEVIEW, NULL,
655 WS_CHILD|WS_VISIBLE|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
656 0, 0, 0, 0, hWnd, (HMENU)TREE_WINDOW, globals.hMainInst, NULL);
657 AddTreeEx();
658 break;
659 case WM_NOTIFY:
660 if((int)wParam != TREE_WINDOW) break;
661 switch(((LPNMHDR)lParam)->code)
663 case TVN_ITEMEXPANDING:
664 CreateInst(((NMTREEVIEW *)lParam)->itemNew.hItem, NULL);
665 break;
666 case TVN_SELCHANGED:
667 RefreshMenu(((NMTREEVIEW *)lParam)->itemNew.hItem);
668 RefreshDetails(((NMTREEVIEW *)lParam)->itemNew.hItem);
669 break;
671 break;
672 case WM_SIZE:
673 MoveWindow(globals.hTree, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
674 break;
675 default:
676 return DefWindowProc(hWnd, uMsg, wParam, lParam);
678 return 0;
681 HWND CreateTreeWindow(HINSTANCE hInst)
683 WNDCLASS wct;
684 const WCHAR wszTreeClass[] = { 'T','R','E','E','\0' };
686 memset(&wct, 0, sizeof(WNDCLASS));
687 wct.lpfnWndProc = TreeProc;
688 wct.lpszClassName = wszTreeClass;
690 if(!RegisterClass(&wct)) return NULL;
692 return CreateWindowEx(WS_EX_CLIENTEDGE, wszTreeClass, NULL, WS_CHILD|WS_VISIBLE,
693 0, 0, 0, 0, globals.hPaneWnd, NULL, hInst, NULL);