c++ - SDL - 窗口数据

标签 c++ sdl

我在浏览 SDL 文档时发现 WindowData(SDL_SetWindowDataSDL_GetWindowData)。 这些函数有什么用?它存储与名称关联的 void 指针,那么它是否仅用于存储我以后可以使用的对象?或者它在 SDL 中是否重要?

最佳答案

这些函数应该可以让您使用窗口对象存储指向任意数据(例如,您选择的内存缓冲区或对象)的指针:

MyObject *object_ptr = new MyObject(); // Your custom object
object_ptr->data = 42; // Your custom data
SDL_SetWindowData(window, "mycustomdata", object_ptr);

// Somewhere else in your code in a place where you have access to 'window'
MyObject *object_ptr = SDL_GetWindowData(window, "mycustomdata");
// do whatever you want with object_ptr..

此行为模仿 win32 API 的 SetWindowLong(hwnd, GWL_USERDATA, pointer); 调用。

关于c++ - SDL - 窗口数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26604970/

相关文章:

c++ - cin.getline 跳过一行输入并获取下一行

c++ - 写入内核配置时为 "Not a directory"

c++ - 损坏的顶点和片段着色器

c++ - 类型不匹配

C++ 我需要为嵌套类定义 header 保护吗?

c++ - 在不指定名称的情况下读取图像文件

c++ - 使用 std::vector 的指针失效

c++ - 在带有 g++ 的 Linux 上使用 SDL2?

c++ - 出现对话框时如何关闭主窗口

c++ - SDL UI 菜单按钮 - 鼠标悬停