How to detect if running inside Windows Metro application process? - c++

I am developing a library and I would like to be able to detect if it is running inside Metro style application to selectively disable/enable some functionality. Is it possible?

You can use the IMetroMode interface to check if your library has been loaded inside a Metro-style application. Call the GetMonitorMode() method, if pMode will hold MMM_METRO then you'll be sure you're running inside a Metro application.

Here is a simple test:
if (WinJS) {
// WinJS exists in global if in WinRT app
}

Related

Start a process in custom desktop with ShellExecute call

I am working on a feasibility task, where I need to start an application in a custom desktop (programmatically created desktop, using CreateDesktop()).
Scenario:
ConsoleTestApplication: Use ShellExecute() to start an MFC application, LaunchingApp
LaunchingApp: Creates a new custom desktop and start a WPF application using ShellExecute(). The WPF application should open in the custom desktop.
The above scenario works while using CreateProcess(). When I tried with ShellExecute(), the custom desktop just glitched away, and didn't work.
Does ShellExecute() work along with custom desktop creation?
Is there any possible way to solve the above scenario using ShellExecute()? Can you suggest a solution for this?
Neither ShellExecute() nor ShellExecuteEx() support launching processes on alternative desktops, only on the desktop of the calling thread.
So, you would have to either use SetThreadDesktop() before ShellExecute/Ex(), or else just use CreateProcess() instead, which supports alternative desktops, as you noted.
ShellExecute/Ex() will simply delegate to CreateProcess() when launching an EXE file, so you really should just use CreateProcess() directly. Use ShellExecute/Ex() only when launching data files (or when you need to force an EXE to launch with UAC elevation).

Calling UWP api from unmanaged DLL

Currently I have a Credential Provider implemented in C++ and I would like to incorporate BLE communication to it. This is provided in Windows 10 by the UWP class Windows.Devices.Bluetooth.GenericAttributeProfile.GattServiceProvider.
I tried to load to make a UWP DLL implementing the function and load it using LoadLibrary but got an ERROR_NOT_APPCONTAINER
Is it possible to use the UWP APIs from some unmanaged C++ code?
You can not load UWP dll inside of desktop application. However it is possible to use many UWP APIs directly as they are essentially COM-based. Typically anything not depending on application context and having public activation factory (constructor) can be used. For example see How to: Activate and Use a Windows Runtime Component Using WRL.

Embedd an external application in a widget under Qt

I was wondering either it is possible to run an external application inside a QT widget under windows operating system. For example, if I were to write a Qt gui application, where in one of the dialogs user could write some text, I could use a textbox there or something similar. But instead, would it be possible to run Notepad++ or windows notepad application in that dialog?
I would appreciate all help.
It is not really practical to do what you describe at the application level, embedding an entire process into a window of another. (It would be technically difficult and the user experience would likely be pretty bad if you could pull it off.)
Fortunately, this very problem of application components has already been solved!
So it is possible to get the end result you describe via a slightly different mechanism. Many applications expose COM interfaces for automation and embedding, and it is possible to embed COM objects within a Qt application.
(Older technologies such as DDE, OLE and ActiveX provided various aspects of this but are all basically deprecated in favour of COM AFAIK.)
Hopefully you can find a COM object from a third party, or find an app that exposes its components via COM and assemble your app that way.
Have a look at the Qt documentation:
Active Qt - ActiveX and COM support for Qt

Is it possible to send Windows Toast notifications from a c++ Windows service?

I am trying to learn how to show Toast notifications from my program which is native c++ console application registered as a windows service.
I learnt that Toasts are part of the windows runtime UI components; So does this mean I have to develop a GUI component for my product in order to be able to send Toasts?
I have developed WinToast, a library written in C++ to integrate Windows Toast Notification easily. I have used it to integrate Toast notifications in different projects, specially with Qt Framework.
The native Toast Notification needs some functions of the Com Fundamentals which are availables only in moderns version of Windows (minimum supported client: Windows 8).
That's why the library loads all the required libraries dynamically. Make your application compatible with older versions of Windows using WinToast. There is an attached example explaining how to use it in the repository.
To show a toast, just create the template and your custom handler and launch it:
WinToastHandlerExample* handler = new WinToastHandlerExample;
WinToastTemplate templ = WinToastTemplate(WinToastTemplate::ImageWithTwoLines);
templ.setImagePath(L"imagepath");
templ.setTextField(L"firstline", 0);
templ.setTextField(L"secondline", 1);
if (!WinToast::instance()->showToast(templ, handler)) {
std::wcout << L"Could not launch your toast notification!";
}
You should check this. Pure unmanaged c++ & COM.
Yes it might be possible check this link Here
Certain WinRT classes can be used from desktop apps, including portions of the Windows.UI namespace. The toast notification APIs are one such example - they can be used by both Windows Store apps and desktop apps

Launching a windowed application from a console application?

I may be approaching this in completely the wrong way as I am pretty new to the C++ language and the overall way this kind of application should be structured, but I hope to confirm the correct method here.
Essentially, I have one cpp file which operates as a console application & a separate cpp file which runs as a windowed application. I want to be able to launch the windowed application when a certain point is reached within the console application. Is this possible? If so, how would I go about doing this?
Some more detail - The console application acts as a 'server' using winsock to communicate with another console application (the client). When the console server application reaches a certain point (a client connects with it) I wish to then launch the other windowed application I have created which will render certain graphics onscreen using Directx. Currently I have both these cpp files as separate projects in a single C++ 2010 Express solution. Currently, there are no links between the two cpp files and they both operate correctly when run separately.
If any more specifics are required, I can provide them but I really want to find out if this approach in general will work.
Thanks.
If you are not running a managed C++ application, then CreateProcess is the canonical WIN32 system call to use.
Do you just want to run the exe from another exe?
System::Diagnostics::Process::Start("C:\\Folder\\file.exe");