Exemple #1
0
LRESULT CPageDesignerApp::OnFileOpen(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	static LPCTSTR FilesFilter = _T(	"All Files\0*.*\0"
												"PageDesigner Document (*.pddoc)\0*.pddoc\0"
												);

	TCHAR sbuffer[4096];
	strcpy(sbuffer, "");	// Initial filename
	
	TCHAR curdir[MAX_PATH];
	GetCurrentDirectory(sizeof(curdir), curdir);

	HWND hwnd = GetMainHwnd();

	OPENFILENAME	ofn = {0};
	ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400A;//sizeof(OPENFILENAME);
	ofn.hwndOwner = hwnd;
	ofn.hInstance = _Module.m_hInst;
	ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
	ofn.lpstrFile = sbuffer;
	ofn.nMaxFile = sizeof(sbuffer);
	ofn.lpstrInitialDir = curdir;
	ofn.lpstrFilter = FilesFilter;
	
	if (GetOpenFileName(&ofn))
	{
		BOOL success = FALSE;

		CComPtr<IArchive> ar;
		ar.CoCreateInstance(CLSID_Archive);

		CComPtr<IArchiveElement> node;
		if (SUCCEEDED(ar->Open(_bstr_t(sbuffer), 2, L"pddoc", &node)))
		{
			CComObject<CPDDocument>* pddocument;
			CComObject<CPDDocument>::CreateInstance(&pddocument);
			if (pddocument)
			{
				pddocument->AddRef();

				HRESULT hr = pddocument->Deserialize(ar, node, NULL);
				success = SUCCEEDED(hr);

				pddocument->ShowViews();
			}
		}


		/*
		LPTSTR ext = PathFindExtension(sbuffer);

		CComPtr<IDOMDocument> document;
		document.CoCreateInstance(CLSID_LDOMDocument);

		VARIANT_BOOL bloaded;
		document->load(_bstr_t(sbuffer), &bloaded);
		if (bloaded)
		{
			CComPtr<IDOMElement> documentElement;
			document->get_documentElement(&documentElement);
			if (documentElement)
			{
				CComObject<CPDDocument>* pddocument;
				CComObject<CPDDocument>::CreateInstance(&pddocument);
				if (pddocument)
				{
					pddocument->AddRef();

					HRESULT hr = pddocument->loadXML(documentElement);
					success = SUCCEEDED(hr);

					pddocument->ShowViews();
				}
			}
		}
		*/

		if (!success)
		{
			MessageBox(GetMainHwnd(), "Failed to load document", "PageDesigner", MB_OK);
		}
	}
	return 0;
}