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