예제 #1
0
HRESULT CreateLink(const TCHAR* path_to_obj, const TCHAR* path_link, const TCHAR* description)
{
	IShellLinkPtr shell_link;
	if (HRESULT hr= shell_link.CreateInstance(CLSID_ShellLink))
		return hr;

	shell_link->SetPath(path_to_obj);
	shell_link->SetDescription(description);

	IPersistFilePtr file;
	if (HRESULT hr= shell_link.QueryInterface(IID_IPersistFile, &file))
		return hr;

#ifndef _UNICODE
	WCHAR path[MAX_PATH];
	::MultiByteToWideChar(CP_ACP, 0, path_link, -1, path, MAX_PATH);
	return file->Save(path, true);
#else
	return file->Save(path_link, true);
#endif
}
STDMETHODIMP CFDMFlashVideoDownloads::ProcessIeDocument(IDispatch *pDispatch)
{
	IHTMLDocument2Ptr spDoc (pDispatch);
	if (spDoc == NULL)
		return E_INVALIDARG;

	IPersistFilePtr spFile (pDispatch);
	if (spFile == NULL)
		return E_INVALIDARG;

	

	USES_CONVERSION;
	BSTR bstrHost = NULL;
	spDoc->get_URL (&bstrHost);
	fsURL url;
	if (url.Crack (W2A (bstrHost)) != IR_SUCCESS)
		return E_FAIL;
	SysFreeString (bstrHost);

	char szPath [MY_MAX_PATH];
	GetTempPath (sizeof (szPath), szPath);
	char szFile [MY_MAX_PATH];
	GetTempFileName (szPath, "fdm", 0, szFile);

	COleVariant vaFile (szFile);
	if (FAILED (spFile->Save (vaFile.bstrVal, FALSE)))
		return E_FAIL;

	HANDLE hFile = CreateFile (szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (hFile == INVALID_HANDLE_VALUE)
		return E_FAIL;

	DWORD dw = GetFileSize (hFile, NULL);

	LPSTR pszHtml = new char [dw + 1];
	ReadFile (hFile, pszHtml, dw, &dw, NULL);
	pszHtml [dw] = 0;

	CloseHandle (hFile);
	DeleteFile (szFile);

	ProcessHtml (url.GetHostName (), pszHtml);
	delete [] pszHtml;

	return S_OK;
}
예제 #3
0
파일: window.cpp 프로젝트: quartorz/55Y90nn
LRESULT CALLBACK window_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	auto on_create = [&](...) -> bool {
		HINSTANCE hinst = ::GetModuleHandle(nullptr);

		HICON hicon = static_cast<HICON>(LoadImage(
			hinst, MAKEINTRESOURCE(IDI_ICON32),
			IMAGE_ICON,
			0,
			0,
			LR_DEFAULTSIZE | LR_SHARED));

		if (hicon == nullptr)
			return false;

		NOTIFYICONDATA nid = {};
		nid.cbSize = sizeof(NOTIFYICONDATA);
		nid.hWnd = hwnd;
		nid.uID = id_tasktray;
		nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
		nid.uCallbackMessage = callback_msg;
		nid.hIcon = hicon;
		::_tcscpy_s(nid.szTip, _T("55Y90nn"));

		return ::Shell_NotifyIcon(NIM_ADD, &nid) != FALSE;
	};

	auto on_command = [&](HWND hwnd, int id, HWND hctl, UINT code) -> void {
		switch (id) {
		case ID_MENU_ADDTOSTARTUP:
		{
			bool succeeded = false;

			string_type startup_dir = ::get_startup_dir(hwnd);
			string_type shortcut_path;
			string_type process_path;
			string_type working_dir;

			shortcut_path.reserve(MAX_PATH);
			process_path.reserve(MAX_PATH);
			working_dir.reserve(_MAX_DRIVE + _MAX_DIR);

			if (startup_dir.size() != 0) {
				TCHAR shortcut_path_str[MAX_PATH];

				if (::PathCombine(shortcut_path_str, startup_dir.data(), _T("55Y90nn.lnk")) != nullptr) {
					shortcut_path = shortcut_path_str;

					TCHAR process_path_str[MAX_PATH];

					if (::GetModuleFileName(nullptr, process_path_str, MAX_PATH) < MAX_PATH) {
						process_path = process_path_str;

						TCHAR drive[_MAX_DRIVE], dir[_MAX_DIR];

						if (::_tsplitpath_s(process_path_str, drive, _MAX_DRIVE, dir, _MAX_DIR, nullptr, 0, nullptr, 0) != EINVAL) {
							working_dir = drive;
							working_dir += dir;
						}
					}
				}

				if (working_dir.size() != 0) {
					IShellLinkPtr psl;
					IPersistFilePtr ppf;

					psl.CreateInstance(CLSID_ShellLink);

					if (SUCCEEDED(psl->SetPath(process_path.data()))
							&& SUCCEEDED(psl->SetDescription(_T("wheel emulator for trackpoint")))
							&& SUCCEEDED(psl->SetWorkingDirectory(working_dir.data()))
							&& SUCCEEDED(psl->QueryInterface(&ppf))) {
						succeeded = SUCCEEDED(ppf->Save(shortcut_path.data(), TRUE));
					}
				}
			}

			if (succeeded) {
				::MessageBox(hwnd, _T("succeeded to add to startup"), _T("message"), MB_OK);
			} else {
				::MessageBox(hwnd, _T("failed to add to startup"), _T("error"), MB_OK | MB_ICONWARNING);
			}

			break;
		}

		case ID_MENU_EXIT:
			::DestroyWindow(hwnd);
			break;
		}
	};

	switch (msg) {
		HANDLE_MSG(hwnd, WM_CREATE, on_create);
		HANDLE_MSG(hwnd, WM_COMMAND, on_command);

	case WM_DESTROY:
		::PostQuitMessage(0);
		return 0;

	case callback_msg:
		if (wParam == id_tasktray) {
			if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN) {
				auto hinst = ::GetModuleHandle(nullptr);

				HMENU hmenu = ::LoadMenu(hinst, MAKEINTRESOURCE(IDR_MENU));
				HMENU hsubmenu = nullptr;

				if (hmenu != nullptr) {
					hsubmenu = ::GetSubMenu(hmenu, 0);
				}

				if (hsubmenu != nullptr) {
					POINT pt;
					::GetCursorPos(&pt);
					::SetForegroundWindow(hwnd);
					::TrackPopupMenu(hsubmenu, TPM_BOTTOMALIGN, pt.x, pt.y, 0, hwnd, nullptr);
					::DestroyMenu(hmenu);
				}
			}

			return 0;
		}

		break;
	}

	return ::DefWindowProc(hwnd, msg, wParam, lParam);
}