Windows Mobile C++ - Application design-type question - c++

i have my application skeleton working as expected - it might be that somebody has a good solution to what i am trying to achieve within Windows Mobile 6.5 enviroment.
Here's what i am actually trying to do:
Application running in background ( it sends periodically network packets to office server, packets are loaded with statistics data and pushed onto the server via Winsock2 and custom made protocol ).
What 'background' means here - is an application that creates a window of 0,0 size and is minimized - i am thinking about going into the services with this, but the next thing that i require stops me today from doing this.
I need this application to be 'visible' somewhere as an icon - i already know i can't do this in the 'tray' area as stated in this post:
Windows Mobile C++ Tray Icon
Now i was trying to utilize the: SHNotificationAdd - but this is ok for a 'notification' as the name says type of thing. So it popsup and you can click to hide it - this is bad.
What i need to achieve is an icon that is visible during the application run cycle, so it flashes when there is no synchronization possible, it changes the icon when synchronization is done.
I am a bit worried it can't be done - i even tried to go and code the "Home" plug-in for this purpose, but was told that some people have themes installed and it might be that my application won't be even visible to those guys.
Now as we're going to deploy it to few places around ( 3 data centers spread across the country - around 130 people smart phones only ) - i need to be sure this application is visible even when there is a theme applied or customization done.
Any chance this can be done ?
I was kinda sure it can be done with a classic 'tray icon approach' until i found that 'tray icons' are not supported for normal applications.
If there is something i can do - i would really appreciate if somebody could shed a bit of light on this for us all please.

You'll have to move to a Windows Mobile paradigm for your app, as what you're trying to do isn't possible (as you're finding). A home screen plug in has problems if the user customizes it, and you are correct that there is no "tray". The icons in the corner (battery, signal strength, etc) are reserved for OEM use only.
My recommendation would be to actually create a visible Form for your application. Maybe it shows just some simple status info like last upload time, amount of data transferred, etc.
You then use the notifications to place a user notification during "events" such as the inability to connect (replacing your "flashing icon" idea) or when synchronization is complete (replacing your "changed icon" idea).

Related

Set audio endpoint devices application specific (programmatically)

Link to the bug report on 'Feedback Hub'
An audio endpoint device, from here on referred to as 'endpoint', is a physical or virtual audio output or input device.
With the Windows 10 April Update 1803 the long overdue 'App volume and device preferences' have been introduced. These settings allow more control over audio stream management as it is now possible to set different endpoints for different applications, no matter whether that particular application comes with an endpoint selection or not.
However, there is an issue where the audio of a program, whose endpoint is non-default, is streamed through the default endpoint (or not at all) after it has been closed and launched again, although the endpoint is displayed correctly in the settings:
As far as I know the issue can be recreated on a Windows 10 machine (version 1803 or higher) with any virtual or physical endpoint and an affected program. I used 'VLC Media Player' in this example (disregarding the fact that it comes with an endpoint selection) as it is well known and widely accessible, which should make it easier to recreate the issue.
What I'm searching for...
... is a programmatically solution to switch between endpoints, which ideally can be launched in form of a script to set the correct endpoint with an application launch.
For my purpose it would be enough to have to adjust the device instance path manually, as the device would be always the same, but I'm not going to complain about a solution which retrieves the device instance path from the registry, too.
Defined endpoints and the device instance path of the device they are using can be retrieved from the subkeys of the key HKEY_USERS\# YOUR SID #\Software\Microsoft\Multimedia\Audio\DefaultEndpoint. I don't know how windows generates the name of the subkeys or where they can be found. If I had to take a wild guess, I'd say these are Application IDs (feel free to correct me if I'm wrong).
The device instance path itself can be found in the Device Manager (under 'Audio inputs and outputs' double click the desired device, navigate to the tab 'Details' and select 'Device instance path' from the 'Property' drop-down menu).
Additionally the entry about Audio Endpoint Devices and Stream Management in the Microsoft Docs might be helpful, but that is way above my head.
A possible but impractical workaround...
... would be, to manually set another endpoint for the application and switch back to desired endpoint at every launch of said application (as shown above).
But not just takes this at least 10 seconds at each and every launch, you might even forget to do this as the audio might just get streamed through the default endpoint *¹.
The alternative to the latter is, that no audio will be streamed at all *² or in some cases it actually works *³.
*¹ e.g.: VLC Media Player, Tom Clancy's Rainbow Six Siege (although the audio will be streamed correctly during the splash screens)
*² e.g.: Call of Duty 4: Modern Warfare, Call of Duty: Modern Warfare 2, Call of Duty: Modern Warfare 3
*³ e.g.: Window Media Player, Microsoft Edge, Firefox
Observations
VLC Media Player comes with an endpoint selection, but so does TeamSpeak 3 and, unlike VLC, it skips the Windows settings completely.
Call of Duty not streaming any audio most likely is connected to the engine as I didn't encounter any other application doing something similar.
Windows Media Player, Microsoft Edge and Firefox are the only programs (I tested so far) which work fine. They have no endpoint selection (I'd know of) and will use the correct endpoint after closing and launching it again. It should be noted, however, that Firefox and Microsoft Edge will show multiple instances in the "App volume and device preferences" when adjusting the endpoint.
Disclaimer
I already tried two 3rd party softwares: 'Audio Router', which didn't work at all and 'CheVolume', which doesn't solve the issue and constantly crashes while doing so.
This question is based on one I asked over at Super User (here), where I didn't get an answer I was able to work with due to my lack of knowledge regarding actual programming (I'm only somewhat familiar with Batch and PowerShell). I'm well aware that neither Stack Overflow nor Super User are script writing services, however, the issue is not being fixed with the Windows 10 October Update 1809 and I see this as a problem which is affecting not just me and with that would be helpful for multiple people after me. Feel free to write a comment or propose an edit if you see this differently.
I'm also not sure whether the tags 'audio-streaming' and 'endpoint' should be used in this context, please propose an edit if they shouldn't or you can think of any better.
Edit - 05/11/18
Using the 3rd party software 'EarTrumpet' I was able to overcome the issue with the 'Call of Duty' games (no audio at all after restarting), however, 'VLC Media Player' would not restart after I assigned a non-default endpoint with 'EarTrumpet' until I closed 'EarTrumpet' again and the issue with 'Tom Clancy's Rainbow Six Siege' remains the same.
Edit - 18/01/19
Added link to a bug report I created on the 'Feedback Hub' 2 month ago.
Edit - 20/01/19
After doing some testing again it should be noted that having 'EarTrumpet' run in the background will keep a non-default endpoint for 'VLC Media Player' across restarts, however, 'VLC Media Player' will only (reliably) restart when the non-default endpoint was set in the 'App volume and device preferences'.
I do not have any solution regarding a programming language to handle such events.
But I can recommend EarTrumpet app to handle this change more quickly https://www.theverge.com/2018/6/13/17457778/eartrumpet-windows-10-audio-app
(Windows store: https://www.microsoft.com/en-us/p/eartrumpet/9nblggh516xp?ranMID=24542&ranEAID=nOD%2FrLJHOac&ranSiteID=nOD_rLJHOac-hUn6PgKuMKwQLdrzRqnPTA&epi=nOD_rLJHOac-hUn6PgKuMKwQLdrzRqnPTA&irgwc=1&OCID=AID681541_aff_7593_1243925&tduid=%28ir__qwqlg6jd0jba3y9hpnbvikaite2xk6kuyv9udtr100%29%287593%29%281243925%29%28nOD_rLJHOac-hUn6PgKuMKwQLdrzRqnPTA%29%28%29&irclickid=_qwqlg6jd0jba3y9hpnbvikaite2xk6kuyv9udtr100&activetab=pivot:overviewtab )
I will update the answer if I find a easy way to script/program a change of output on each app.

MUD Server and text based client

I have started to develop a simple MUD (text based multiplayer dungeon) where client uses only terminal to connect and play.
However i approached it the different way, i want the player to be able to move around the rooms (x,y) and see the map of a room like in the screenshot below
The whole screen as it is seen is being sent out by the server to the client on updates like:
somebody moved, something has changed in the current location, somebody dropped something, etc ...
At the bottom of the screen, there is a place where clients can put commands like:
look, east, west, pick up, drop, inventory, ...
Problem
The problem with the design however is, that when user is in the middle of putting a command and in meantime server has updated it's screen (somebody moved, or some event was generated ) he will loose the command he was typing because the whole screen got refreshed.
How do i send the screen to the player?
I build the view on the server side, and when sending to the client i use ANSI characters to:
Clear the screen (\u001b[H\u001b[2J)
Locate the cursor in specific areas of the window (\033[....) to draw specific areas of the view
Question
Is it possible, that clients don't loose their input when i send a view to them?
In other words, is it possible (maybe some ANSI code required?) that when i type something in the terminal and meantime if i receive something, my input is not broken by the newly received message?
To visualize the problem:
Good:
from server: aaa
from server: bbb
> input
Current:
from server: aaa
> in
from server: bbb
put
Alternative Solution
It's probably a better idea to construct the view on the Client side - then the server only needs to send the "raw information" and the client can display it. In this case, you've said the server sends a new view on events like someone moving - so just send a message to the client saying "Bob has moved", rather than an entirely new rendered screen, and let the client handle the update.
This has multiple advantages - to solve your problem, you can just buffer any server input until the user's finished typing, or redraw any bits of the screen that the client user's not actively changing.
It also allows for more customisation on the client side - if the server sends the view over, how does the client display it on a terminal that's a different resolution to the server's view? With client-side rendering, you can deal with this sort of issue on a per-client basis. You can also open up the door to massively more customisation by letting client users customise their personal views.
Workaround with your existing strategy
If you are fixed on having the server construct the views, then on the client you might be able to read single-character inputs at a time (on windows _getch, on linux ncurses provides this functionality), then if a server update occurs just render the new view and then re-render what the user's entered beforehand.
Another Suggestion
ANSI codes are... messy. Using a library like curses can make console-based-guis much nicer and more maintainable. On linux there's ncurses, and on windows there's an open-source variant called pdcurses (apparently has the same API, just exposed in an independent library. You'd need to change linker settings when compiling on Windows, but hopefully not any code). Thanks to Bartek for mentioning this.

Which trigger should I use for UWP app to be persistently in the background

I am trying to make a simple app that would work with the Corsair SDK to change the colors of my keyboard programmatically. I've developed a simple one that uses straight Win32 API that uses a notification icon to hold the process and allow me to stop it.
I'm trying to make a UWP equivalent of the application using C++ as well. The thing I am looking for is the appropriate trigger so that I can run it in the background as soon as I have it installed much like the "Mail" app that runs in the background and can create notifications (which I won't be doing yet).
Also I would like it that I don't have any forms (or at most have it integrated with Settings)
However for now, I would just like to figure out which trigger should I use?
I was thinking of SystemTrigger::userPresent and SystemTrigger::userNotPresent (to show a different lighting effects on my keyboard depending on whether the user is present or not).
The only thing different between the two modes if when the user is present, I will take in the keyboard states and read some user specific settings.

ActiveX WebBrowser control do not load countries dictionary on web-form

Good day!
First of all I want to say sorry for my pure English :)
I need to host an ActiveX WebBrowser control object on one of the forms of my application. I use ATL CAxWindow::Create(... CLSID_WebBrowser ...) and at first sight all is OK: web sites load correctly, navigating works, no any problems.
But one of the web-forms contains a list-box with countries dictionary to load from server and my WebBrowser control do not load it, therefore I cannot fill this web-form fully..
If I navigate to that web-form with IE the country dictionary loads correctly. I have several samples/examples of WebBrowser control applications (with MFC CWnd::CreateControl and other) and some of them DO NOT WORK like my application, but some - WORK CORRECTLY. I do not see any serious differences between my app and downloaded samples yet, so I need help.
P. S. I tried to change FEATURE_BROWSER_EMULATION for my application in registry (IE 7.0, IE 8.0, IE 9.0 modes), but without effect. Though, samples work without any registry tweaks.
I will try to remember how the problem was solved:
There are no miracles and WebBrowser contol object didn't work because of custom windows messages (WM_KEYDOWN, WM_KEYUP, etc) handler in host application. One simple experiment showed me that the control itself worked correctly and I started to study the host application code, where custom WM-hadlers were found.

Capturing window output in another window

I am building a C++ (Qt) based application for controlling a flash based UI. Because the flash runtime leaks spectatular amounts of memory, we execute the UI as a .swf loaded in the standalone flash player separate from the command-and-control app written i C++.
The C++ starts the flash player as an external process with appropriate parameters, and communicates with it over a TCP socket connected to localhost.
The application runs primarily on Windows XP and above.
The unfortunate side effect of running the flash player standalone is that two applications are shown in the Alt+tab list as well as in the task bar on windows (one being our application, the other being the flash player). Additionally, as the application runs full screen, flash must manage the entire screen. Allowing the C++ app to draw parts of the screen would be a massive improvement.
We would like to somehow merge the two, while leaving our own application in control. I am thinking something along the lines of Google Chrome, which appears to be running each browser tab in a separate process while displaying all output in a single window.
I've been reading up in the Win32 API (and google) in order to determine if accomplishing this is even possible. Althogh so far I've come up with dll injection as the only semi-viable solution, but I would very much like to consider that plan B.
Any suggestions would be appreciated.
The Alt+Tab list shows top-level (no parent) windows that are visible and don't have the WS_EX_TOOLWINDOW extended style. So if you have two windows from two processes but you only want to see one in the Alt-Tab list (and on the task bar), then you have a few options:
Add the WS_EX_TOOLWINDOW to one of the windows.
Re-parent one of the windows to a hidden top-level window.
Re-parent one of the windows (probably the Flash player) to the other window. This is tricky, but it's probably how Chrome and many other multi-process single-window apps work. What makes it tricky is handling the lifetimes of the windows and inadvertently serializing the message queues.
I guess this question and its answers are related to your question:
Embedding Flash Player in a C++ or Java application?
DLL injection won't get you anywhere, the memory would still be allocated in your main process if you're instantiating the flash player as an in-process server.
If you want to keep control over the memory leaks you have to keep the flash player in a seperate process.
Your current approach sounds viable, your only problem seems to be that the process is still visible in something like the Alt+Tab list... as far as i recall, setting the extended window style to WS_EX_TOOLWINDOW should help you with that.
For hiding the process from the taskbar see e.g. here.