From ecd514d5d6b9b0457f64cbebbd8c93a6fbfa2485 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Sun, 2 Jul 2006 13:04:26 +0200 Subject: [PATCH] oleview: Added open TypeLib file functionality. --- programs/oleview/En.rc | 1 + programs/oleview/Makefile.in | 2 +- programs/oleview/main.h | 3 ++- programs/oleview/oleview.c | 36 +++++++++++++++++++++++++++++++++++- programs/oleview/resource.h | 2 ++ programs/oleview/typelib.c | 23 +++++++++++++++-------- 6 files changed, 56 insertions(+), 11 deletions(-) diff --git a/programs/oleview/En.rc b/programs/oleview/En.rc index f5b3a28c239..dfb09aada67 100644 --- a/programs/oleview/En.rc +++ b/programs/oleview/En.rc @@ -95,6 +95,7 @@ STRINGTABLE IDS_ABOUT "OleView - OLE/COM Object Viewer" IDS_ABOUTVER "version 1.0" IDS_TYPELIBTITLE "ITypeLib viewer" + IDS_OPEN "Open" IDM_BIND, "Bind to file via a File Moniker" IDM_TYPELIB, "Open a TypeLib file and view the contents" diff --git a/programs/oleview/Makefile.in b/programs/oleview/Makefile.in index 2df5004ab8d..00fc481ce55 100644 --- a/programs/oleview/Makefile.in +++ b/programs/oleview/Makefile.in @@ -4,7 +4,7 @@ SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = oleview.exe APPMODE = -mwindows -municode -IMPORTS = comctl32 shell32 oleaut32 ole32 user32 advapi32 kernel32 +IMPORTS = comdlg32 comctl32 shell32 oleaut32 ole32 user32 advapi32 kernel32 EXTRALIBS = -luuid EXTRADEFS = -DUNICODE diff --git a/programs/oleview/main.h b/programs/oleview/main.h index ad200fb27d1..689e01f0af5 100644 --- a/programs/oleview/main.h +++ b/programs/oleview/main.h @@ -108,6 +108,7 @@ typedef struct HWND hTree; HWND hEdit; HWND hStatusBar; + WCHAR wszFileName[MAX_LOAD_STRING]; }TYPELIB; extern GLOBALS globals; @@ -138,7 +139,7 @@ void CreateInst(HTREEITEM item, WCHAR *wszMachineName); void ReleaseInst(HTREEITEM item); /* typelib.c */ -BOOL CreateTypeLibWindow(HINSTANCE hInst); +BOOL CreateTypeLibWindow(HINSTANCE hInst, WCHAR *wszFileName); BOOL TypeLibRegisterClass(void); /* interface.c */ diff --git a/programs/oleview/oleview.c b/programs/oleview/oleview.c index 73980b28829..88ce7250a21 100644 --- a/programs/oleview/oleview.c +++ b/programs/oleview/oleview.c @@ -25,6 +25,13 @@ static WCHAR wszRegEdit[] = { 'r','e','g','e','d','i','t','.','e','x','e','\0' } static WCHAR wszFormat[] = { '<','o','b','j','e','c','t','\n',' ',' ',' ', 'c','l','a','s','s','i','d','=','\"','c','l','s','i','d',':','%','s','\"','\n', '>','\n','<','/','o','b','j','e','c','t','>','\0' }; +WCHAR wszFilter[] = { 'T','y','p','e','L','i','b',' ','F','i','l','e','s',' ', + '(','*','t','l','b',';','*','o','l','b',';','*','.','d','l','l',';', + '*','.','o','c','x',';','*','.','e','x','e',')','\0', + '*','.','t','l','b',';','*','.','o','l','b',';','*','.','d','l','l',';', + '*','.','o','c','x','*','.','e','x','e','\0', + 'A','l','l',' ','F','i','l','e','s',' ','(','*','.','*',')','\0', + '*','.','*','\0','\0' }; INT_PTR CALLBACK SysConfProc(HWND hDlgWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -124,6 +131,22 @@ INT_PTR CALLBACK CreateInstOnProc(HWND hDlgWnd, UINT uMsg, WPARAM wParam, LPARAM return FALSE; } +void InitOpenFileName(HWND hWnd, OPENFILENAME *pofn, WCHAR *wszFilter, + WCHAR *wszTitle, WCHAR *wszFileName) +{ + memset(pofn, 0, sizeof(OPENFILENAME)); + pofn->lStructSize = sizeof(OPENFILENAME); + pofn->hwndOwner = hWnd; + pofn->hInstance = globals.hMainInst; + + pofn->lpstrTitle = wszTitle; + pofn->lpstrFilter = wszFilter; + pofn->nFilterIndex = 0; + pofn->lpstrFile = wszFileName; + pofn->nMaxFile = MAX_LOAD_STRING; + pofn->Flags = OFN_HIDEREADONLY; +} + void CopyClsid(HTREEITEM item) { TVITEM tvi; @@ -380,10 +403,21 @@ int MenuCommand(WPARAM wParam, HWND hWnd) vis ? MF_UNCHECKED : MF_CHECKED); ResizeChild(); break; + case IDM_TYPELIB: + { + OPENFILENAME ofn; + static WCHAR wszTitle[MAX_LOAD_STRING]; + static WCHAR wszName[MAX_LOAD_STRING]; + + LoadString(globals.hMainInst, IDS_OPEN, wszTitle, sizeof(wszTitle)); + InitOpenFileName(hWnd, &ofn, wszFilter, wszTitle, wszName); + if(GetOpenFileName(&ofn)) CreateTypeLibWindow(globals.hMainInst, wszName); + break; + } case IDM_VIEW: hSelect = TreeView_GetSelection(globals.hTree); if(IsInterface(hSelect)) InterfaceViewer(hSelect); - else CreateTypeLibWindow(globals.hMainInst); + else CreateTypeLibWindow(globals.hMainInst, NULL); break; case IDM_EXIT: DestroyWindow(hWnd); diff --git a/programs/oleview/resource.h b/programs/oleview/resource.h index 5d7818b403c..73cde3de19b 100644 --- a/programs/oleview/resource.h +++ b/programs/oleview/resource.h @@ -29,6 +29,8 @@ #define IDS_ABOUT 20 #define IDS_ABOUTVER 21 +#define IDS_OPEN 30 + #define IDM_BIND 100 #define IDM_TYPELIB 101 #define IDM_SYSCONF 102 diff --git a/programs/oleview/typelib.c b/programs/oleview/typelib.c index 09275f44c9c..3fb8689c559 100644 --- a/programs/oleview/typelib.c +++ b/programs/oleview/typelib.c @@ -30,7 +30,6 @@ void AddToStrW(WCHAR *wszDest, const WCHAR *wszSource) int PopulateTree(void) { - TVITEM tvi; TVINSERTSTRUCT tvis; ITypeLib *pTypeLib; ITypeInfo *pTypeInfo, *pRefTypeInfo; @@ -64,9 +63,6 @@ int PopulateTree(void) const WCHAR wszVT_BSTR[] = { 'B','S','T','R',' ','\0' }; const WCHAR wszVT_CY[] = { 'C','U','R','R','E','N','C','Y',' ','\0' }; - memset(&tvi, 0, sizeof(TVITEM)); - tvi.hItem = TreeView_GetSelection(globals.hTree); - U(tvis).item.mask = TVIF_TEXT|TVIF_CHILDREN; U(tvis).item.cchTextMax = MAX_LOAD_STRING; U(tvis).item.pszText = wszText; @@ -74,15 +70,14 @@ int PopulateTree(void) tvis.hInsertAfter = (HTREEITEM)TVI_LAST; tvis.hParent = TVI_ROOT; - SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi); - if(FAILED((hRes = LoadTypeLib(((ITEM_INFO*)tvi.lParam)->path, &pTypeLib)))) + if(FAILED((hRes = LoadTypeLib(typelib.wszFileName, &pTypeLib)))) { WCHAR wszMessage[MAX_LOAD_STRING]; WCHAR wszError[MAX_LOAD_STRING]; LoadString(globals.hMainInst, IDS_ERROR_LOADTYPELIB, wszError, sizeof(WCHAR[MAX_LOAD_STRING])); - wsprintfW(wszMessage, wszError, ((ITEM_INFO*)tvi.lParam)->path, hRes); + wsprintfW(wszMessage, wszError, typelib.wszFileName, hRes); MessageBox(globals.hMainWnd, wszMessage, NULL, MB_OK|MB_ICONEXCLAMATION); return 1; } @@ -261,11 +256,23 @@ BOOL TypeLibRegisterClass(void) return TRUE; } -BOOL CreateTypeLibWindow(HINSTANCE hInst) +BOOL CreateTypeLibWindow(HINSTANCE hInst, WCHAR *wszFileName) { WCHAR wszTitle[MAX_LOAD_STRING]; LoadString(hInst, IDS_TYPELIBTITLE, wszTitle, sizeof(WCHAR[MAX_LOAD_STRING])); + if(wszFileName) lstrcpyW(typelib.wszFileName, wszFileName); + else + { + TVITEM tvi; + + memset(&tvi, 0, sizeof(TVITEM)); + tvi.hItem = TreeView_GetSelection(globals.hTree); + + SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi); + lstrcpyW(typelib.wszFileName, ((ITEM_INFO*)tvi.lParam)->path); + } + globals.hTypeLibWnd = CreateWindow(wszTypeLib, wszTitle, WS_OVERLAPPEDWINDOW|WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInst, NULL);