implemented get window title for win32

This commit is contained in:
Bayemite 2021-05-31 20:58:29 +10:00
parent 114776a246
commit 88afee4222
4 changed files with 63 additions and 1 deletions

View File

@ -2895,6 +2895,26 @@ GLFWAPI int glfwWindowShouldClose(GLFWwindow* window);
*/
GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* window, int value);
/*! @brief Retrieves the title of the specified window.
*
* This function gets the window title, encoded as UTF-8, of the specified
* window.
*
* @param[in] window The window to query.
* @return A copy of the UTF-8 encoded window title, or NULL if an error has occurred.
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_ERROR.
*
* @thread_safety This function must only be called from the main thread.
*
* @sa @ref window_title
* @sa @ref glfwSetWindowTitle
*
* @ingroup window
*/
GLFWAPI char* glfwGetWindowTitle(GLFWwindow* window);
/*! @brief Sets the title of the specified window.
*
* This function sets the window title, encoded as UTF-8, of the specified
@ -2912,7 +2932,8 @@ GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* window, int value);
* @thread_safety This function must only be called from the main thread.
*
* @sa @ref window_title
*
* @sa @ref glfwGetWindowTitle
*
* @since Added in version 1.0.
* @glfw3 Added window handle parameter.
*

View File

@ -650,6 +650,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig);
void _glfwPlatformDestroyWindow(_GLFWwindow* window);
char* _glfwPlatformGetWindowTitle(_GLFWwindow* window);
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
int count, const GLFWimage* images);

View File

@ -1462,6 +1462,37 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
DestroyIcon(window->win32.smallIcon);
}
char* _glfwPlatformGetWindowTitle(_GLFWwindow* window)
{
int count = GetWindowTextLengthW(window->win32.handle);
if(count == 0)
{
SetLastError(0);
int error = GetLastError();
if(error != 0)
{
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, "Win32: Querying window title failed");
return NULL;
}
else
return calloc(1, sizeof(char)); // single \0
}
else
{
count += 1; // the \0
WCHAR* wideTitle = calloc(count, sizeof(WCHAR));
GetWindowTextW(window->win32.handle, wideTitle, count);
char* title = _glfwCreateUTF8FromWideStringWin32(wideTitle);
if(!title)
return calloc(1, sizeof(char)); // single \0
return title;
}
}
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
{
WCHAR* wideTitle = _glfwCreateWideStringFromUTF8Win32(title);

View File

@ -501,6 +501,15 @@ GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* handle, int value)
window->shouldClose = value;
}
GLFWAPI char* glfwGetWindowTitle(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return _glfwPlatformGetWindowTitle(window);
}
GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title)
{
_GLFWwindow* window = (_GLFWwindow*) handle;