mirror of
https://github.com/holub/mame
synced 2025-07-06 10:29:38 +03:00
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
This commit is contained in:
parent
c81a76166d
commit
69f23d3d84
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user