summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Nathan Woods <npwoods@mess.org>2016-09-25 22:22:18 -0400
committer Nathan Woods <npwoods@mess.org>2016-09-25 22:22:18 -0400
commit69f23d3d84b6741d262803152d707afa5086b7b7 (patch)
treea0df6a6f56e1d8560ad74d29de4439c5c26dbfe3
parentc81a76166d52d7b918180062807b9b068fddd63e (diff)
Changed win_get_window_text_utf8() to return std::string
This eliminated an unnecessary conversion step. Also, I have no idea what this WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) stuff is; it is hard to understand how it could possibly be correct because it ignores the 'window' parameter
-rw-r--r--src/osd/modules/debugger/win/consolewininfo.cpp6
-rw-r--r--src/osd/windows/winutf8.cpp33
-rw-r--r--src/osd/windows/winutf8.h2
3 files changed, 20 insertions, 21 deletions
diff --git a/src/osd/modules/debugger/win/consolewininfo.cpp b/src/osd/modules/debugger/win/consolewininfo.cpp
index de1c65f90cb..5ba21d46167 100644
--- a/src/osd/modules/debugger/win/consolewininfo.cpp
+++ b/src/osd/modules/debugger/win/consolewininfo.cpp
@@ -99,11 +99,9 @@ void consolewin_info::set_cpu(device_t &device)
m_views[1]->set_source_for_device(device);
// then update the caption
- char curtitle[256];
-
std::string title = string_format("Debug: %s - %s '%s'", device.machine().system().name, device.name(), device.tag());
- win_get_window_text_utf8(window(), curtitle, ARRAY_LENGTH(curtitle));
- if (title.compare(curtitle) != 0)
+ std::string curtitle = win_get_window_text_utf8(window());
+ if (title != curtitle)
win_set_window_text_utf8(window(), title.c_str());
// and recompute the children
diff --git a/src/osd/windows/winutf8.cpp b/src/osd/windows/winutf8.cpp
index 0086ad7b383..ed2a84ca679 100644
--- a/src/osd/windows/winutf8.cpp
+++ b/src/osd/windows/winutf8.cpp
@@ -89,26 +89,27 @@ BOOL win_set_window_text_utf8(HWND window, const char *text)
// win_get_window_text_utf8
//============================================================
-int win_get_window_text_utf8(HWND window, char *buffer, size_t buffer_size)
+std::string win_get_window_text_utf8(HWND window)
{
- int result = 0;
- TCHAR t_buffer[256];
-
- t_buffer[0] = '\0';
-
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
- // invoke the core Win32 API
- GetWindowText(window, t_buffer, ARRAY_LENGTH(t_buffer));
+ {
+ // invoke the core Win32 API
+ int length = GetWindowTextLength(window);
+ if (length <= 0)
+ return std::string();
+
+ TCHAR *buffer = (TCHAR *) alloca((length + 1) * sizeof(TCHAR));
+ GetWindowText(window, buffer, length + 1);
+ return utf8_from_tstring(buffer);
+ }
#else
- auto title = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView()->Title;
- wcsncpy(t_buffer, title->Data(), ARRAY_LENGTH(t_buffer));
+ {
+ TCHAR t_buffer[256];
+ auto title = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView()->Title;
+ wcsncpy(t_buffer, title->Data(), ARRAY_LENGTH(t_buffer));
+ return utf8_from_tstring(t_buffer);
+ }
#endif
-
- std::string utf8_buffer = utf8_from_tstring(t_buffer);
-
- result = snprintf(buffer, buffer_size, "%s", utf8_buffer.c_str());
-
- return result;
}
diff --git a/src/osd/windows/winutf8.h b/src/osd/windows/winutf8.h
index 6aa72b6a21c..a8d072ed2cc 100644
--- a/src/osd/windows/winutf8.h
+++ b/src/osd/windows/winutf8.h
@@ -17,7 +17,7 @@ void win_output_debug_string_utf8(const char *string);
// wrappers for user32.dll
int win_message_box_utf8(HWND window, const char *text, const char *caption, UINT type);
BOOL win_set_window_text_utf8(HWND window, const char *text);
-int win_get_window_text_utf8(HWND window, char *buffer, size_t buffer_size);
+std::string win_get_window_text_utf8(HWND window);
HWND win_create_window_ex_utf8(DWORD exstyle, const char* classname, const char* windowname, DWORD style,
int x, int y, int width, int height, HWND wndparent, HMENU menu,
HINSTANCE instance, void* param);