From b69592416c57d12fe70811f82b7f6297bde9d7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Thu, 17 Jul 2008 16:58:07 +0200 Subject: [PATCH] wordpad: Show error if file open fails. --- programs/wordpad/En.rc | 2 ++ programs/wordpad/No.rc | 2 ++ programs/wordpad/wordpad.c | 19 +++++++++++++++++++ programs/wordpad/wordpad.h | 2 ++ 4 files changed, 25 insertions(+) diff --git a/programs/wordpad/En.rc b/programs/wordpad/En.rc index d1a84730edc..b9e455226c7 100644 --- a/programs/wordpad/En.rc +++ b/programs/wordpad/En.rc @@ -236,4 +236,6 @@ BEGIN STRING_OLE_STORAGE_NOT_SUPPORTED, "OLE storage documents are not supported" STRING_WRITE_FAILED, "Could not save the file." STRING_WRITE_ACCESS_DENIED, "You do not have access to save the file." + STRING_OPEN_FAILED, "Could not open the file." + STRING_OPEN_ACCESS_DENIED, "You do not have access to open the file." END diff --git a/programs/wordpad/No.rc b/programs/wordpad/No.rc index f73b14597ca..5a3be26d136 100644 --- a/programs/wordpad/No.rc +++ b/programs/wordpad/No.rc @@ -236,4 +236,6 @@ BEGIN STRING_OLE_STORAGE_NOT_SUPPORTED, "OLE storage documents are not supported" STRING_WRITE_FAILED, "Klarte ikke lagre filen." STRING_WRITE_ACCESS_DENIED, "Du har ikke tilgang til å lagre filen." + STRING_OPEN_FAILED, "Klarte ikke åpne filen." + STRING_OPEN_ACCESS_DENIED, "Du har ikke tilgang til å åpne filen." END diff --git a/programs/wordpad/wordpad.c b/programs/wordpad/wordpad.c index 20fa60c8a1c..be6bb8be55a 100644 --- a/programs/wordpad/wordpad.c +++ b/programs/wordpad/wordpad.c @@ -698,6 +698,22 @@ static void set_fileformat(WPARAM format) target_device(hMainWnd, wordWrap[reg_formatindex(fileFormat)]); } +static void ShowOpenError(DWORD Code) +{ + LPWSTR Message; + + switch(Code) + { + case ERROR_ACCESS_DENIED: + Message = MAKEINTRESOURCEW(STRING_OPEN_ACCESS_DENIED); + break; + + default: + Message = MAKEINTRESOURCEW(STRING_OPEN_FAILED); + } + MessageBoxW(hMainWnd, Message, wszAppTitle, MB_ICONEXCLAMATION | MB_OK); +} + static void DoOpenFile(LPCWSTR szOpenFileName) { HANDLE hFile; @@ -709,7 +725,10 @@ static void DoOpenFile(LPCWSTR szOpenFileName) hFile = CreateFileW(szOpenFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) + { + ShowOpenError(GetLastError()); return; + } ReadFile(hFile, fileStart, 5, &readOut, NULL); SetFilePointer(hFile, 0, NULL, FILE_BEGIN); diff --git a/programs/wordpad/wordpad.h b/programs/wordpad/wordpad.h index c5305bb8088..96b2a25893f 100644 --- a/programs/wordpad/wordpad.h +++ b/programs/wordpad/wordpad.h @@ -195,6 +195,8 @@ #define STRING_OLE_STORAGE_NOT_SUPPORTED 1706 #define STRING_WRITE_FAILED 1707 #define STRING_WRITE_ACCESS_DENIED 1708 +#define STRING_OPEN_FAILED 1709 +#define STRING_OPEN_ACCESS_DENIED 1710 LPWSTR file_basename(LPWSTR);