Changing the screen brightness on Windows via the console - windows

I am trying to write a simple console application for Windows 10 that changes the screen brightness. Ultimately, I want to use this application with AutoHotKey, but this is secondary.
In researching this, almost everything I found referred to Android, which doesn't help. I did find this Q&A about changing the screen brightness with C, but unfortunately that is for Linux.
This archived thread contains a script that (while appearing quite hacky) makes a good impression - but it
is deprecated, and on many [Systems] it will not return the full brightness settings array. So, where you should have 8 levels, IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS will only return 6, or none at all. (by jkiel, 1)
So I would prefer to use the WmiMonitorBrightness class (2 3) over IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS. It also provides a lot finer granularity, but I lack the skills to implement it correctly.
So how can I change the screen brightness on Windows 10? Possibly using the mentioned WmiMonitorBrightness class? I don't mind if it is a C application, an AutoHotKey script or something else, that I can control from console.

Looking for a solution, I found this software from 2008 which works like a charm for me on Windows 10. The developer provided the C# source and compiled application here. "You will need the Microsoft .NET Framework 2.0 or greater for the app to work."
Plus it supports the full granularity of setting brightness on your screen.
To use the console app, the following parameters are allowed:
DisplayBrightnessConsole.exe
This will return the current brightness level.
DisplayBrightnessConsole.exe -getlevels
This will return all possible brightness levels accepted by the display, separated by a new line.
DisplayBrightnessConsole.exe 20 (or some other brightness level number)
This will set the brightness level of the display to the parameter given, in this case, 20.
The code currently only works on single-display systems. If your system has more than one display, it
will only work on the first (generally primary) display. It should be fairly easy to modify it to support more.
Possibly helpful for people using python - but it doesn't help in my specific case:
How can I detect brightness changes using Python and WMI on Windows 10?

Related

Transparent window possible with integrated graphics only

I have been following the vulkan tutorial for a while now and just got to the part where I was able to create a triangle.
I wanted to get transparency working because it's a major part of my project.
I made the clear color alpha value 0.0, and started experimenting.
I spent some time bashing my head against the wall, because the validation layers kept telling me that these alpha compositing(?) flags were not supported, so I went as far as to create the windows myself (instead of with glfw, which is what I was doing).
Some time later, I noticed that the support for the flags is there, but only for my integrated graphics card:
So when using the 1050 I get the black:
But when using integrated graphics:
boom works
This was even a bit weird to me because it was working even though I was still setting the compositeAlpha to VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR. Looks like windows does the alpha blending without the need for the flags.
I did then experiment with changing it to the POST and PRE flags, but saw no difference at all.
I'm new to this so I'm at a loss as to how things may work.
One more thing is, my windows advanced display settings shows this:
And so I thought that maybe, as it's the integrated graphics that's doing the rendering of what seems to be the windows system (I'm assuming that's what "display 1" entails), it is the only adapter that has access to those framebuffers and is thus the only that's capable of doing the blending.
Am I right? Because if I am, then I must find a way to display with the driver that's doing the windows rendering, and render with the most powerful one, since it seems that windows often picks integrated graphics for it's display stuff.
And if I'm not, I'd be really glad for you to explain to me why I'm dumb :D
Thank you.

Windows API call to change console video mode?

Is there a Windows API call to change a terminal session's video mode, in a manner not dependent on INT 10H? (I specifically need to get to video mode 3 -- saving the old version of the screen, and removing scrollback, in the process, but it'd be pretty interesting if others are available as well.)
The Windows version of dos.h no longer includes the REGS union or the INTCALL macro, so I'm guessing it's deprecated in favor of some new approach.
Changing to a legacy video mode first requires support to go into full-screen mode with the console window. That support has started disappearing a long time ago. I can't quite remember the last machine I had that still allowed it but it was in the previous century.
There's a quick way to find out. Open a console window and press Alt+Enter. If nothing happens (like on a 64-bit OS) or you hear a loud beep then it won't be possible. Keep in mind that even if it does, few users still have machines where it works.
Move ahead with this by programming DirectX. Or just a GUI app, they are not hard to slam together these days.

vb6 icon location on windows

Where can I find the orginal vb6 ( or windows ) icon? (.ico files)
I need, error, warning, question, and information icons which come up on the messagebox.
Thanks a lot.
As the icons can differ for each OS version, you can get the icons from Windows using LoadIcon() passing one of the standard icon IDs.
See http://msdn.microsoft.com/en-us/library/ms648072.aspx for details.
If you want them as .ico files, you can extract them (on your development machine) from user32.dll using a resource editor.
(Updated with corrected info from Cody Gray)
The standard Windows message box icons have changed many times across the various versions of Windows. They're included with a couple of the system DLL files, but you shouldn't try and extract them dynamically yourself. As I mentioned in a comment to another answer, the ID numbers are undocumented for a reason: namely because it's possible for them to change in future versions of Windows or even in future Windows updates. There's absolutely no reason to go through the effort trying to extract them, either. Windows will already retrieve them for you, if you ask nicely.
The nice way of asking is to use the LoadIcon function, and specify the IDI identifier of the icon you want. Windows will return an HICON value, or a handle to an icon resource.
Since you mention that you're using VB.NET, you can also use the SystemIcons class, which has static properties to return any of the common icons. This is a .NET wrapper that saves you from having to P/Invoke the LoadIcon function from the Windows API yourself.
Better yet, if you just want to display a message box containing one of the icons, all you have to do is call the MessageBox API function. Tell Windows the MB_ICON value that you want, and you're off. As before, this has already been wrapped for you by the .NET Framework in the identically-named MessageBox class.
The benefit of both of these functions is that they'll always return the correct icons regardless of the current version of Windows. A comment made attempting to clarify the question seems to suggest that you want to use the old icons on a current version of Windows. But of course, you do not want to do this. The icons have been updated throughout the Windows shell for a good reason, and your application should take advantage of them. The new icons are more clear and fit in better with the overall system theme. Additionally, if your app still uses the old icons, it will be confusing to users and look very out of place. It's always best to follow standard platform conventions, rather than trying to do "something else", even if you think your "something else" is "better" for whatever reason than the platform default. Your users will not agree, and your application will reflect your shoddy craftsmanship.
Since people who ask this type of question inevitably disagree with me and insist that they must do it anyway, and that it is a "requirement" (whatever that means), I'll point out that the old icons are not available in the newer versions of Windows. The icons have been completely replaced throughout the system for a reason. It's also strictly forbidden by the licensing agreements to extract icons from system DLL files and redistribute them with your application. Don't do this.
Also, before deciding on which icon you should display in your message box, be sure to consult Microsoft's Windows User Experience Interaction Guidelines, which provide some very handy rules on selecting the proper icon to convey the right message and fit with the Windows tone. I provide more information on that in my answer here; very much recommended reading for any Windows application developer.
Edit: It's like pulling teeth to get any more details on this question. I'm not sure why you're so secretive about what you're trying to accomplish, but note that in the future, you'll have a lot better luck including these things in your question to start with, rather than hoping people will pull it out of you. Most people aren't nearly as persistent as I am.
Anyway, you finally mention that you're doing some type of interop between VB 6 code and .NET code. That should not be relevant in the case of the message box icons used. The VB 6 MsgBox function is 100% equivalent to the Win32 API MessageBox function and the .NET MessageBox class that I discussed earlier. All of them are going to use the current system icons, and it shouldn't require any extra work to make them look the same. Ensure that you've passed the same icon specifier to all of the functions. Here's a table for convenience:
VB 6 "MsgBox" Icon Constant | VB.NET "MessageBox" Icon Identifier
---------------------------------------------------------------------------------
vbCritical | MessageBoxIcon.Error
vbQuestion | MessageBoxIcon.Question (DEPRECATED -- do not use)
vbExclamation | MessageBoxIcon.Warning
vbInformation | MessageBoxIcon.Information
Note that the "Question" style icon has since been deprecated and you should not use this value. If you're still using it in the VB 6 code, you should change that code to use a different icon (or no icon at all). The above-linked Windows User Experience Interaction Guidelines provide more details on why this icon has been deprecated and how to choose a suitable replacement.

Which Windows (C++) screen capture libraries fit my requirements?

I'm ready to outsource the screen capture functionality of our application, because it's not our core business and I've spent too much time trying to get our code to do all the things I need. Time for a specialist, I think. My requirements, in decreasing order of importance, are below. Does anyone have experience with any commercial or free libraries that meet most or all of these requirements?
Has to work in Windows XP and higher. (But not Win95/98/Me.)
Visual C++ 2005 compatible, where screenshot can be triggered from my code. Preferably a static library, but a DLL or COM object is OK. I'd prefer not to shell out to a standalone EXE because there are some users that will try to tamper with our application and I think having an obvious separate screenshot EXE makes that too easy.
Must be able to take full screenshots of multiple monitor systems. (Preferably the way the "Print Screen" key does in Windows, by making a bitmap of the displays stitched together, but if I have to take the pictures separately and combine them myself that's acceptable.)
Must be able to capture screen correctly when Remote Desktop Client (or any RDP client or VM) is in full screen mode. (Of course, it should also work when RDP is in windowed mode, but that shouldn't be a problem as long as it doesn't operate by simulating a key press that might get transmitted to the remote OS instead of being handled locally.)
Must be able to capture screen correctly when Windows Media Player (or any other media player) is in full screen mode.
Must be able to capture screen correctly when game (e.g. World of Warcraft) is in full screen mode.
Would be nice to be able to capture a few seconds of user activity as a video.
I don't know of a library that would do what you want.
If I had to code your requirements, I would probably use the source code of the TightVNC server as my starting point. I think it has the technology to do everything on your list EXCEPT....
I'm not sure that technically there's ANYTHING that can do a screen capture of somebody's Remote Desktop session. Think about it: There can be multiple remote desktop sessions (the csrss.exe process) occuring using the same physical remote desktop server. If you were sitting in front of the machine looking at the video monitor, you wouldn't see anything happening at all. So what woould you expect to capture. VNC is only going to capture what's happening with the "real" video (the non-remote csrss.exe).
I dont know if this really helps, but the best imaging libraries available are available from
www.accusoft.com and
www.leadtools.com
Both support creatting screenshots, though i don't know, if hey will properly capture movie player output that displays through graphics acceleration or the recording of movies from screen.
If I were you I would investigate WindowsClippings, a pretty mature and extensible application written in C++ that does precisely what you need. It has an API you can extend to your requirements and is pretty cheap at 18$
Some people in our office are using Magick++ (an ImageMagick library) to make screenshots. I don't know all the specs, but you could take a look at it and see if it matches your requirements.

How to preserve other application windows sizes and positions when changing resolution? (eg. to and from full screen game in non-desktop resolution)

Has anyone noticed this odd behavior of application that utilize D3D or OpenGL when they go to full screen in Windows? It applies only when applications go to full screen and then switch back to window or terminate. They either shuffle window positions of other applications (when I am on single monitor machine), or move all the other applications windows to another screen when I am on multiple monitor machine.
I would take this for granted if there weren't for applications that didn't show this two anomalies. So, my question would be what exactly does one need to take care of when writing an application to alleviate these two problems? Also, I am not sure if this problem exists on other platforms besides Windows?
My primary setup concerning this is OpenGL/C++, but I presume this applies to whatever setup you have since it seems to be platform API thing that needs to be taken care of.
edit: OK, here is some more clarification on my observation. Problem persists even on same resolution as desktop one. So, it does not seem to be related to resolution switch, because I've seen application/games that even when they are not in the same resolution as desktop, when they switch back, windows on desktop are restored as they once were before the full screen application was run.
edit2: it looks like it is a resolution switch problem, Windows (at least XP) does not seem to remember positions and size (in case of multiple monitor setup) of applications windows. Looks like only solution is the one I provided in an answer to the question - even though it seems like something OS should provide, at least as an API call or two. I'm still not convinced this is the only solution, there must be an easy way of graceful, easy restoration, no?
Shouldn't you be using ChangedDisplaySettingsEx(..., CDS_FULLSCREEN, NULL)? That will tell the system the resolution swap is temporary.
I can't say that I'm 100% certain about the situation you're experiencing. However, my guess is it's because most D3D/OpenGL games will change the resolution of your machine when they startup/shutdown for performance reasons.
The ones you see that don't shuffle the windows around are likely not changing the resolution because they may be able to run at your current settings.
Hm, I've gone through some more research about this - it looks like there is no default fallback on restoring all running windows sizes and positions after changing resolution, so it must be done from within an application (at least in XP).
So, in order to gracefully return back from other resolution (full screen game for example), I would need to get all running applications hWnd's with EnumWindows and appropriate callback and store each of the windows RECT structure via GetWindowRect in a list.
When switching back to desktop resolution I would EnumWindows again, but with a different callback which sets each of the running application windows position and size with SetWindowPos, using the list of RECTs I've saved before switching to full screen.
There are gotcha's, ofcourse, like watching you get a window hwnd only through EnumWindows etc. It seems odd that OS doesn't provide a feature like that, even if only API. I wonder how other OS's out there handle this, if they handle it at all.

Resources