oleview.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /*
  2. * OleView (oleview.c)
  3. *
  4. * Copyright 2006 Piotr Caban
  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. #include "main.h"
  21. #include "commdlg.h"
  22. #include "shellapi.h"
  23. GLOBALS globals;
  24. static const WCHAR wszRegEdit[] = { '\\','r','e','g','e','d','i','t','.','e','x','e','\0' };
  25. static const WCHAR wszFormat[] = { '<','o','b','j','e','c','t','\n',' ',' ',' ',
  26. 'c','l','a','s','s','i','d','=','\"','c','l','s','i','d',':','%','s','\"','\n',
  27. '>','\n','<','/','o','b','j','e','c','t','>','\0' };
  28. static INT_PTR CALLBACK SysConfProc(HWND hDlgWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  29. {
  30. HKEY hKey;
  31. WCHAR buffer[MAX_LOAD_STRING];
  32. DWORD bufSize;
  33. WCHAR wszReg[] = { 'S','o','f','t','w','a','r','e','\\',
  34. 'M','i','c','r','o','s','o','f','t','\\','O','L','E','\\','\0' };
  35. WCHAR wszEnableDCOM[] = { 'E','n','a','b','l','e','D','C','O','M','\0' };
  36. WCHAR wszEnableRemote[] = { 'E','n','a','b','l','e',
  37. 'R','e','m','o','t','e','C','o','n','n','e','c','t','\0' };
  38. WCHAR wszYes[] = { 'Y', '\0' };
  39. WCHAR wszNo[] = { 'N', '\0' };
  40. switch(uMsg)
  41. {
  42. case WM_INITDIALOG:
  43. if(RegOpenKeyW(HKEY_LOCAL_MACHINE, wszReg, &hKey) != ERROR_SUCCESS)
  44. RegCreateKeyW(HKEY_LOCAL_MACHINE, wszReg, &hKey);
  45. bufSize = sizeof(buffer);
  46. if(RegGetValueW(hKey, NULL, wszEnableDCOM, RRF_RT_REG_SZ,
  47. NULL, buffer, &bufSize) != ERROR_SUCCESS)
  48. {
  49. bufSize = sizeof(wszYes);
  50. RegSetValueExW(hKey, wszEnableDCOM, 0, REG_SZ, (BYTE*)wszYes, bufSize);
  51. }
  52. CheckDlgButton(hDlgWnd, IDC_ENABLEDCOM,
  53. buffer[0]=='Y' ? BST_CHECKED : BST_UNCHECKED);
  54. bufSize = sizeof(buffer);
  55. if(RegGetValueW(hKey, NULL, wszEnableRemote, RRF_RT_REG_SZ,
  56. NULL, buffer, &bufSize) != ERROR_SUCCESS)
  57. {
  58. bufSize = sizeof(wszYes);
  59. RegSetValueExW(hKey, wszEnableRemote, 0, REG_SZ, (BYTE*)wszYes, bufSize);
  60. }
  61. CheckDlgButton(hDlgWnd, IDC_ENABLEREMOTE,
  62. buffer[0]=='Y' ? BST_CHECKED : BST_UNCHECKED);
  63. RegCloseKey(hKey);
  64. return TRUE;
  65. case WM_COMMAND:
  66. switch(LOWORD(wParam)) {
  67. case IDOK:
  68. bufSize = sizeof(wszYes);
  69. RegOpenKeyW(HKEY_LOCAL_MACHINE, wszReg, &hKey);
  70. RegSetValueExW(hKey, wszEnableDCOM, 0, REG_SZ,
  71. IsDlgButtonChecked(hDlgWnd, IDC_ENABLEDCOM) == BST_CHECKED ?
  72. (BYTE*)wszYes : (BYTE*)wszNo, bufSize);
  73. RegSetValueExW(hKey, wszEnableRemote, 0, REG_SZ,
  74. IsDlgButtonChecked(hDlgWnd, IDC_ENABLEREMOTE) == BST_CHECKED ?
  75. (BYTE*)wszYes : (BYTE*)wszNo, bufSize);
  76. RegCloseKey(hKey);
  77. EndDialog(hDlgWnd, IDOK);
  78. return TRUE;
  79. case IDCANCEL:
  80. EndDialog(hDlgWnd, IDCANCEL);
  81. return TRUE;
  82. }
  83. }
  84. return FALSE;
  85. }
  86. static INT_PTR CALLBACK CreateInstOnProc(HWND hDlgWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  87. {
  88. HWND hEdit;
  89. switch(uMsg)
  90. {
  91. case WM_COMMAND:
  92. switch(LOWORD(wParam)) {
  93. case IDOK:
  94. memset(globals.wszMachineName, 0, sizeof(WCHAR[MAX_LOAD_STRING]));
  95. hEdit = GetDlgItem(hDlgWnd, IDC_MACHINE);
  96. if (GetWindowTextLengthW(hEdit)>0)
  97. GetWindowTextW(hEdit, globals.wszMachineName, MAX_LOAD_STRING);
  98. EndDialog(hDlgWnd, IDOK);
  99. return TRUE;
  100. case IDCANCEL:
  101. EndDialog(hDlgWnd, IDCANCEL);
  102. return TRUE;
  103. }
  104. }
  105. return FALSE;
  106. }
  107. static void InitOpenFileName(HWND hWnd, OPENFILENAMEW *pofn, WCHAR *wszFilter,
  108. WCHAR *wszTitle, WCHAR *wszFileName)
  109. {
  110. memset(pofn, 0, sizeof(OPENFILENAMEW));
  111. pofn->lStructSize = sizeof(OPENFILENAMEW);
  112. pofn->hwndOwner = hWnd;
  113. pofn->hInstance = globals.hMainInst;
  114. pofn->lpstrTitle = wszTitle;
  115. pofn->lpstrFilter = wszFilter;
  116. pofn->nFilterIndex = 0;
  117. pofn->lpstrFile = wszFileName;
  118. pofn->nMaxFile = MAX_LOAD_STRING;
  119. pofn->Flags = OFN_HIDEREADONLY | OFN_ENABLESIZING;
  120. }
  121. static void CopyClsid(HTREEITEM item)
  122. {
  123. TVITEMW tvi;
  124. memset(&tvi, 0, sizeof(TVITEMW));
  125. tvi.hItem = item;
  126. tvi.cchTextMax = MAX_LOAD_STRING;
  127. SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
  128. if(OpenClipboard(globals.hMainWnd) && EmptyClipboard() && tvi.lParam)
  129. {
  130. HANDLE hClipData = GlobalAlloc(GHND, sizeof(WCHAR[MAX_LOAD_STRING]));
  131. LPVOID pLoc = GlobalLock(hClipData);
  132. lstrcpyW(pLoc, ((ITEM_INFO *)tvi.lParam)->clsid);
  133. GlobalUnlock(hClipData);
  134. SetClipboardData(CF_UNICODETEXT, hClipData);
  135. CloseClipboard();
  136. }
  137. }
  138. static void CopyHTMLTag(HTREEITEM item)
  139. {
  140. TVITEMW tvi;
  141. memset(&tvi, 0, sizeof(TVITEMW));
  142. tvi.hItem = item;
  143. tvi.cchTextMax = MAX_LOAD_STRING;
  144. SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
  145. if(OpenClipboard(globals.hMainWnd) && EmptyClipboard() && tvi.lParam)
  146. {
  147. HANDLE hClipData = GlobalAlloc(GHND, sizeof(WCHAR[MAX_LOAD_STRING]));
  148. LPVOID pLoc = GlobalLock(hClipData);
  149. int clsidLen = lstrlenW(((ITEM_INFO *)tvi.lParam)->clsid)-1;
  150. ((ITEM_INFO *)tvi.lParam)->clsid[clsidLen] = '\0';
  151. wsprintfW(pLoc, wszFormat, ((ITEM_INFO *)tvi.lParam)->clsid+1);
  152. ((ITEM_INFO *)tvi.lParam)->clsid[clsidLen] = '}';
  153. GlobalUnlock(hClipData);
  154. SetClipboardData(CF_UNICODETEXT, hClipData);
  155. CloseClipboard();
  156. }
  157. }
  158. static void ResizeChild(void)
  159. {
  160. RECT client, stat, tool;
  161. MoveWindow(globals.hStatusBar, 0, 0, 0, 0, TRUE);
  162. MoveWindow(globals.hToolBar, 0, 0, 0, 0, TRUE);
  163. if(IsWindowVisible(globals.hStatusBar))
  164. GetClientRect(globals.hStatusBar, &stat);
  165. else stat.bottom = 0;
  166. if(IsWindowVisible(globals.hToolBar))
  167. {
  168. GetClientRect(globals.hToolBar, &tool);
  169. tool.bottom += 2;
  170. }
  171. else tool.bottom = 0;
  172. GetClientRect(globals.hMainWnd, &client);
  173. MoveWindow(globals.hPaneWnd, 0, tool.bottom,
  174. client.right, client.bottom-tool.bottom-stat.bottom, TRUE);
  175. }
  176. void RefreshMenu(HTREEITEM item)
  177. {
  178. TVITEMW tvi;
  179. HTREEITEM parent;
  180. HMENU hMenu = GetMenu(globals.hMainWnd);
  181. memset(&tvi, 0, sizeof(TVITEMW));
  182. tvi.hItem = item;
  183. SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
  184. parent = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM,
  185. TVGN_PARENT, (LPARAM)item);
  186. SendMessageW(globals.hToolBar, TB_ENABLEBUTTON, IDM_CREATEINST, FALSE);
  187. SendMessageW(globals.hToolBar, TB_ENABLEBUTTON, IDM_RELEASEINST, FALSE);
  188. SendMessageW(globals.hToolBar, TB_ENABLEBUTTON, IDM_VIEW, FALSE);
  189. if(tvi.lParam && ((ITEM_INFO *)tvi.lParam)->cFlag&SHOWALL)
  190. {
  191. EnableMenuItem(hMenu, IDM_COPYCLSID, MF_ENABLED);
  192. EnableMenuItem(hMenu, IDM_HTMLTAG, MF_ENABLED);
  193. EnableMenuItem(hMenu, IDM_VIEW, MF_GRAYED);
  194. if(!((ITEM_INFO *)tvi.lParam)->loaded)
  195. {
  196. EnableMenuItem(hMenu, IDM_CREATEINST, MF_ENABLED);
  197. EnableMenuItem(hMenu, IDM_CREATEINSTON, MF_ENABLED);
  198. EnableMenuItem(hMenu, IDM_RELEASEINST, MF_GRAYED);
  199. SendMessageW(globals.hToolBar, TB_ENABLEBUTTON, IDM_CREATEINST, TRUE);
  200. }
  201. else
  202. {
  203. EnableMenuItem(hMenu, IDM_CREATEINST, MF_GRAYED);
  204. EnableMenuItem(hMenu, IDM_CREATEINSTON, MF_GRAYED);
  205. EnableMenuItem(hMenu, IDM_RELEASEINST, MF_ENABLED);
  206. SendMessageW(globals.hToolBar, TB_ENABLEBUTTON, IDM_RELEASEINST, TRUE);
  207. }
  208. }
  209. else if(tvi.lParam &&
  210. (((ITEM_INFO *)tvi.lParam)->cFlag&INTERFACE || parent==tree.hTL))
  211. {
  212. EnableMenuItem(hMenu, IDM_TYPEINFO, MF_GRAYED);
  213. EnableMenuItem(hMenu, IDM_CREATEINST, MF_GRAYED);
  214. EnableMenuItem(hMenu, IDM_CREATEINSTON, MF_GRAYED);
  215. EnableMenuItem(hMenu, IDM_RELEASEINST, MF_GRAYED);
  216. EnableMenuItem(hMenu, IDM_COPYCLSID, MF_ENABLED);
  217. EnableMenuItem(hMenu, IDM_HTMLTAG, MF_GRAYED);
  218. EnableMenuItem(hMenu, IDM_VIEW, MF_ENABLED);
  219. SendMessageW(globals.hToolBar, TB_ENABLEBUTTON, IDM_VIEW, TRUE);
  220. }
  221. else
  222. {
  223. EnableMenuItem(hMenu, IDM_TYPEINFO, MF_GRAYED);
  224. EnableMenuItem(hMenu, IDM_CREATEINST, MF_GRAYED);
  225. EnableMenuItem(hMenu, IDM_CREATEINSTON, MF_GRAYED);
  226. EnableMenuItem(hMenu, IDM_RELEASEINST, MF_GRAYED);
  227. EnableMenuItem(hMenu, IDM_COPYCLSID, MF_GRAYED);
  228. EnableMenuItem(hMenu, IDM_HTMLTAG, MF_GRAYED);
  229. EnableMenuItem(hMenu, IDM_VIEW, MF_GRAYED);
  230. }
  231. if(parent==tree.hAID || parent==tree.hGBCC)
  232. EnableMenuItem(hMenu, IDM_COPYCLSID, MF_ENABLED);
  233. }
  234. static int MenuCommand(WPARAM wParam, HWND hWnd)
  235. {
  236. BOOL vis;
  237. HTREEITEM hSelect;
  238. WCHAR wszAbout[MAX_LOAD_STRING];
  239. switch(wParam)
  240. {
  241. case IDM_ABOUT:
  242. LoadStringW(globals.hMainInst, IDS_ABOUT, wszAbout, ARRAY_SIZE(wszAbout));
  243. ShellAboutW(hWnd, wszAbout, NULL, NULL);
  244. break;
  245. case IDM_COPYCLSID:
  246. hSelect = (HTREEITEM)SendMessageW(globals.hTree,
  247. TVM_GETNEXTITEM, TVGN_CARET, 0);
  248. CopyClsid(hSelect);
  249. break;
  250. case IDM_HTMLTAG:
  251. hSelect = (HTREEITEM)SendMessageW(globals.hTree,
  252. TVM_GETNEXTITEM, TVGN_CARET, 0);
  253. CopyHTMLTag(hSelect);
  254. break;
  255. case IDM_CREATEINST:
  256. hSelect = (HTREEITEM)SendMessageW(globals.hTree,
  257. TVM_GETNEXTITEM, TVGN_CARET, 0);
  258. CreateInst(hSelect, NULL);
  259. SendMessageW(globals.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hSelect);
  260. break;
  261. case IDM_CREATEINSTON:
  262. if(DialogBoxW(0, MAKEINTRESOURCEW(DLG_CREATEINSTON),
  263. hWnd, CreateInstOnProc) == IDCANCEL) break;
  264. hSelect = (HTREEITEM)SendMessageW(globals.hTree,
  265. TVM_GETNEXTITEM, TVGN_CARET, 0);
  266. CreateInst(hSelect, globals.wszMachineName);
  267. SendMessageW(globals.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hSelect);
  268. break;
  269. case IDM_RELEASEINST:
  270. hSelect = (HTREEITEM)SendMessageW(globals.hTree,
  271. TVM_GETNEXTITEM, TVGN_CARET, 0);
  272. ReleaseInst(hSelect);
  273. RefreshMenu(hSelect);
  274. RefreshDetails(hSelect);
  275. break;
  276. case IDM_EXPERT:
  277. globals.bExpert = !globals.bExpert;
  278. CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
  279. globals.bExpert ? MF_CHECKED : MF_UNCHECKED);
  280. EmptyTree();
  281. if(globals.bExpert) AddTreeEx();
  282. else AddTree();
  283. hSelect = (HTREEITEM)SendMessageW(globals.hTree,
  284. TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)TVI_ROOT);
  285. SendMessageW(globals.hTree, TVM_SELECTITEM, 0, (LPARAM)hSelect);
  286. RefreshMenu(hSelect);
  287. break;
  288. case IDM_FLAG_INSERV:
  289. vis = globals.dwClsCtx&CLSCTX_INPROC_SERVER;
  290. globals.dwClsCtx = globals.dwClsCtx&(~CLSCTX_INPROC_SERVER);
  291. globals.dwClsCtx = globals.dwClsCtx|((~vis)&CLSCTX_INPROC_SERVER);
  292. if(!globals.dwClsCtx) globals.dwClsCtx = vis;
  293. else CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
  294. vis ? MF_UNCHECKED : MF_CHECKED);
  295. break;
  296. case IDM_FLAG_INHANDL:
  297. vis = globals.dwClsCtx&CLSCTX_INPROC_HANDLER;
  298. globals.dwClsCtx = globals.dwClsCtx&(~CLSCTX_INPROC_HANDLER);
  299. globals.dwClsCtx = globals.dwClsCtx|((~vis)&CLSCTX_INPROC_HANDLER);
  300. if(!globals.dwClsCtx) globals.dwClsCtx = vis;
  301. else CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
  302. vis ? MF_UNCHECKED : MF_CHECKED);
  303. break;
  304. case IDM_FLAG_LOCSERV:
  305. vis = globals.dwClsCtx&CLSCTX_LOCAL_SERVER;
  306. globals.dwClsCtx = globals.dwClsCtx&(~CLSCTX_LOCAL_SERVER);
  307. globals.dwClsCtx = globals.dwClsCtx|((~vis)&CLSCTX_LOCAL_SERVER);
  308. if(!globals.dwClsCtx) globals.dwClsCtx = vis;
  309. else CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
  310. vis ? MF_UNCHECKED : MF_CHECKED);
  311. break;
  312. case IDM_FLAG_REMSERV:
  313. vis = globals.dwClsCtx&CLSCTX_REMOTE_SERVER;
  314. globals.dwClsCtx = globals.dwClsCtx&(~CLSCTX_REMOTE_SERVER);
  315. globals.dwClsCtx = globals.dwClsCtx|((~vis)&CLSCTX_REMOTE_SERVER);
  316. if(!globals.dwClsCtx) globals.dwClsCtx = vis;
  317. else CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
  318. vis ? MF_UNCHECKED : MF_CHECKED);
  319. break;
  320. case IDM_REFRESH:
  321. EmptyTree();
  322. if(globals.bExpert) AddTreeEx();
  323. else AddTree();
  324. hSelect = (HTREEITEM)SendMessageW(globals.hTree,
  325. TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)TVI_ROOT);
  326. SendMessageW(globals.hTree, TVM_SELECTITEM, 0, (LPARAM)hSelect);
  327. RefreshMenu(hSelect);
  328. break;
  329. case IDM_REGEDIT:
  330. {
  331. STARTUPINFOW si;
  332. PROCESS_INFORMATION pi;
  333. WCHAR app[MAX_PATH];
  334. GetWindowsDirectoryW(app, MAX_PATH - ARRAY_SIZE(wszRegEdit));
  335. lstrcatW( app, wszRegEdit );
  336. memset(&si, 0, sizeof(si));
  337. si.cb = sizeof(si);
  338. if (CreateProcessW(app, app, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
  339. {
  340. CloseHandle(pi.hProcess);
  341. CloseHandle(pi.hThread);
  342. }
  343. break;
  344. }
  345. case IDM_STATUSBAR:
  346. vis = IsWindowVisible(globals.hStatusBar);
  347. ShowWindow(globals.hStatusBar, vis ? SW_HIDE : SW_SHOW);
  348. CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
  349. vis ? MF_UNCHECKED : MF_CHECKED);
  350. ResizeChild();
  351. break;
  352. case IDM_SYSCONF:
  353. DialogBoxW(0, MAKEINTRESOURCEW(DLG_SYSCONF), hWnd, SysConfProc);
  354. break;
  355. case IDM_TOOLBAR:
  356. vis = IsWindowVisible(globals.hToolBar);
  357. ShowWindow(globals.hToolBar, vis ? SW_HIDE : SW_SHOW);
  358. CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
  359. vis ? MF_UNCHECKED : MF_CHECKED);
  360. ResizeChild();
  361. break;
  362. case IDM_TYPELIB:
  363. {
  364. static const WCHAR filterW[] = {'%','s','%','c','*','.','t','l','b',';','*','.','o','l','b',';','*','.','d','l','l',';','*','.','o','c','x',';','*','.','e','x','e','%','c','%','s','%','c','*','.','*','%','c',0};
  365. OPENFILENAMEW ofn;
  366. static WCHAR wszTitle[MAX_LOAD_STRING];
  367. static WCHAR wszName[MAX_LOAD_STRING];
  368. WCHAR filter_typelib[MAX_LOAD_STRING], filter_all[MAX_LOAD_STRING], filter[MAX_PATH];
  369. LoadStringW(globals.hMainInst, IDS_OPEN, wszTitle, ARRAY_SIZE(wszTitle));
  370. LoadStringW(globals.hMainInst, IDS_OPEN_FILTER_TYPELIB, filter_typelib, ARRAY_SIZE(filter_typelib));
  371. LoadStringW(globals.hMainInst, IDS_OPEN_FILTER_ALL, filter_all, ARRAY_SIZE(filter_all));
  372. wsprintfW( filter, filterW, filter_typelib, 0, 0, filter_all, 0, 0 );
  373. InitOpenFileName(hWnd, &ofn, filter, wszTitle, wszName);
  374. if(GetOpenFileNameW(&ofn)) CreateTypeLibWindow(globals.hMainInst, wszName);
  375. break;
  376. }
  377. case IDM_VIEW:
  378. hSelect = (HTREEITEM)SendMessageW(globals.hTree,
  379. TVM_GETNEXTITEM, TVGN_CARET, 0);
  380. if(IsInterface(hSelect)) InterfaceViewer(hSelect);
  381. else CreateTypeLibWindow(globals.hMainInst, NULL);
  382. break;
  383. case IDM_EXIT:
  384. DestroyWindow(hWnd);
  385. break;
  386. }
  387. return 0;
  388. }
  389. static void UpdateStatusBar(int itemID)
  390. {
  391. WCHAR info[MAX_LOAD_STRING];
  392. if(!LoadStringW(globals.hMainInst, itemID, info, ARRAY_SIZE(info)))
  393. LoadStringW(globals.hMainInst, IDS_READY, info, ARRAY_SIZE(info));
  394. SendMessageW(globals.hStatusBar, SB_SETTEXTW, 0, (LPARAM)info);
  395. }
  396. static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg,
  397. WPARAM wParam, LPARAM lParam)
  398. {
  399. switch(uMsg)
  400. {
  401. case WM_CREATE:
  402. OleInitialize(NULL);
  403. PaneRegisterClassW();
  404. TypeLibRegisterClassW();
  405. if(!CreatePanedWindow(hWnd, &globals.hPaneWnd, globals.hMainInst))
  406. PostQuitMessage(0);
  407. SetLeft(globals.hPaneWnd, CreateTreeWindow(globals.hMainInst));
  408. SetRight(globals.hPaneWnd, CreateDetailsWindow(globals.hMainInst));
  409. SetFocus(globals.hTree);
  410. break;
  411. case WM_COMMAND:
  412. MenuCommand(LOWORD(wParam), hWnd);
  413. break;
  414. case WM_DESTROY:
  415. EmptyTree();
  416. OleUninitialize();
  417. PostQuitMessage(0);
  418. break;
  419. case WM_MENUSELECT:
  420. UpdateStatusBar(LOWORD(wParam));
  421. break;
  422. case WM_SETFOCUS:
  423. SetFocus(globals.hTree);
  424. break;
  425. case WM_SIZE:
  426. if(wParam == SIZE_MINIMIZED) break;
  427. ResizeChild();
  428. break;
  429. default:
  430. return DefWindowProcW(hWnd, uMsg, wParam, lParam);
  431. }
  432. return 0;
  433. }
  434. static BOOL InitApplication(HINSTANCE hInst)
  435. {
  436. WNDCLASSW wc;
  437. WCHAR wszAppName[MAX_LOAD_STRING];
  438. LoadStringW(hInst, IDS_APPNAME, wszAppName, ARRAY_SIZE(wszAppName));
  439. memset(&wc, 0, sizeof(WNDCLASSW));
  440. wc.lpfnWndProc = WndProc;
  441. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  442. wc.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
  443. wc.lpszMenuName = MAKEINTRESOURCEW(IDM_MENU);
  444. wc.lpszClassName = wszAppName;
  445. if(!RegisterClassW(&wc))
  446. return FALSE;
  447. return TRUE;
  448. }
  449. static BOOL InitInstance(HINSTANCE hInst, int nCmdShow)
  450. {
  451. HWND hWnd;
  452. WCHAR wszAppName[MAX_LOAD_STRING];
  453. WCHAR wszTitle[MAX_LOAD_STRING];
  454. TBBUTTON tB[] = {
  455. {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
  456. {0, IDM_BIND, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
  457. {1, IDM_TYPELIB, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
  458. {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
  459. {2, IDM_REGEDIT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
  460. {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
  461. {3, IDM_CREATEINST, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
  462. {4, IDM_RELEASEINST, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
  463. {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
  464. {5, IDM_VIEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0}
  465. };
  466. LoadStringW(hInst, IDS_APPNAME, wszAppName, ARRAY_SIZE(wszAppName));
  467. LoadStringW(hInst, IDS_APPTITLE, wszTitle, ARRAY_SIZE(wszTitle));
  468. hWnd = CreateWindowW(wszAppName, wszTitle, WS_OVERLAPPEDWINDOW,
  469. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL);
  470. if(!hWnd) return FALSE;
  471. globals.hStatusBar = CreateStatusWindowW(WS_VISIBLE|WS_CHILD,
  472. wszTitle, hWnd, 0);
  473. globals.hToolBar = CreateToolbarEx(hWnd, WS_CHILD|WS_VISIBLE, 0, 1, hInst,
  474. IDB_TOOLBAR, tB, 10, 16, 16, 16, 16, sizeof(TBBUTTON));
  475. SendMessageW(globals.hToolBar, TB_ENABLEBUTTON, IDM_CREATEINST, FALSE);
  476. SendMessageW(globals.hToolBar, TB_ENABLEBUTTON, IDM_RELEASEINST, FALSE);
  477. SendMessageW(globals.hToolBar, TB_ENABLEBUTTON, IDM_VIEW, FALSE);
  478. globals.hMainWnd = hWnd;
  479. globals.hMainInst = hInst;
  480. globals.bExpert = TRUE;
  481. globals.dwClsCtx = CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER;
  482. ShowWindow(hWnd, nCmdShow);
  483. UpdateWindow(hWnd);
  484. return TRUE;
  485. }
  486. int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
  487. {
  488. MSG msg;
  489. HANDLE hAccelTable;
  490. if(!InitApplication(hInst))
  491. return FALSE;
  492. if(!InitInstance(hInst, nCmdShow))
  493. return FALSE;
  494. hAccelTable = LoadAcceleratorsW(hInst, MAKEINTRESOURCEW(IDA_OLEVIEW));
  495. while(GetMessageW(&msg, NULL, 0, 0))
  496. {
  497. if(TranslateAcceleratorW(globals.hMainWnd, hAccelTable, &msg)) continue;
  498. TranslateMessage(&msg);
  499. DispatchMessageW(&msg);
  500. }
  501. return msg.wParam;
  502. }