WinAPI function that chages the Display Settings to Duplicate - c++

I am attempting to change the display settings to "Duplicate" when I have 2 monitors connected to a PC?
Ie, I am attempting to select the following setting(outlined in red) but using a WinAPI function call.
My Problem: I dont know what WinAPI function call I use to change the display setting to "Duplicate"? I've googled and haven't found any such function.
I am looking for a function that is supported on Windows 2000 or XP and up and not just a Windows Vista and up function. Does anyone know what WinAPI function call I use to achieve this?

I believe you want to use ChangeDisplaySettingsEx. You set up DEVMODE structures for both monitors, with the dmPosition member set to (0, 0), and set (only) the DM_POSITION flag, so all you do is change their relative positions, not things like resolution or bit depth.
This is supposed to work back as far as Windows 2000.

i THINK U WILL GET THE ANSWER OF YOU QUESTION LINK BELOW
http://www.c-sharpcorner.com/uploadfile/GemingLeader/changing-display-settings-programmatically/

Related

How to set upper-left corner window icon in glut?

I searched a lot to find a method to set the icon of a window created using the glut framework (even if would be better to say that I use freeGLUT), but I could find only ways that use WinAPI, while I would use a cross-platform solution.
I tried to use GLUT_ICON, but that 's available for Windows only (I work on Linux) and I tried also glutSetIconTitle() function on both Windows and Linux without results (first passing to the function the file 's path, like glutSetIconTitle("icon.ico"), and then passing the file data as an array, like glutSetIconTitle(file_data)). Can someone help me?

How to get font metrics for the system clock in the Windows Explorer notification area? [duplicate]

System's tray area clock visual theme is documented in MSDN, so I suppose Microsoft expects us to be able to use it. I'd like to use it to draw my taskbar band's background, in order to blend better with the tray area. When I try to
OpenThemeData(NULL, L"CLOCK");
It always fails. The only way I found to get that theme, is locate the actual clock window, and to request its theme:
Use FindWindowEx to locate a window with Shell_TrayWnd class, then locate its child with class TrayNotifyWnd, then this window's child with TrayClockWClass class.
Call OpenThemeData and pass the actual clock's window handle.
Obviously, internal Windows window class names are undocumented. Although the method above seems to work, I'd rather use something less fragile.
Question: Is there any sane way to get tray area's clock visual theme?
Apparently you can't always use OpenThemeData with NULL
http://microsoft.public.platformsdk.shell.narkive.com/gkVTBGA2/cannot-open-theme-data-for-tray-notification-area
Jim Barry 6 years ago
You need to have an HWND that you can call SetWindowTheme for. Set
pszSubAppName to "TrayNotifyHoriz" or "TrayNotifyVert" and leave
pszSubIdList as NULL. You can then call OpenThemeData with
pszClassList set to "TrayNotify".
How anyone is supposed to figure this stuff out is totally beyond me.
The visual styles documentation is quite frankly abysmal, an absolute
disgrace.
-- Jim Barry, MVP (Windows SDK)

How can I hide the mouse cursor?

I wanna ask if someone can provide me a c++ code in which I can hide/show the pointer of the mouse when pressing a specific key..
I found several codes written for only TURBO C++, none of which can be compiled and run using dev c++ or even visual c++..
I tried running the codes I found in Dev C++ but I only get lots of errors and incompatibilities..
I also found several articles that says I can use the function ShowCursor but it just wouldn't work..
In fact hiding the cursor can turn out to be quite a task, depending on what you want to achive. If you're programming a GUI-application using the WinAPI it is pretty easy.
Just calling ShowCursor(false); once might turn out not to work in some cases though, since the ShowCursor function only "sets an internal display counter". The cursor is displayed until this counter is smaller than 0 (see msdn on it). You could try something like this:
while(ShowCursor(false)>=0);
to ensure the counter gets below 0.
This will however only hide the cursor inside your applications window, if you're using newer Windows versions like Windows 7. Hiding the cursor all over the system could turn out to be a lot more difficult.
If you are programming a console application ShowCursor won't show any effect as far as I've tested it. Using the following code:
while(ShowCursor(false)>=0);
std::cout<<ShowCursor(false)<<std::endl;
std::cout<<ShowCursor(true)<<std::endl;
we can see, that the counter definitely is below 0, but still the cursor is displayed. I haven't come up with a solution to this so far.
If you look at the documentation for the SetCursor function, setting the cursor to a NULL handle (e.g SetCursor(NULL)) will remove the cursor from the screen.

How do I keep an OpenCV namedWindow with a HWND handle on top of all other windows in Windows 8?

The title pretty much says it all. I've created a window with namedWindow() and filled it with a matrix. I then assign it to a HWND using cvGetWindowHandle() so that I can use the Windows function SetWindowPos(). Using this I'm supposed to be able to set the flags HWND_TOPMOST, SWP_NOMOVE and SWP_NOSIZE in order to keep it above all other windows even when I click on a window behind it.
I've either misread something here and got the wrong idea or I believe that the problem might be the fact that I have upgraded to Windows 8 and they have deprecated this function or something. Is there another way to go about this?
I don't have a setup to try this in c++, but I wanted to do something similar in python so I ended up using a python win32 library. With a combination of the following calls (I assume you can find them for win32 in c++), I always managed to get the screen on top. But it didn't stay there. I had to bring it up when I wanted it.
win32gui.SetForegroundWindow(hwnd) # I use just this. apparently it can trigger permission error but I never had a problem with it
win32gui.SetFocus(hwnd) # apparently doesn't trigger error without permission like setforegroundwindow
win32gui.BringWindowToTop(hwnd) # not sure if this helps any
win32gui.SetActiveWindow(hwnd) #not sure if this helps any

DeferWindowPos and SWP_SHOWWINDOW/SWP_HIDEWINDOW

I am writing a virtual desktop application which utilises the DeferWindowPos API functions. The current method I am using is moving the windows off the screen if they're not on the current virtual desktop. However I know wish to also hide the windows that are off-screen so they do not appear on the task bar. I have attempted this by also passing SWP_SHOWWINDOW/SWP_HIDEWINDOW to the DeferWindowPos() calls. I have read a few sites regarding this and one of them suggested that if SWP_SHOWWINDOW/SWP_HIDEWINDOW are passed, then the window will only show or hide, and no reposition. Can anyone confirm this, or am I doing something wrong?
In addition to the rtfm, DeferWindowPos is eventually going to call SetWindowPos. SetWindowPos always validates its parameters by passing them to the WindowProc via WM_WINDOWPOSCHANGING so, unless you are also hooking every windows WindowProc as part of your virtual desktop manager, moving them off screen is going to fail for any windows where the devs are doing something "clever" or unusual - like clamping to the edge of the workspace.
You need to read the documentation, which clearly states
If any of the windows in the multiple-window- position structure have the SWP_HIDEWINDOW or SWP_SHOWWINDOW flag set, none of the windows are repositioned.
I, too, noticed this statement in the documentation:
If any of the windows in the multiple-window- position structure have the SWP_HIDEWINDOW or SWP_SHOWWINDOW flag set, none of the windows are repositioned.
...after I'd already rewritten some code to use DWP, so I thought I'd try running it. It worked just fine even though I'd used either SWP_SHOWWINDOW or SWP_HIDEWINDOW for every single call to DWP.
This was on Windows 7 64-bit, so YMMV.