oleview.c 21 KB

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