filedrm.cpp

来自「WIndows mobile 5.0 pocket pc sdk sample 」· C++ 代码 · 共 639 行 · 第 1/2 页

CPP
639
字号
			if (s_hWndLV)
			{	
				FillListView (g_hInst, s_hWndLV, g_szCurrentDirectory);
				SetFocus (s_hWndLV);
			}

            break;
        case WM_PAINT:
            RECT rc;

			hdc = BeginPaint(hWnd, &ps);

			GetClientRect (hWnd, &rc);
            if (g_pDisplayedImage)
			{
				if (FAILED (g_pDisplayedImage->Draw (hWnd, hdc, &rc)))
				{
					delete g_pDisplayedImage;
					g_pDisplayedImage = NULL;

					ShowWindow (s_hWndLV, SW_SHOW);
					SetFocus (s_hWndLV);
				}
			}

            EndPaint(hWnd, &ps);
            break;
        case WM_DESTROY:
#ifdef SHELL_AYGSHELL
            CommandBar_Destroy(g_hWndMenuBar);
#endif // SHELL_AYGSHELL
			if (g_pDisplayedImage)
			{
				delete g_pDisplayedImage;
			}

			PostQuitMessage(0);
            break;

#if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP)
        case WM_ACTIVATE:
            // Notify shell of our activate message
            SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
            break;
        case WM_SETTINGCHANGE:
            SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
            break;
#endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP

		case WM_DISPLAYIMAGE:
			ShowWindow (s_hWndLV, SW_HIDE);
			SetFocus (hWnd);
			break;

		case WM_INITMENUPOPUP:
			if (!g_pDisplayedImage)
			{
				const HMENU hmenuPopup = reinterpret_cast<HMENU>(wParam); 
				OnInitMenuPopup (s_hWndLV, hmenuPopup);
			}
			break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

#ifndef WIN32_PLATFORM_WFSP
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
#ifdef SHELL_AYGSHELL
            {
                // Create a Done button and size it.  
                SHINITDLGINFO shidi;
                shidi.dwMask = SHIDIM_FLAGS;
                shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
                shidi.hDlg = hDlg;
                SHInitDialog(&shidi);
            }
#endif // SHELL_AYGSHELL

            return (INT_PTR)TRUE;

        case WM_COMMAND:
#ifdef SHELL_AYGSHELL
            if (LOWORD(wParam) == IDOK)
#endif
            {
                EndDialog(hDlg, LOWORD(wParam));
                return (INT_PTR)TRUE;
            }
            break;

        case WM_CLOSE:
            EndDialog(hDlg, message);
            return (INT_PTR)TRUE;

#ifdef _DEVICE_RESOLUTION_AWARE
        case WM_SIZE:
            {
		DRA::RelayoutDialog(
			g_hInst, 
			hDlg, 
			DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_ABOUTBOX_WIDE) : MAKEINTRESOURCE(IDD_ABOUTBOX));
            }
            break;
#endif
    }
    return (INT_PTR)FALSE;
}
#endif // !WIN32_PLATFORM_WFSP


LRESULT OnNotify (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	LRESULT lResult = 0;

	const LPNMHDR pNotifyHeader = reinterpret_cast<LPNMHDR>(lParam);

	if (pNotifyHeader->idFrom == ID_LISTVIEW)
	{
		const HWND hWndList = pNotifyHeader->hwndFrom;

		switch(pNotifyHeader->code)
		{
			case NM_RECOGNIZEGESTURE:
				lResult = TRUE;				// No gestures
				break;

			case LVN_ITEMACTIVATE:
			{
				LVITEM lvi = { 0 };
				const LPNMLISTVIEW lpnmlv = reinterpret_cast<LPNMLISTVIEW>(lParam);
				TCHAR szText[MAX_PATH];

				lvi.mask = LVIF_TEXT | LVIF_PARAM;
				lvi.iItem = lpnmlv->iItem;
				lvi.pszText = szText;
				lvi.cchTextMax = ARRAYSIZE(szText);
				ListView_GetItem (hWndList, &lvi);

				const DWORD dwFileAttributes = lvi.lParam;
				if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
				{
					size_t cchCurrentDirectory;
					StringCchLength (g_szCurrentDirectory, ARRAYSIZE(g_szCurrentDirectory), &cchCurrentDirectory);
					if (*((g_szCurrentDirectory + cchCurrentDirectory) - 1) != _T('\\'))
					{
						StringCchCat (g_szCurrentDirectory, ARRAYSIZE(g_szCurrentDirectory), _T("\\"));
					}
					StringCchCat (g_szCurrentDirectory, ARRAYSIZE(g_szCurrentDirectory), szText);
					FillListView (g_hInst, hWndList, g_szCurrentDirectory);
				}
				else
				{
					if (IsJPEGFile (szText))
					{
						if (FAILED (DisplayJPEG (hWnd, g_szCurrentDirectory, szText)))
                        {
                            /*
                             *  In case we fail to display the image ensure that the
                             *  listview window still has focus.
                             */
                            SetFocus(hWndList);
                        }
					}
					else
					{
						TCHAR szMessage [MAX_LOADSTRING];
						TCHAR szTitle [MAX_LOADSTRING];
						
						if (   0 != LoadString (g_hInst, IDS_NOHANDLER_MSG, szMessage, ARRAYSIZE (szMessage))
							&& 0 != LoadString (g_hInst, IDS_NOHANDLER_TITLE, szTitle, ARRAYSIZE (szTitle)))
						{
							MessageBox (hWnd, szMessage, szTitle, MB_OK | MB_ICONERROR);
							SetFocus (hWndList);
						}
					}
				}
				break;
			}

			default:
				break;
		}
	}

	return lResult;
}



HRESULT IsDRMProtected (const LPCTSTR pszDirectory, const LPCTSTR pszFile, BOOL *fIsDRM)
{
	HRESULT	hr;
	BOOL	fResult;
	TCHAR	szFullPath [MAX_PATH];

	fResult = FALSE;
	hr = BuildFullName (szFullPath, ARRAYSIZE (szFullPath), pszDirectory, pszFile);
	if (SUCCEEDED (hr))
	{
		hr = FileDrmIsDRM (szFullPath, &fResult);
		if (SUCCEEDED (hr))
		{
			*fIsDRM = fResult;
		}
	}
	return hr;
}



HRESULT DisplayJPEG (HWND hWnd, const LPCTSTR pszDirectory, const LPCTSTR pszFile)
{
	HRESULT hr;
	TCHAR	szFullName[MAX_PATH];

	hr = BuildFullName (szFullName, ARRAYSIZE (szFullName), pszDirectory, pszFile);
	if (SUCCEEDED (hr))
	{
		assert (g_pDisplayedImage == NULL);
		g_pDisplayedImage = new CImageView ();
		if (g_pDisplayedImage)
		{
			hr = g_pDisplayedImage->OpenImageFile (hWnd, szFullName);
            if (SUCCEEDED (hr))
            {
    			if (SendMessage (hWnd, WM_DISPLAYIMAGE, 0, 0))
	    		{
		    		const DWORD dwLastError = GetLastError ();
			    	hr = HRESULT_FROM_WIN32(dwLastError);
			    }
            }
		}
		else
		{
			hr = E_OUTOFMEMORY;
		}
	}
	return hr;
}

HRESULT ShowProtectionStatus (HWND hWndList)
{
	HRESULT hr;
	LVITEM	lvi = { 0 };
	TCHAR	szText[MAX_PATH];
	BOOL	fIsDRM;

	lvi.mask = LVIF_TEXT;
	lvi.iItem = ListView_GetSelectionMark (hWndList);
	if (lvi.iItem != -1)
	{
		lvi.pszText = szText;
		lvi.cchTextMax = ARRAYSIZE(szText);
	
		if (ListView_GetItem (hWndList, &lvi))
		{
			hr = IsDRMProtected (g_szCurrentDirectory, szText, &fIsDRM);
			if (SUCCEEDED (hr) && fIsDRM)
			{
				TCHAR szFullpath [MAX_PATH];

				hr = BuildFullName (szFullpath, ARRAYSIZE (szFullpath), g_szCurrentDirectory, szText);
				if (SUCCEEDED (hr))
				{
					hr = FileDrmShowLicenseInfo (hWndList, szFullpath);
				}
			}
		}
	}
	else
	{
		hr = E_INVALIDARG;
	}

	return hr;
}

LRESULT	OnInitMenuPopup	(HWND hWndList, HMENU hmenuPopup)
{
	HRESULT hr;
	LVITEM	lvi = { 0 };
	TCHAR	szText[MAX_PATH];
	BOOL	fIsDRM;

	lvi.mask = LVIF_TEXT;
	lvi.iItem = ListView_GetSelectionMark (hWndList);
	if (lvi.iItem != -1)
	{
		lvi.pszText = szText;
		lvi.cchTextMax = ARRAYSIZE(szText);
		if (ListView_GetItem (hWndList, &lvi))
		{
			hr = IsDRMProtected (g_szCurrentDirectory, szText, &fIsDRM);
			if (SUCCEEDED (hr) && fIsDRM)
			{
				EnableMenuItem (hmenuPopup, ID_MENU_DRMPROTECTION, MF_BYCOMMAND | MF_ENABLED);
			}
			else
			{
				EnableMenuItem (hmenuPopup, ID_MENU_DRMPROTECTION, MF_BYCOMMAND | MF_GRAYED);
			}
		}
	}
	else
	{
		EnableMenuItem (hmenuPopup, ID_MENU_DRMPROTECTION, MF_BYCOMMAND | MF_GRAYED);
	}

	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?