Detecting screen monitor Power State change in c++ - winapi

I have a Windows message loop. I need to detect when the screen powers back up. Is there a windows message?
detect power state change contains the C# way, I need the C++ way, using win32 API.
If there isn't a Windows message, how do I poll for screen monitor power state?

There is a Windows message WM_POWERBROADCAST. There Windows API has a lot of support for power management. See the section on Windows Power Management at MSDN for the details.

For newer windows versions (starting with windows 8) you should use GUID_CONSOLE_DISPLAY_STATE instead of GUID_MONITOR_POWER_ON

Related

Is there a way to turn on Bluetooth using winapi?

I'm looking for a way to turn on my computer's Bluetooth using the Windows API only. I didn't see any function in BluetoothApis.h for this. If you know any way (maybe using the Device API), I would love to hear it!
This is the setting I want to turn on using the Windows API:
I don't know about Win32 API, but it can be done easily via Windows Runtime API Windows.Devices.Radios. The RadioState enum can be set to On, Off or Disabled.
A UWP example is here.
For Win32 apps it is still possible to access the Windows Runtime API, for example by compiling with VC++ /ZM flag ("Consume Windows Runtime Extension") and invoking Windows::Foundation::Initialize(); on startup, as explained in the Microsoft's blog: How to access the Windows 10 APIs from C++.

Does windows CE 7.0 has same API and functionality with normal windows system programming?

I Want to know if Windows CE 7.0 has same API and functionality with normal Windows system programming.
For example, i have to deal with serial(RS-232), TCP/IP, select() and so on in Windows CE 7.0.
Can i use all of API same as normal Windows?
Or there are some Difference between them ?
The API are similar, but you should expect some differences.
For example serial port drivers may not support asynchronous read/writes. This is supported in the OS (since ver 7.0), but I have seen no drivers actually using it.
Also socket API is similar but, as you know, evil hides in details.
As a general rule you can't take for granted that software running on Windows desktop (or "normal" if you prefer :)) will just need a rebuild to run on CE.
It will need at least a rebuild (and sometimes this may be clumsy if you are using different releases of Visual Studio).

Monitor process resources on Windows CE 5.0

I'm developing a WinCE 5.0 application that uses two commercial libraries. When the application starts calling the second library it gets slowlier and then after some use, it hangs and the whole OS freezes. It has to be rebooted to work again. The thing is that I'm developing this without a physical device (a testing person installs each release and runs the tests) and without an emulator (the device provider is not facilitating an OS image).
My intuition tells me that the second library is using all the available resources (basically, handles and memory) for a WinCE 5.0 process. I have to prove this to the library vendor. So I wish to add to my logs some general process and system information. Could you recommend me which APIs to call to get this information in CE?
I would really appreciate any hint
Thanks in advance!
Windows CE provides a very robust set of APIs for a subsystem called CeLog. CeLog is what Kernel Tracker uses to collect and display it's information. You can get all the way down to scheduler calls and thread migrations if you want. The real danger with using CeLog is in collecting too much data so that making sense of it is difficult, but if you filter the collections to just your process, that should help. You could collect the data to a log file, then use Kernel Tracker to open and view that data.
Here are some good starting points for info:
Introduction to Remote Kernel Tracker
More on Remote Kernel Tracker
CeLogFlush.exe (particularly the section 'Collecting Data on a Standalone Device with CeLogFlush')
Implementing a Custom Event Tracking Library
Embedded Visual C++ 4 contained "Remote Performance Monitor" that could do just that. Microsoft retracted EVC4 as free download some time ago, but it can still be downloaded from MSDN or found on the internet.
With service pack 4 it should work for WinCE 5.0. It does not appear to work with Windows Embedded 6.0 and newer though.

Developing power consumption aware applications

Firstly, please don't move to serverfault. It is indeed a programming question :-)
We are developing occasionally connected applications. These applications reside on laptop and handhelds. In my case, the application runs on a small servlet container (like jetty).
The requirement is that if the system is idle, the application should suspend itself.
If the lid of the laptop is closed, then the application and the servlet container are in a suspend mode.
Are such things a feature of the OS itself or can such power awareness be built into the application? If it can be built into the application, how ?
Every OS provides a set of APIs and notifications you can use and subscribe to appropriately. Windows, for example, sends a WM_POWERBROADCAST message to all windows before an power event happens. Read on it more in Power Management section at MSDN.
However you want the power-aware features in a java application, which will require you to use some sort of a JNI bridge. There's a codeproject article on detecting standby and denying the request (although denying power transitions is not possible in Windows Vista/7 any more).

How to emulate/replace/re-enable classical Sound Mixer controls (or commands) in Windows Vista?

I have a problem (and have been having it for some time now) -- the new sound mixer stack in Vista features new cool things, but also re-invents the wheel. Many applications that used to use Volume Mixer on a Windows system to mix different voiced outputs into one input (for example Wave-out + Line-in --> Stereo Mix) have since stopped working. The prime example of this behavior is the Shoutcast DSP plugin (could be useful for solution testing).
How Can I re-enable XP-mixer controls, or maybe emulate this behavior somehow, so that the program (SC DSP) can properly manage Microphone/Line-In playback volume along with Wave-out playback volume?
My thinking would be to emulate a program hooked-in into the Vista Mixer for Wave-Out and Line-out (or Mic speaker volume -- all playback, shown as separate adjustable "programs" so that the Vista Mixer could refer to it) and 'hook' it into the system under some emulation representing itself as the old volume mixer control interface for the program, but I frankly have no idea how to do that.
To clarify: this is not my PC (it is a HP Pavilion laptop). The problem seems to exist mostly due to the fact that Vista mixer controls separate programs, not separate inputs/outputs. The hardware is fully capable of doing what is needed when using Windows XP. I am well aware of the fact that this is a driver issue, but the driver is simply prepared for what Vista presents to the programmer through interfaces. The mixer device - as seen in the operating system, however it might look in software - is based on the mixer APIs for Windows Audio control.
Search using Google on Vista and line-in playback volume control for more info on the problem (and the sheer amount of users affected by it). Of course, a re-write of the Shoutcast Source DSP plug-in for WinAMP would do the trick, but that is not likely to happen...
Controlling the volume levels of a soundcards indivudual input/output levels in Windows Vista mixer is possible using the audio EndPoint API
This should allow you to adjust the main volume, and the volume of and connected audio inputs. One wrinkle about this that when you enumerate the end points, if there isn't a microphone plugged into your soundcard, then nothing will be enumerated. This means you'll need to change your application to respond to "microphone plugged in" events, and notify the user appropriately.
Another option is to dip below the Microsoft Core Audio and access the WaveRT driver directly. This is a lot more work than using the WASAPI/Endpoint APIs, but will give you the most control over access to the inputs/outputs of the soundcard.
The audio driver controls which mixer controls are available, and this will depend largely on the capabilities of the hardware.
If the Vista driver doesn't have certain controls, then it's likely to be a shortcoming of that driver and not of Vista.
(Please tell us which sound card/device you are using.)
It would be possible to write a program to create your own mixer controls (this would be a software-only driver for a virtual sound card), but this program wouldn't be able to affect the audio routing inside the device if the actual driver doesn't have some mixer control for this.
If you mark your app as running in Windows XP compatibility, then all the old controls and behaviors will come back.
If you mark your app as running in Windows XP compatibility, then all the old controls and behaviors will come back.
This is true, but as of Vista SP1 patch KB957388, included in SP2, and with some soundcard drivers, the old mixer API (winmm.dll) functions can hang when the app is in XP compatibility mode. In particular, mixerGetNumDevs and less often mixerOpen will not return on some computers.
I've got reports from 5 Vista users out of around 200 Vista users in total where my app hangs when starting up, and I have tracked it down to these functions hanging.
I would like to report this to Microsoft but cannot find anywhere to do so.
All I can do now is release my software without compatibility mode enabled, but this loses functionality in my app, and the software cannot control the line-in or microphone mixers.
I don't have time to work with low level API functions directly. I rely on high level components, and I cannot find any for the new audio API's for my development system (Delphi).
I would be interested in paying someone to write a DLL for me!!!
e mail ross att stationplaylist dott com

Resources