2014-10-28 95 views

回答

3

這些功能都應該讓你存儲的指針指向任意的數據(例如,您的選擇或對象的內存緩衝區)有一個窗口對象:

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.. 

這種行爲模仿SetWindowLong(hwnd, GWL_USERDATA, pointer);調用Win32的API。

+1

很好的例子,真正的文檔應該有這樣的 – Zammalad 2014-10-28 15:36:02