Equivalent of SetCooperativeLevel in DX 11 - directx

I am trying to figure out if SetCooperativeLevel is still available in DX11. If it is no longer supported, what is the new API to get exclusive input from input device? Thanks.

The last version of DirectInput was DirectInput8. It has not been significantly changed since then. Use of DirectInput to handle keyboard and mouse is not recommended, use the Win32 messages instead. For legacy gamepads and joysticks, you can continue to use DirectInput for Win32 desktop apps, but it is not available for Windows Store, Windows phone, or Xbox One apps.
For Xbox 360 Common Controllers on Windows, you should use XINPUT. See GamePad in DirectX Tool Kit for a nice helper for using it for gamepads.
PS: For Some details on XInput 1.4 on Windows 8.0 and later vs. XInput 1.3 on Windows 7 et all, see this post.
To handle 'input focus' you should monitor the Win32 message WM_ACTIVATEAPP. If wParam is TRUE, then you are foreground. If wParam is FALSE, then you are losing focus.

Related

Using DirectInput with XBOX One controller and window focus on Windows 10

I am trying to use DirectInput to capture XBOX One controller input signals. I am tying it to a C# WinForms application. The issue I am having is: When the form has focus, it captures inputs just fine. When the window loses focus, I don't get any feedback. On Windows 7, this isn't an issue.
I have tried other controllers on Windows 10: PS4, Logitech, Steering Wheels, etc... Everything works as expected: When the window loses focus, I still get feedback. It's just the XBOX One controller on Windows 10.
I thought maybe it had something to do with this line:
dev.SetCooperativeLevel(_ctlParent, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
But, even if I take that line out, everything still acts the same.
It seems like the XBOX One controller ignores the CooperativeLevel.Background flag and adds the CooperativeLevel.Foreground flag. Here is some more info about the flags.
Is there anyone else familiar with this issue that has figured out a work around?
Been exploring this myself regarding XBox One controllers. Each API has its own set of limitations when it comes to XBox One and XBox360 controllers.
Here's a summary of what I've learned:
Windows.Gaming.Input ref
Unlimited(?) number of controllers on Windows 10.
(Until recently I thought the limit was 8 but I've tested with 9 XBox 360/XBox One controllers so the MAX_PLAYER_NUMBER=8 found in DirectXTK is not set according to a real limit for Windows 10. ref)
Limitations:
Controllers can’t be accessed in the background...
(Not 100% sure though. I haven't gotten the controllers to work in the background myself and documentation says this limitation exists for UWP apps. ref )
Only works on UWP devices (e.g. Windows 10, XBoxOne, Windows Tablets, etc)
The Gamepad class only supports Xbox One certified or Xbox 360 compatible gamepads (ref), other gamepads can be accessed via the RawGameController class (ref).
XInput ref
API for accessing 4 XInput compatible controllers (e.g. XBox 360 or XBox One controllers)
XInput controllers can be accessed in the background.
Limitations:
Max 4 controllers.
Only XInput capable devices.
Unable to activate the extra 2 rumble motors in XBox One controller triggers. (Use Windows.Gaming.Input to do that.)
DirectInput ref
The oldest of these APIs.
Unlimited number of controllers (?)
Limitations:
XBox One controllers cannot be accessed in the background. (Bug or a feature?)
XBox 360 and XBox One controllers have triggers on the same axis, no guide button and no rumble.
Windows Store Apps can’t use DirectInput. ref
Microsoft no longer recommends using DirectInput. ref
Raw Input ref
Unlimited number of controllers (Lacking reference. Tested with 9 controllers.)
XBox One and other controllers can be accessed in the background.
(Use this source code to try it out: ref)
Limitations:
XBox 360 and XBox One controllers have triggers on the same axis, no guide button and probably no rumble. (Tested using this source code ref)
The drivers for the Xbox 360 Common Controller and the Xbox One Controller both emulate "HID" for use with the legacy DirectInput API for older games, but the emulation tends to have some quirks like this one.
Probably the best solution is to use XINPUT for these controllers and only fall back to DirectInput for legacy HID controllers. For Windows 10 DirectX 12 / UWP apps you can use Windows.Gaming.Input directly as well.
See XINPUT and Windows 8 and DirectX Tool Kit: Now with GamePads.

Delphi Chromium Embedded (TChromium) - How to mute all sounds? [duplicate]

I have an application which has sound. I have a global property to mute the sound. The problem is, there's so many different things which can make sound, I would hate to iterate through different class types and mute/unmute their sound. Instead, I'm looking for a way to mute the sound on a global application level. I don't mean muting the entire system volume either.
One scenario: In Windows 7, you can open the Volume Mixer and adjust the volume of individual applications. While I don't intend to change this actual particular value (as I know it's Windows 7 specific), I would like to change the volume of everything in my application all at once. I would also need the ability to completely mute the sound of everything in my application. I need this ability to be compatible with Windows XP and above. I am assuming it will involve Windows API calls, but I have no idea what calls to make.
XP does not support per-application volume control. That capability was added in Vista. So what you are attempting to do cannot be done in XP by fair means.
There is software called IndieVolume that retro fits per-app volume control to XP. I can only imagine it does so by means of low-level hacking, DLL injection and so on. I doubt that's really an option for you.
What you're asking for isn't possible on XP; the OS simply does not support per-application volume levels.
You can accomplish what you want by creating a settings class that keeps things like SoundActive: Boolean or PlaySounds: Boolean or something similar. Place it in it's own unit, and have an initialization section that creates an instance of it and a finalization section that frees it (making it effectively a collection of global values).
Each unit that needs access to these settings simply uses the unit containing them, and adjusts behavior accordingly. So each of your child classes or forms or whatever would just need a check added:
if CurrentSettings.PlaySounds then
// Code that makes sounds, plays music, whatever.
The settings class can also contain methods that keep track of the current volume level (on XP, the system-wide level), and methods to increase or decrease volume using the MMSystem volume functions (there are tons of examples here and through Google of doing so). Your app can then use the OnActivate and OnDeactivate events to set the volume level when your app gains focus, and restore it to the proper volume when your app loses focus.
In Vista and higher, you can use the IAudioEndPointVolume interface I mentioned earlier and either the GetMasterVolumeLevel or SetMasterVolumeLevel methods to control system wide volume (I have an example of doing this, along with the appropriate MMDevAPI interface definitions) or device level volume (using IMMDevioce.Activate to select the proper device first and then the above IAudioEndPointVolume methods on the device interface received from IMMDevice.Activate in the ppInterface parameter).
For individual applications, you use the ISimpleAudioVolume interface, which has four methods: GetMasterVolume and SetMasterVolume, which control the volume level for your application's audio session, and GetMute and SetMute to allow you to retrieve the current mute flag value or set it respectively. (Larry Osterman of MS, who was one of the developers who worked on the new audio support in Vista and Win7, has a great starting point article on his blog about the types of audio in the new API and when to use each of them.)
It's conceptually possible to determine at runtime which operating system you're using, and to programmatically switch between using the MMSystem functionality on XP and earlier, and the MMDevAPI functionality on Vista and higher. Expecting someone here to provide the code for doing so is a little unreasonable, however. The links I've provided should get you started on the right track, and when you run into snags along the way specific help in working through those snags would be great questions.

How to put a specific monitor into standby mode? [duplicate]

I have 3 monitors, but I don't need them all turned on all the time. I can just shut them down with power button, but I want to use their standby mode, like Windows does when we let PC idle for a while - it shuts down monitors, HDD, etc.
But of course, I wanna keep using PC and let just that monitor on standby. Others must remain on and that one doesn't wake up even with me using PC.
Is it possible to do that? It would be great to have a shortcut like Winkey+1, 2, 3 etc to shut down and wake up each monitor.
An existing app with this feature is not likely to exist, but is there a Windows API function that can control monitor state, for each monitor in a MultiMonitor system?
The display control panel applet calls SetDisplayConfig to start or stop forced projection on a particular target
You can probably use MS Detours or some other API hooking tool to inspect the usage pattern of the API while using the applet to adjust display settings.
You'll want to try Display Fusion. You should be able to do what you're asking for using Monitor configurations.
I know I'm late on this but use DDC to control your display. You can easily create hotkeys that send a command via DDC to the display to turn-off. This would be equivalent to turning off the display using the button. Works like a charm for me. The only trick is that DDC command specs vary across monitor manufacturers but its not hard to find the right codes to send with the help of google.
Ready made tools also exist for this; search for anything that is related to DDC or EDID and you should find.
Be aware though that this does not remove the display from Windows which means that apps may find their way onto displays that are off and you will be looking for them.

How to mute the sound of my application?

I have an application which has sound. I have a global property to mute the sound. The problem is, there's so many different things which can make sound, I would hate to iterate through different class types and mute/unmute their sound. Instead, I'm looking for a way to mute the sound on a global application level. I don't mean muting the entire system volume either.
One scenario: In Windows 7, you can open the Volume Mixer and adjust the volume of individual applications. While I don't intend to change this actual particular value (as I know it's Windows 7 specific), I would like to change the volume of everything in my application all at once. I would also need the ability to completely mute the sound of everything in my application. I need this ability to be compatible with Windows XP and above. I am assuming it will involve Windows API calls, but I have no idea what calls to make.
XP does not support per-application volume control. That capability was added in Vista. So what you are attempting to do cannot be done in XP by fair means.
There is software called IndieVolume that retro fits per-app volume control to XP. I can only imagine it does so by means of low-level hacking, DLL injection and so on. I doubt that's really an option for you.
What you're asking for isn't possible on XP; the OS simply does not support per-application volume levels.
You can accomplish what you want by creating a settings class that keeps things like SoundActive: Boolean or PlaySounds: Boolean or something similar. Place it in it's own unit, and have an initialization section that creates an instance of it and a finalization section that frees it (making it effectively a collection of global values).
Each unit that needs access to these settings simply uses the unit containing them, and adjusts behavior accordingly. So each of your child classes or forms or whatever would just need a check added:
if CurrentSettings.PlaySounds then
// Code that makes sounds, plays music, whatever.
The settings class can also contain methods that keep track of the current volume level (on XP, the system-wide level), and methods to increase or decrease volume using the MMSystem volume functions (there are tons of examples here and through Google of doing so). Your app can then use the OnActivate and OnDeactivate events to set the volume level when your app gains focus, and restore it to the proper volume when your app loses focus.
In Vista and higher, you can use the IAudioEndPointVolume interface I mentioned earlier and either the GetMasterVolumeLevel or SetMasterVolumeLevel methods to control system wide volume (I have an example of doing this, along with the appropriate MMDevAPI interface definitions) or device level volume (using IMMDevioce.Activate to select the proper device first and then the above IAudioEndPointVolume methods on the device interface received from IMMDevice.Activate in the ppInterface parameter).
For individual applications, you use the ISimpleAudioVolume interface, which has four methods: GetMasterVolume and SetMasterVolume, which control the volume level for your application's audio session, and GetMute and SetMute to allow you to retrieve the current mute flag value or set it respectively. (Larry Osterman of MS, who was one of the developers who worked on the new audio support in Vista and Win7, has a great starting point article on his blog about the types of audio in the new API and when to use each of them.)
It's conceptually possible to determine at runtime which operating system you're using, and to programmatically switch between using the MMSystem functionality on XP and earlier, and the MMDevAPI functionality on Vista and higher. Expecting someone here to provide the code for doing so is a little unreasonable, however. The links I've provided should get you started on the right track, and when you run into snags along the way specific help in working through those snags would be great questions.

Questions about Window Handles

lang: c#.net 2.0
I have a Application X, that calls SubWindows 1, 2 and 3.
I will Pop up a MessageBox, when 1, 2 or 3 is opened.
My idea is a timer that ticks every 3 seconds and checks if the windows are opened.
But how to find the 3 exact windows? Can I use a Window-Handle-Spy-Application and Hardcode the Window-Handles in my code to find them ever? Or change the window handle when the Application X is opened new?
I'm going to answer in terms of Win32 because I'm more familiar with Win32 than the .Net Framework and you can find the appropriate functions in the .Net Framework or use P/Invoke to call these Win32 functions.
I'm assuming that you know the following:
Process ID of Application X.
The name (or text) or Windows 1, 2, 3 and that these windows have uniquely identifiable text.
If you don't know the process id you need to enumerate the processes and compare each process's name to Application X and when you get a match, then you know the process id.
To find the three windows the first thing we need to do is find the top level windows with the process ID. One of these will be the ancestor of the subwindows.
Enumerate all windows using EnumWindows(); During the enumeration make a note of all windows (there may be more than one) that have the process id you are looking for.
With the list of windows matching the process id, you need to check all the descendents of each window in that list. You can do that by using EnumChildWindows(); Make sure you do all child windows of the child windows etc until there are no more. That way you'll cover every window in the process. For each window you find, compare it the known text of the subwindows you are looking for. When you get a match store that HWND somewhere you can use it.
Now that you have the HWNDs, I'm assuming you can turn them into .Net usable Windows controls.
I did a quick search, it seems that EnumWindows is not part of the .Net Framework, so you will have to use P/Invoke to do this work. It may just be easier for you to write a helper function in C/C++ that does all the searching and just passes back the HWNDs in an array - that way you only have to call one function via P/Invoke and all the work for this searching can be done in C/C++ where calling Win32 directly will be more straightforward.

Resources