XAML apps using C++/CX for Desktop Windows - c++

I have experimented with XAML UI programming using C++ for Windows 8 Store apps. I really like the developer experience, the XAML designer and the fact that I can get pure native apps with a modern rich user interface and high performance.
I want to create similar XAML apps using C++ for Desktop Windows (the non-Store world). How do I do this? For years I have waited for a native UI stack for Windows Desktop which is newer than MFC and somewhat higher level than direct Win32/GDI programming.

Both Silverlight and WPF use XAML along with code-behind to implement apps. Neither are still maintained but if you want to play with the same technology, it's there.
As Jeff McClintock mentioned, Microsoft has announced that a future update to Windows 8 will allow apps to run on the desktop, but I expect that this will merely be a windowing change and the apps will still run in the restricted sandbox that Store Apps run within. Maybe Microsoft will introduce yet another desktop-based UI framework and support it for three years before killing it.
WTL is newer than MFC, although its last update was six years ago. I personally recommend Qt, as it allows access to native Win32 calls (so you can do whatever ganky stuff Win32 apps normally want to do) while still having a rich, robust UI framework to build upon.

A future update to Windows 8.1 will allow Windows 8 Store Apps to run in a Window on the Desktop, and appear on the taskbar like a Win32 Application. This allows Store apps to Act a lot like Desktop Apps. MS have hinted store-app XMAL will be available to Desktop apps at some point in future.
http://www.gottabemobile.com/2014/04/02/microsoft-listens-to-users-start-menu-and-windowed-apps-are-on-the-way/

Codejock has some markup language support in MFC (native C++).
http://www.codejock.com/inc/img/downloads/samples/toolkitpro_markupsample_full.png

What I am looking at is C++/WinRT for native C++ applications that use the WinRT framework for UWP apps, at least for Windows 10. See C++/WinRT in the Microsoft Dev Center for a starting place.
C++/WinRT is an entirely standard modern C++17 language projection for
Windows Runtime (WinRT) APIs, implemented as a header-file-based
library, and designed to provide you with first-class access to the
modern Windows API. With C++/WinRT, you can author and consume Windows
Runtime APIs using any standards-compliant C++17 compiler. The Windows
SDK includes C++/WinRT; it was introduced in version 10.0.17134.0
(Windows 10, version 1803).
The intro article in the series goes on to say:
For authoring and consuming Windows Runtime APIs using C++, there is
C++/WinRT. This is Microsoft's recommended replacement for the Windows
Runtime C++ Template Library (WRL) and C++/CX.
I first got started with UWP apps for Windows 10 using C++/CX which uses the Microsoft Visual Studio C++ extensions with ref and all of the C# like extensions for C++ in a .NET world.
I am now working with Visual Studio 2017 and the C++/WinRT framework which uses native C++17 features along with an SDK. I believe you can also use C++/WinRT with Visual Studio 2015 with the latest updates, update 3.
There is also a package available from Extensions and Updates within Visual Studio, C++/WinRT, which contains a couple of Visual Studio templates for a couple of different application types.
C++/WinRT seems to be a work in progress. It seems best if you are using Visual Studio 2017 with the latest Windows 10, Version 1803, which contains the SDK and the XAML editor works fine. I have had problems with the XAML editor with an earlier build of Windows 10 Enterprise at work (IT Services maintains its own update servers and is a couple of builds behind the bleeding edge).
See also my question synchronizing SDK with Windows 10 update and using WinRT with Standard C++ which has an updated version of a test program from this article, C++ - Introducing C++/WinRT.

Related

Build UWP apps using Ninja?

Can we use ninja to build UWP apps and hence create the appx package for the same?
I don't feel there is an online article for the same. I know how to do it using VS and Make.
In theory: Yes
Notable one thing: Ninja just official support C++, I can't find any result Ninja support other programming languages
With C++ we have 2 options:
C++/CX: You should activate flag /ZW for Windows Metadata
C++/WinRT: With WinRT you just compile without any restrict, this doesn't need Windows Metadata anymore
C++/CX: we have long story behind Windows Runtime development before C++ 11/14 became official so Microsoft add their own implementation features to MSVC. So with C++/CX you can compile with very old SDK like 10240, 10586, ... and in theory it also work with Windows 8.0/8.1 SDK, Windows Phone 8.0/8.1 SDK. Another attemp try to compile UWP with C++/CX on FastBuild (system build like Ninja) is successful, you can read as a reference here: https://github.com/fastbuild/fastbuild/issues/623
C++/WinRT is reunion attempt make Windows Runtime back to standard C++ 17. C++/WinRT can also compile with Clang/GCC. Base on answer from Kenny Kerr (creator of C++/WinRT): C++/WinRT is not limit with old SDK, but he recommended to use newer SDK like 17134. Link his answer https://stackoverflow.com/a/53193711/8707331.
Some useful links for C++ UWP:
https://github.com/MicrosoftDocs/cpp-docs/blob/master/docs/porting/how-to-use-existing-cpp-code-in-a-universal-windows-platform-app.md
https://modernwindows.wordpress.com/2015/05/28/modern-c-and-clang/
you can create uwp apps in following ways:
c# and xaml
web technologies like html, css and js. and you can use any
third party js libraries with it. you can even use hosted web apps
as uwp apps or latest technologies like pwas can also be shipped as
uwp apps. more here : https://developer.microsoft.com/en-us/windows/pwa
c++ and xaml : with this approach you can use c++ libraries (if they comply by uwp platform) the reason you do not have much support online for this is because majority of uwp developers use c# and xaml approach.
There are some work around for that, and one of them is to create a Desktop app and then package that in MSIX packaging , which packages a windows Desktop app into a uwp app and you can even distribute it through Microsoft store.
CMake can't be used to generate UWP package. However, you could use make.exe or Visual Studio to generate UWP package. For more you could refer to Create an app package with the MakeAppx.exe tool and Package a UWP app with Visual Studio.

Windows forms application in VS2010 WITHOUT .NET?

I want to create more or less portable (stand-alone, no install, WinXP to Win7) Win32 forms application in Visual Studio 2010. When I create a new project, it appears that the only way I can do it is if I use .NET/CLR, which makes me think it will be very unportable.
What is the preferred way of creating such apps?
Depending on what you mean with portable. An .NET application will function on all versions of Windows that runs the correct version of .NET (even other OS'ses in some cases http://www.mono-project.com/Main_Page). You will only have a dependency of a hudge framework, that I think most people running Windows have by now.
Besides .NET you have other alternatives such as MFC or native Win32 API.
you can either use C/C++ with MFC in VS 2010 or use something different altogehter creating a "native application" like C++ Builder or Delphi.
On the other hand .NET is installed by default in Windows XP SP3 and up - at least .NET 2.0 is always available... see http://en.wikipedia.org/wiki/.NET_Framework#Versions.
You can use .NET in conjunction with a linker (example 1 and 2) if you don't mind large executable sizes.
Otherwise, C/C++ without managed extensions.

How to build Boost C++ on Windows 8 Developer Preview?

I want to use Boost C++ in a Windows 8 Metro app and I can't get the library built on Windows 8 via Visual Studio 11 in the Windows 8 Developer Preview. I believe this is due to the limited out-of-the-box functionality on VS 11 at this time.
The latest version of Boost (1.48.0) does not come with an installer.
Does anyone have a solution for this?
If the answer is build on Windows 7 and transfer, how do I accomplish this?
Boost C++ download: http://www.boost.org/users/download/
Boost C++ getting started: http://www.boost.org/doc/libs/1_48_0/more/getting_started/windows.html
A Metro library and a desktop library are different things. Metro libraries are severely restricted. You could build the library on Windows 7 and hand-install it on your system, but that would not mean you could use it on your system from a Metro app, if it made system calls that Metro does not allow.
Rather than "all of Boost" you would be best served by trying to get the pieces you need working. If you don't use Boost to work with files, what do you care that file access must now be async, and must go through APIs that ensure your Metro app has declared the right capabilities, and so on? And of course if you are using part of Boost that is in C++11, (eg shared_ptr) save yourself a lot of trouble and use the C++11 version.

Best way to create a standalone-exe (Forms) (C++)

I have to create an application for testing that is relatively simple. If a user plugs in a device into a USB (hid library), the form will say "Pass". If no device is detected, it will say "Fail".
I want to create the app to run on WinXP+. It must be a forms application as it needs to be visual and have colors. The biggest requirement for me is that it must be stand-alone (a user just double clicks, the file and it opens, no installation). I need to avoid installing any extra .dll files and want to avoid the .net framework all together. It has to be written in C++.
So my question is, what are my options? I am new to Forms applications and the only forms application I have written required the .net framework.
From my research, Visual C++ seems out of the question as it requires .net for Forms apps. What about Turbo C++ by Borland? It seems outdated, but can it do the job?
I would suggest Borland C++ Builder 5 or 6. Visual C++ lacks the functionality to create C++ form apps, if we dismiss MFC
I'd say Visual C++ would probably still be your best option. A standard simple Win32 C/C++ program using only the native API will should suite your needs just fine. If you're targeting XP+, then the only dependency would be "msvcrt.dll" which is included with Windows by default.
Edit: This article on MSDN should get you started in the right direction.
What you're talking about is C++/CLI, it's microsoft's dialect of C++ that requires a .Net framework. Please distinguish it from real (native) C++, which can be used to create what you want to. Visual C++ is perfectly fine, just make sure you don't create a .Net project.
Forms are a .NET library. It's not Windows or anything like that, you can use the native GUI libraries in Win32 with no problem or any native wrapping of them. You can implement this in native C++ easily in Visual Studio.
If you're looking to create the application in a rapid fashion (i.e. stock UI components that you can drag and drop onto forms), my experience is that Embarcardero C++ Builder effectively solves that problem space.
I like Visual C++ but it's not a great environment for rapidly creating forms based applications. I want to emphasize that I'm referring to Rapid Application Development (RAD) tools. There are plenty of great C++ IDEs and libraries for creating forms based applications and all of them should be able to create standalone exes.
Here is a list of related questions that might help in your decision:
https://stackoverflow.com/q/1754020/4916
https://stackoverflow.com/q/93326/4916
Best C++ IDE or Editor for Windows

Is it possible to program for Windows Phone 7 in standard C++ only?

I know that the recommended language for Windows Phone 7 development is C#.
However, for various reasons, I very much prefer continuing to program in standard C++, if possible.
Is it possible to program for Windows Phone 7 in standard C++ only?
If the answer is yes, what tools and resources do I need to accomplish that?
EDIT, finally: for WP7 it won't ever be, but for Windows Phone 8 - yes you can. Native apps, C/C++, iOS/Android portability and code sharing, DirectX. You'll need Visual Studio 2012 and Windows 8 for WP8 development, though. VS2010 is not getting the requisite SDK. To run the emulator, you'll need a 64-bit physical Windows 8 box with a SLAT-enabled CPU. You can still develop on a virtual machine, but you'd need a device to run apps, the emulator won't start.
The nongame UI, however, will still be XAML-based and managed. The entirety of Win32 API will not be supported. They're pushing a model with managed UI layer and a native middleware beneath it. Purely native development is still not an option; although one might try with WinMD classes as code-behind for XAML. The visual XAML designer will probably choke, and you'll need a dummy managed DLL anyway.
EDIT: even assembly, as long as it's targeting Thumb-2 and the mnemonics are UAL-style. For running on the simulator, you'd have to produce an alternative set of assembly files (or other sources) targeting Intel.
For the sake of posterity, here's the pre-06/20/2012 answer:
If you work for Microsoft or an OEM, then yes. Otherwise, no (for now).
There's hope though. Google did relent and issued their NDK after a while; Microsoft might, too. The native code capability is already there. Once they come up with a sensible sandboxing solution, why not.
Also, there's already some pressure from big-name software vendors to open up native development. Mozilla people stated outright that there will be no Firefox on WP7 unless it's native. Similar rumors about Flash.
EDIT: if you want a native SDK on WP7, like I do, please go sign the petition here and/or the one over there. Thank you!
EDIT2: see this. It's a leak and therefore not official, but still, I say there's some hope.
EDIT3: also this. Still not official, but this rumor moves the timeframe for native app support even closer - to the upcoming Tango release.
EDIT4: Microsoft seems to be pretty keen to promote WinRT, their new tablet-oriented XAML-based app platform, which allows for (among other things) unmanaged C++. Now, on every other major mobile OS the tablet and the phone app stacks are one and the same. Just sayin'.
EDIT5: there's been some proof-of-concept work along the lines of C++ => LLVM => MSIL and C++ => LLVM => C#, but nothing production-quality so far.
Phone manufacturers such as Samsung can deploy applications written in unmanaged code, but all other developers can not.
No that is not possible. Microsoft has made a decision to only allow application developers to use managed code on the Windows Phone 7 devices.
According to Wikipedia Windows Phone 7.0 runs Windows CE 6.0 R3/7.0 hybrid as operating system.
In theory one could use C++ to build standard* C++ programs targeting Windows CE 6.0 R3 and 7.0 (supposed to come out on Q1 2011). I mean all the standard* dlls should be there (gdi32.dll, user32.dll) Internet Explorer and other C++ programs are still running on Windows Phone 7.
The how to get the application on the phone? and how to run the application on the phone? are the next questions which at the moment I don't know how to answer.
This interview tells something about it: Writing the WP7 App Platform in C# and C++ I haven't watched it yet, so you might add respective comments :)
Windows Phone 7 supports Silverlight and XNA.
All programs for Windows Phone 7 are written in .NET managed code. It is also possible to write Windows Phone 7 applications in Visual Basic .NET.
Visual Studio 2010 Express for Windows Phone includes XNA Game Studio 4.0 and an on-screen phone emulator, and also integrates with Visual Studio 2010. You can develop visuals and animations for Silverlight applications using Microsoft Expression Blend.
The Silverlight and XNA platforms for Windows Phone 7 share some libraries, and you can use some XNA libraries in a Silverlight program and vice versa.
But you can’t create a program that mixes visuals from both platforms. Maybe that will be possible in the future, but not now.
EDIT:
to be more clear..there is no native C++ support you'll have to use either Silverlight or XNA,both are based on .net framework.