Sat, 14 Oct 2023 10:55:11 +0200
implement table activate/selection events (WinUI3)
// Dies ist die Haupt-DLL. #include "stdafx.h" #include <stdio.h> #include "toolkit.h" #using "UIcore.dll" static UIcallback startup_func; void *startup_data; static UIcallback open_func; void *open_data; static UIcallback exit_func; void *exit_data; public ref class AppCallbacks : public UI::IApplicationCallbacks { public: UIcallback startupFunc = NULL; void *startupData = NULL; UIcallback openFunc = NULL; void *openData = NULL; UIcallback exitFunc = NULL; void *exitData = NULL; virtual void __clrcall OnStartup() { if (startupFunc) { startupFunc(NULL, startupData); } } virtual void __clrcall OnOpen() { if (openFunc) { openFunc(NULL, openData); } } virtual void __clrcall OnExit() { if (exitFunc) { exitFunc(NULL, exitData); } } }; void* ObjectToPtr(Object ^obj) { GCHandle handle = GCHandle::Alloc(obj); IntPtr pointer = GCHandle::ToIntPtr(handle); return pointer.ToPointer(); } Object^ PtrToObject(void *ptr) { GCHandle h = GCHandle::FromIntPtr(IntPtr(ptr)); Object^ object = h.Target; //h.Free(); return object; } // EventWrapper ObjEventWrapper::ObjEventWrapper(UIcallback callback, void *eventdata) { this->callback = callback; this->eventdata = eventdata; action = gcnew Action<IntPtr>(this, &ObjEventWrapper::Callback); } Action<IntPtr>^ ObjEventWrapper::GetAction() { return action; } void ObjEventWrapper::Callback(IntPtr uiobj) { if (callback) { callback(uiobj.ToPointer(), eventdata); } } EventWrapper::EventWrapper(UIcallback callback, void *eventdata) { this->callback = callback; this->eventdata = eventdata; } void EventWrapper::Callback(Object ^sender, RoutedEventArgs ^e) { if (callback) { callback(NULL, eventdata); } } UI_EXPORT void __stdcall UIinit(char *appname) { UI::Application ^app = UI::Application::GetInstance(); app->Name = gcnew String(appname); } UI_EXPORT void __stdcall UIonstartup(UIcallback f, void *userdata) { startup_func = f; startup_data = userdata; } UI_EXPORT void __stdcall UIonopen(UIcallback f, void *userdata) { open_func = f; open_data = userdata; } UI_EXPORT void __stdcall UIonexit(UIcallback f, void *userdata) { exit_func = f; exit_data = userdata; } UI_EXPORT void __stdcall UImain() { AppCallbacks ^ac = gcnew AppCallbacks(); ac->startupFunc = startup_func; ac->startupData = startup_data; ac->openFunc = open_func; ac->openData = open_data; ac->exitFunc = exit_func; ac->exitData = exit_data; UI::Application ^app = UI::Application::GetInstance(); app->callbacks = ac; Thread ^thread = app->Start(); thread->Join(); } UI_EXPORT void __stdcall UIshow(gcroot<UI::MainWindow^> *window) { (*window)->ShowWindow(); }