Sun, 16 Apr 2023 10:20:21 +0200
minimal working winui app
--- a/make/vs/testapp/main.c Sat Apr 15 21:06:45 2023 +0200 +++ b/make/vs/testapp/main.c Sun Apr 16 10:20:21 2023 +0200 @@ -1,6 +1,53 @@ -#include <stdio.h> +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2023 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ -int main(int argc, char** argv) { - printf("hello world!\n"); - return 0; +#include <Windows.h> + +#include <stdio.h> +#include <stdlib.h> + +#include <ui/ui.h> + + + +void application_startup(UiEvent* event, void* data) { + UiObject* obj = ui_window("Test", NULL); + + ui_show(obj); } + + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow) +{ + ui_init("app1", 0, NULL); + ui_onstartup(application_startup, NULL); + + ui_main(); + + return (EXIT_SUCCESS); +}
--- a/make/vs/testapp/testapp.vcxproj Sat Apr 15 21:06:45 2023 +0200 +++ b/make/vs/testapp/testapp.vcxproj Sun Apr 16 10:20:21 2023 +0200 @@ -27,6 +27,9 @@ <ProjectGuid>{3541f08b-e6cc-4c23-a0d3-51983aab33c6}</ProjectGuid> <RootNamespace>testapp</RootNamespace> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained> + <WindowsPackageType>None</WindowsPackageType> + <AppxPackage>false</AppxPackage> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> @@ -111,9 +114,10 @@ <SDLCheck>true</SDLCheck> <PreprocessorDefinitions>_DEBUG;_CONSOLE;UI_WINUI;%(PreprocessorDefinitions)</PreprocessorDefinitions> <ConformanceMode>true</ConformanceMode> + <AdditionalIncludeDirectories>C:\Users\Olaf\Projekte\toolkit\ui;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> <Link> - <SubSystem>Console</SubSystem> + <SubSystem>Windows</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> </Link> </ItemDefinitionGroup> @@ -139,6 +143,11 @@ <ItemGroup> <None Include="packages.config" /> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\ui\winui\winui.vcxproj"> + <Project>{04d5ee2c-6076-4c7c-8b70-b0f6d602ff55}</Project> + </ProjectReference> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> <Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
--- a/ui/ui/toolkit.h Sat Apr 15 21:06:45 2023 +0200 +++ b/ui/ui/toolkit.h Sun Apr 16 10:20:21 2023 +0200 @@ -79,6 +79,10 @@ #define FALSE 0 #endif +#ifndef UIEXPORT +#define UIEXPORT +#endif + #ifdef __cplusplus extern "C" { #endif @@ -284,8 +288,8 @@ }; -void ui_init(char *appname, int argc, char **argv); -char* ui_appname(); +void ui_init(const char *appname, int argc, char **argv); +const char* ui_appname(); UiContext* ui_global_context(void);
--- a/ui/ui/window.h Sat Apr 15 21:06:45 2023 +0200 +++ b/ui/ui/window.h Sun Apr 16 10:20:21 2023 +0200 @@ -35,7 +35,7 @@ extern "C" { #endif -UiObject* ui_window(char *title, void *window_data); +UiObject* ui_window(const char *title, void *window_data); UiObject* ui_simplewindow(char *title, void *window_data); char* ui_openfiledialog(UiObject *obj);
--- a/ui/winui/toolkit.cpp Sat Apr 15 21:06:45 2023 +0200 +++ b/ui/winui/toolkit.cpp Sun Apr 16 10:20:21 2023 +0200 @@ -1,5 +1,134 @@ -#include "../ui/toolkit.h" +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2023 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "toolkit.h" + +#include <Windows.h> +#undef GetCurrentTime +#include <winrt/Windows.Foundation.Collections.h> +#include <winrt/Windows.UI.Xaml.Interop.h> +#include <winrt/Microsoft.UI.Xaml.Controls.h> +#include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h> +#include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h> +#include <winrt/Microsoft.UI.Xaml.Markup.h> + + +using namespace winrt; +using namespace Microsoft::UI::Xaml; +using namespace Microsoft::UI::Xaml::Controls; +using namespace Microsoft::UI::Xaml::XamlTypeInfo; +using namespace Microsoft::UI::Xaml::Markup; +using namespace Windows::UI::Xaml::Interop; + +static const char* application_name; + +static ui_callback startup_func; +static void* startup_data; + +static ui_callback open_func; +void* open_data; + +static ui_callback exit_func; +void* exit_data; + +static ui_callback appclose_fnc; + +static void* appclose_udata; + + +static UiObject* active_window; + -int testfunc() { - return 123; +class App : public ApplicationT<App, IXamlMetadataProvider> { +public: + void OnLaunched(LaunchActivatedEventArgs const&) { + Resources().MergedDictionaries().Append(XamlControlsResources()); + if (startup_func) { + startup_func(NULL, startup_data); + } + } + IXamlType GetXamlType(TypeName const& type) { + return provider.GetXamlType(type); + } + IXamlType GetXamlType(hstring const& fullname) { + return provider.GetXamlType(fullname); + } + com_array<XmlnsDefinition> GetXmlnsDefinitions() { + return provider.GetXmlnsDefinitions(); + } +private: + XamlControlsXamlMetaDataProvider provider; +}; + + + +void ui_init(const char* appname, int argc, char** argv) { + application_name = appname; +} + +const char* ui_appname() { + return application_name; +} + +UiContext* ui_global_context(void) { + return NULL; } + +void ui_context_closefunc(UiContext* ctx, ui_callback fnc, void* udata) { + +} + +void ui_onstartup(ui_callback f, void* userdata) { + startup_func = f; + startup_data = userdata; +} + +void ui_onopen(ui_callback f, void* userdata) { + open_func = f; + open_data = userdata; +} + +void ui_onexit(ui_callback f, void* userdata) { + exit_func = f; + exit_data = userdata; +} + +void ui_main() { + init_apartment(); + Application::Start([](auto&&) {make<App>(); }); +} + +void ui_show(UiObject* obj) { + UiWidget* w = (UiWidget*)obj->widget; + w->show(); +} + +void ui_close(UiObject* obj) { + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/toolkit.h Sun Apr 16 10:20:21 2023 +0200 @@ -0,0 +1,38 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2023 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#define UIEXPORT extern "C" __declspec(dllexport) +#include "../ui/toolkit.h" + + +class UiWidget { +public: + virtual void show() {}; +}; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/window.cpp Sun Apr 16 10:20:21 2023 +0200 @@ -0,0 +1,70 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2023 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "window.h" + +#include <Windows.h> +#undef GetCurrentTime +#include <winrt/Windows.Foundation.Collections.h> +#include <winrt/Windows.UI.Xaml.Interop.h> +#include <winrt/Microsoft.UI.Xaml.Controls.h> +#include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h> +#include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h> +#include <winrt/Microsoft.UI.Xaml.Markup.h> + +#include <stdlib.h> + +using namespace winrt; +using namespace Microsoft::UI::Xaml; +using namespace Microsoft::UI::Xaml::Controls; +using namespace Microsoft::UI::Xaml::XamlTypeInfo; +using namespace Microsoft::UI::Xaml::Markup; +using namespace Windows::UI::Xaml::Interop; + + +class UiWindow : UiWidget { +public: + UiWindow(const char* title) { + window = Window(); + } + + virtual void show() { + window.Activate(); + } + + Window window{ nullptr }; +}; + +UiObject* ui_window(const char* title, void* window_data) { + UiObject* obj = (UiObject*)malloc(sizeof(UiObject)); + + UiWindow* window = new UiWindow(title); + obj->widget = window; + + return obj; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/winui/window.h Sun Apr 16 10:20:21 2023 +0200 @@ -0,0 +1,44 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2023 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "toolkit.h" + +#include "../ui/window.h" + +#include <Windows.h> +#undef GetCurrentTime +#include <winrt/Windows.Foundation.Collections.h> +#include <winrt/Windows.UI.Xaml.Interop.h> +#include <winrt/Microsoft.UI.Xaml.Controls.h> +#include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h> +#include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h> +#include <winrt/Microsoft.UI.Xaml.Markup.h> + +
--- a/ui/winui/winui.vcxproj Sat Apr 15 21:06:45 2023 +0200 +++ b/ui/winui/winui.vcxproj Sun Apr 16 10:20:21 2023 +0200 @@ -27,6 +27,9 @@ <ProjectGuid>{04d5ee2c-6076-4c7c-8b70-b0f6d602ff55}</ProjectGuid> <RootNamespace>winui</RootNamespace> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained> + <WindowsPackageType>None</WindowsPackageType> + <AppxPackage>false</AppxPackage> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> @@ -136,10 +139,15 @@ </ItemDefinitionGroup> <ItemGroup> <ClCompile Include="toolkit.cpp" /> + <ClCompile Include="window.cpp" /> </ItemGroup> <ItemGroup> <None Include="packages.config" /> </ItemGroup> + <ItemGroup> + <ClInclude Include="toolkit.h" /> + <ClInclude Include="window.h" /> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> <Import Project="..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.230225.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
--- a/ui/winui/winui.vcxproj.filters Sat Apr 15 21:06:45 2023 +0200 +++ b/ui/winui/winui.vcxproj.filters Sun Apr 16 10:20:21 2023 +0200 @@ -18,8 +18,19 @@ <ClCompile Include="toolkit.cpp"> <Filter>Quelldateien</Filter> </ClCompile> + <ClCompile Include="window.cpp"> + <Filter>Quelldateien</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <None Include="packages.config" /> </ItemGroup> + <ItemGroup> + <ClInclude Include="toolkit.h"> + <Filter>Headerdateien</Filter> + </ClInclude> + <ClInclude Include="window.h"> + <Filter>Headerdateien</Filter> + </ClInclude> + </ItemGroup> </Project> \ No newline at end of file