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