简体   繁体   English

在不使用XAML的情况下向标题栏添加按钮

[英]Add a button to titlebar without using XAML

I have a C++ Windows 10 app created from the MSVC template "DirectX 11 App (Universal Windows)" . 我有一个从MSVC模板“ DirectX 11 App(通用Windows)”创建的C ++ Windows 10应用程序。 At now, my app dos not have any .xaml files. 目前,我的应用程序没有任何.xaml文件。 I want to add a button to the titlebar. 我想在标题栏中添加一个按钮。 Corresponding to Windows Universal App Fullscreen Button , I have to add something like 对应于Windows Universal App全屏按钮 ,我必须添加类似

CoreApplication::GetCurrentView()->TitleBar->ExtendViewIntoTitleBar = true;
Window::Current->SetTitleBar(myTitleBar);

where myTitleBar is of class Windows::UI::Xaml::UIElement . 其中myTitleBar属于Windows::UI::Xaml::UIElement

The question is how to create that myTitleBar . 问题是如何创建myTitleBar Do I have to create a xaml that defines title bar with "Fullscreen" button (and how to integrate it)? 我是否必须创建一个通过“全屏”按钮定义标题栏的xaml(以及如何集成它)? Or maybe it is possible to do it purely in C++? 还是有可能完全用C ++做到? Or I have to recreate my app using another template "DirectX 11 and XAML App (Universal Windows)" ? 还是我必须使用另一个模板“ DirectX 11和XAML App(通用Windows)”重新创建我的应用程序?

If you want to implement your application purely by DirectX, then you will need draw the buttons and text yourself, as well as to implement some basic "collision detection" to detect if the mouse was clicked inside your button when the user presses the mouse button. 如果要仅通过DirectX来实现应用程序,则需要自己绘制按钮并输入文字,以及实现一些基本的“碰撞检测”以检测用户在按下鼠标按钮时是否在按钮内部单击了鼠标。

However, if you want to use XAML UI elements such as Titlebar and Button together with DirectX, you must interop between XAML and DirectX, which is better to start with template "DirectX 11 and XAML App (Universal Windows)". 但是,如果要与DirectX一起使用标题栏和按钮之类的XAML UI元素,则必须在XAML和DirectX之间进行互操作,最好从模板“ DirectX 11和XAML App(通用Windows)”开始。 Here you can find detailed instruction as how to implement application with both XAML and DirectX. 在这里,您可以找到有关如何同时使用XAML和DirectX实施应用程序的详细说明。

myTitleBar in defined in your xaml file. 在xaml文件中定义了myTitleBar。 You will have a grid named myTitleBar like this: 您将拥有一个名为myTitleBar的网格,如下所示:

<Grid Grid.Row="0" x:Name="myTitleBar" Height="32">
    <!--you can customize whatever you want else in this grid-->
</Grid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM