diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-30 15:38:47 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-30 15:38:47 +0000 |
commit | fff369b8be4e7df5af4f9c2cedd29234248fd35b (patch) | |
tree | 4e6494c94c2cb379273ab1beab20c0c142485601 /base | |
parent | c376c45bd9f166acbdc776c640161d7fbd5956a4 (diff) | |
download | chromium_src-fff369b8be4e7df5af4f9c2cedd29234248fd35b.zip chromium_src-fff369b8be4e7df5af4f9c2cedd29234248fd35b.tar.gz chromium_src-fff369b8be4e7df5af4f9c2cedd29234248fd35b.tar.bz2 |
Remove win_util::FormatMessage and FormatLastWin32Error. These were only used in a couple of diagnostic places and one can always use the "Error Lookup" utility.
Move window HWND-specific functions from base/win_util.h to a new file app/win/hwnd_util.h. I plan to put some more stuff from app/win_util into this file as well.
Move gfx/window_impl.h into app/win
TEST=it compiles
BUG=none
Review URL: http://codereview.chromium.org/6019007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70312 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/file_util_win.cc | 10 | ||||
-rw-r--r-- | base/win_util.cc | 67 | ||||
-rw-r--r-- | base/win_util.h | 19 | ||||
-rw-r--r-- | base/win_util_unittest.cc | 37 |
4 files changed, 4 insertions, 129 deletions
diff --git a/base/file_util_win.cc b/base/file_util_win.cc index 3ca52ae..2644803 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -757,9 +757,8 @@ int WriteFile(const FilePath& filename, const char* data, int size) { 0, NULL)); if (!file) { - LOG(WARNING) << "CreateFile failed for path " << filename.value() << - " error code=" << GetLastError() << - " error text=" << win_util::FormatLastWin32Error(); + LOG(WARNING) << "CreateFile failed for path " << filename.value() + << " error code=" << GetLastError(); return -1; } @@ -770,9 +769,8 @@ int WriteFile(const FilePath& filename, const char* data, int size) { if (!result) { // WriteFile failed. - LOG(WARNING) << "writing file " << filename.value() << - " failed, error code=" << GetLastError() << - " description=" << win_util::FormatLastWin32Error(); + LOG(WARNING) << "writing file " << filename.value() + << " failed, error code=" << GetLastError(); } else { // Didn't write all the bytes. LOG(WARNING) << "wrote" << written << " bytes to " << diff --git a/base/win_util.cc b/base/win_util.cc index 3fcfb92..b7d5cd7 100644 --- a/base/win_util.cc +++ b/base/win_util.cc @@ -70,30 +70,6 @@ bool GetUserSidString(std::wstring* user_sid) { return true; } -#pragma warning(push) -#pragma warning(disable:4312 4244) -WNDPROC SetWindowProc(HWND hwnd, WNDPROC proc) { - // The reason we don't return the SetwindowLongPtr() value is that it returns - // the orignal window procedure and not the current one. I don't know if it is - // a bug or an intended feature. - WNDPROC oldwindow_proc = - reinterpret_cast<WNDPROC>(GetWindowLongPtr(hwnd, GWLP_WNDPROC)); - SetWindowLongPtr(hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(proc)); - return oldwindow_proc; -} - -void* SetWindowUserData(HWND hwnd, void* user_data) { - return - reinterpret_cast<void*>(SetWindowLongPtr(hwnd, GWLP_USERDATA, - reinterpret_cast<LONG_PTR>(user_data))); -} - -void* GetWindowUserData(HWND hwnd) { - return reinterpret_cast<void*>(GetWindowLongPtr(hwnd, GWLP_USERDATA)); -} - -#pragma warning(pop) - bool IsShiftPressed() { return (::GetKeyState(VK_SHIFT) & 0x8000) == 0x8000; } @@ -106,27 +82,6 @@ bool IsAltPressed() { return (::GetKeyState(VK_MENU) & 0x8000) == 0x8000; } -std::wstring GetClassName(HWND window) { - // GetClassNameW will return a truncated result (properly null terminated) if - // the given buffer is not large enough. So, it is not possible to determine - // that we got the entire class name if the result is exactly equal to the - // size of the buffer minus one. - DWORD buffer_size = MAX_PATH; - while (true) { - std::wstring output; - DWORD size_ret = - GetClassNameW(window, WriteInto(&output, buffer_size), buffer_size); - if (size_ret == 0) - break; - if (size_ret < (buffer_size - 1)) { - output.resize(size_ret); - return output; - } - buffer_size *= 2; - } - return std::wstring(); // error -} - bool UserAccountControlIsEnabled() { // This can be slow if Windows ends up going to disk. Should watch this key // for changes and only read it once, preferably on the file thread. @@ -144,28 +99,6 @@ bool UserAccountControlIsEnabled() { return (uac_enabled != 0); } -std::wstring FormatMessage(unsigned messageid) { - wchar_t* string_buffer = NULL; - unsigned string_length = ::FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, NULL, messageid, 0, - reinterpret_cast<wchar_t *>(&string_buffer), 0, NULL); - - std::wstring formatted_string; - if (string_buffer) { - formatted_string = string_buffer; - LocalFree(reinterpret_cast<HLOCAL>(string_buffer)); - } else { - // The formating failed. simply convert the message value into a string. - base::SStringPrintf(&formatted_string, L"message number %d", messageid); - } - return formatted_string; -} - -std::wstring FormatLastWin32Error() { - return FormatMessage(GetLastError()); -} - bool SetAppIdForPropertyStore(IPropertyStore* property_store, const wchar_t* app_id) { DCHECK(property_store); diff --git a/base/win_util.h b/base/win_util.h index 4ba7eeb..c06e9c7 100644 --- a/base/win_util.h +++ b/base/win_util.h @@ -23,14 +23,6 @@ void GetNonClientMetrics(NONCLIENTMETRICS* metrics); // Returns the string representing the current user sid. bool GetUserSidString(std::wstring* user_sid); -// Useful for subclassing a HWND. Returns the previous window procedure. -WNDPROC SetWindowProc(HWND hwnd, WNDPROC wndproc); - -// Pointer-friendly wrappers around Get/SetWindowLong(..., GWLP_USERDATA, ...) -// Returns the previously set value. -void* SetWindowUserData(HWND hwnd, void* user_data); -void* GetWindowUserData(HWND hwnd); - // Returns true if the shift key is currently pressed. bool IsShiftPressed(); @@ -40,10 +32,6 @@ bool IsCtrlPressed(); // Returns true if the alt key is currently pressed. bool IsAltPressed(); -// A version of the GetClassNameW API that returns the class name in an -// std::wstring. An empty result indicates a failure to get the class name. -std::wstring GetClassName(HWND window); - // Returns false if user account control (UAC) has been disabled with the // EnableLUA registry flag. Returns true if user account control is enabled. // NOTE: The EnableLUA registry flag, which is ignored on Windows XP @@ -52,13 +40,6 @@ std::wstring GetClassName(HWND window); // if the OS is Vista. bool UserAccountControlIsEnabled(); -// Use the Win32 API FormatMessage() function to generate a string, using -// Windows's default Message Compiled resources; ignoring the inserts. -std::wstring FormatMessage(unsigned messageid); - -// Uses the last Win32 error to generate a human readable message string. -std::wstring FormatLastWin32Error(); - // Sets the application id in given IPropertyStore. The function is intended // for tagging application/chromium shortcut, browser window and jump list for // Win7. diff --git a/base/win_util_unittest.cc b/base/win_util_unittest.cc index 673bc84..b0aeb8e 100644 --- a/base/win_util_unittest.cc +++ b/base/win_util_unittest.cc @@ -50,40 +50,3 @@ class ThreadLocaleSaver { }; } // namespace - -TEST(BaseWinUtilTest, FormatMessage) { - // Because we cannot write tests of every language, we only test the message - // of en-US locale. Here, we change the current locale temporarily. - ThreadLocaleSaver thread_locale_saver; - WORD language_id = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); - LCID locale_id = MAKELCID(language_id, SORT_DEFAULT); - ASSERT_TRUE(SetThreadLocale(locale_id)); - - const int kAccessDeniedErrorCode = 5; - SetLastError(kAccessDeniedErrorCode); - ASSERT_EQ(GetLastError(), kAccessDeniedErrorCode); - std::wstring value; - TrimWhitespace(win_util::FormatLastWin32Error(), TRIM_ALL, &value); - EXPECT_EQ(std::wstring(L"Access is denied."), value); - - // Manually call the OS function - wchar_t * string_buffer = NULL; - unsigned string_length = - ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, NULL, - kAccessDeniedErrorCode, 0, - reinterpret_cast<wchar_t *>(&string_buffer), 0, NULL); - - // Verify the call succeeded - ASSERT_TRUE(string_length); - ASSERT_TRUE(string_buffer); - - // Verify the string is the same by different calls - EXPECT_EQ(win_util::FormatLastWin32Error(), std::wstring(string_buffer)); - EXPECT_EQ(win_util::FormatMessage(kAccessDeniedErrorCode), - std::wstring(string_buffer)); - - // Done with the buffer allocated by ::FormatMessage() - LocalFree(string_buffer); -} |