I'm using WinAPI ChangeDisplaySettingsEx to switch my windows 10 screens config.
There are more than two screens, so ScreenSwitch.exe is not enough for me.
I referenced this:
https://www.codeproject.com/Articles/178027/How-to-create-a-display-switcher-for-Windows-XP?msg=3850767#xx3850767xx
and successed disable a screen in these code:
string displayName = #"\\.\DISPLAY3";
DEVMODE devMode= new DEVMODE();
devMode.dmPosition.x = 0;
devMode.dmPosition.y = 0;
devMode.dmPelsWidth = 0;
devMode.dmPelsHeight = 0;
devMode.dmFields = DEVMODE_Flags.DM_PELSHEIGHT | DEVMODE_Flags.DM_PELSWIDTH | DEVMODE_Flags.DM_POSITION;
devMode.dmSize = (ushort)Marshal.SizeOf(devMode);
ChangeDisplaySettingsEx(displayName, ref devMode, IntPtr.Zero, (int)(DeviceFlags.CDS_RESET | DeviceFlags.CDS_UPDATEREGISTRY), IntPtr.Zero);
But I can't enable screen:
...
devMode.dmPosition.x = -3840;
devMode.dmPosition.y = -1059;
devMode.dmPelsWidth = 3840;
devMode.dmPelsHeight = 2160;
...
ChangeDisplaySettingsEx got -1 result means CHANGE_FAILED
I guess that screen has disabled, so enable it need more information?
I tried save DEVMODE when the screen enabled, and send it to ChangeDisplaySettingsEx when screen disabled. Not works.
Thanks for any suggest
Thanks Strive Sun's answer.
It work.
I can't enable my "\.\DISPLAY3" directly,
My "Screen2" will be active first, although the argument is "Screen3".
But it can workaround easily, like this:
enableScreen(2);
enableScreen(3);
disableScreen(2);
I also tried use EnumDisplayDevices to get the deviceName of my monitor.
I got "\.\DISPLAY3\Monitor0".
But it will fail in ChangeDisplaySettingsEx, got -5 result (means BAD_PARAM).
Related
I'm using Microsoft.Office.Interop.Access to open access db using code like this :
Access.Application AccApp = new Access.Application();
AccApp.Visible = true;
AccApp.OpenCurrentDatabase(databasePathAndFileName, false, databasePassword);
The point is when access opens the window's size is small I need to maximize the access window after opening it .
Thanks
The VBA command for this is
DoCmd.RunCommand acCmdAppMaximize
which should be callable from C# interop as follows:
const int acCmdAppMaximize = 10;
AccApp.DoCmd.RunCommand(acCmdAppMaximize);
Obviously, you can (and should) skip the redeclaration of the acCmdAppMaximize constant if it is already provided by the interop library.
Thanks to #Heinzi who pointed me to the right direction , This worked for me :
Microsoft.Office.Interop.Access.Application AccApp = new Microsoft.Office.Interop.Access.Application();
AccApp.Visible = true;
AccApp.OpenCurrentDatabase("D:\\Settings.accdb", false, "017014A");
AccApp.RunCommand(AcCommand.acCmdAppMaximize);
Im using win32 touchinjection on windows 10 desktop.
I have been trying for two days to get pen simulation.
The code below works with PointerInputType.Touch but i need pressure and orientation, which don't seem to work.
GetLastError() returns 87 which means bad parameter but i have tried every pair of parameters i can think of.
InitializeTouchInjection();
pointer = new PointerTouchInfo();
pointer.PointerInfo.PointerId = 1;
pointer.PointerInfo.pointerType = PointerInputType.PEN;
pointer.TouchMasks = TouchMask.PRESSURE | TouchMask.ORIENTATION;
// pointer.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE;
pointer.Pressure = 1024;
pointer.Orientation = 90;
// pointer.PointerInfo.PtHimetricLocation.X = 50;
// pointer.PointerInfo.PtHimetricLocation.Y = 200;
pointer.PointerInfo.PtPixelLocation.X = 50;
pointer.PointerInfo.PtPixelLocation.Y = 200;
pointer.PointerInfo.PointerFlags = PointerFlags.INCONTACT |PointerFlags.INRANGE| PointerFlags.DOWN;
var a1=InjectTouchInput(1, new[] { pointer });
var b1 = GetLastError();
int errCode = Marshal.GetLastWin32Error();
Any information on how i could get this working or debug this further would be greatly appreciated.
There's a new InjectSyntheticPointerInput API very similar to InjectTouchInput which supports pen as well as touch. Can't help with C# or .NET but I imagine it can be exposed the same way. Only problem is it's only supported by Windows 10 1809 and above, so you'll need at least that version of the Windows SDK (which only supports Visual Studio 2017, not 2015, FYI).
I am new to SlimDX and I've heard that there is a way to capture screenshots using this library. The reason I want to use SlimDX is that I want to capture screenshots much faster than
Graphics.CopyFromScreen()
so that I can make a livestream app running at higher framerates.
I have some code I found on the internet which should capture the desktop, but it always crashes at the line where I create an instance of Device.
I tried changing the DeviceType parameter to Software and the CreateFlags to Multithreaded just to see if anything changes, but nothing did and this is what it says every time:
SlimDX.Direct3D9.Direct3D9Exception: 'D3DERR_INVALIDCALL: Invalid call (-2005530516)'
Here's the code I have:
var pp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
var d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, pp);
var surface = Surface.CreateOffscreenPlain(d, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Format.A8R8G8B8, Pool.Scratch);
d.GetFrontBufferData(0, surface);
//not sure if this will work
var ds = Surface.ToStream(surface, ImageFileFormat.Jpg);
var img = Image.FromStream(ds);
I've also read that it could be a result of BackBuffer not being supported by the graphics card, but in that case I really don't know how to fix this.
My graphics card is AMD R270X.
Any ideas?
Setting pp.BackBufferCount to 0 worked. The capture time is still pretty long though..
When I scan document via Leadtools SDK using sample code that provided by Leadtools. It show me scanning options form. I don't want to show this scanning options(form) to user.
How can I hide this and set scanning options programmatically? I have gone through leadtools documentations and example but couldn't find.
Sceenshot of sanning options is attached Scanning Options
WiaAcquireFlags flags = WiaAcquireFlags.None;
bool showProgress = true;
_progressDlg = new ProgressForm("Transferring", "", 100);
_wiaAcquiring = true;
if (_showUserInterface)
{
flags = WiaAcquireFlags.UseCommonUI | WiaAcquireFlags.ShowUserInterface;
}
else
{
if (SelectAcquireSource() != System.Windows.Forms.DialogResult.OK)
{
_wiaAcquiring = false;
return;
}
}
if (_showUserInterface && _wiaVersion == WiaVersion.Version2)
showProgress = false;
if (showProgress)
_progressDlg.Show();
_wiaSession.AcquireOptions = _wiaAcquireOptions;
_transferMode = (_wiaProperties.DataTransfer.TransferMode == WiaTransferMode.None) ? WiaTransferMode.Memory : _wiaProperties.DataTransfer.TransferMode;
According to the documentation, if you do not want to show the user interface of the scanner, you should not pass the WiaAcquireFlags for ShowUserInterface and instead use WiaAcquireFlags.None.
https://www.leadtools.com/help/leadtools/v19/dh/wa/wiaacquireflags.html
In the code you pasted above, you need to ensure that _showUserInterface is set to false.
If you want to set the properties programmatically, you can use the WiaSession.SetPropertyXXX() methods. For example, if your device (scanner) supports setting the X and Y resolution values, you can do it using code like this:
_wiaSession.SetPropertyLong(_selectedWiaItem, null, WiaPropertyId.ScannerItemXRes, 300);
_wiaSession.SetPropertyLong(_selectedWiaItem, null, WiaPropertyId.ScannerItemYRes, 300);
https://www.leadtools.com/help/leadtools/v19/dh/wa/wiasession-setpropertylong.html
I'm working with a motorolla MC55 which scans and beeps on a successful scan, I need to disable that feature so that it doesn't play any sounds at all on a scan.
Any ideas how I can accomplish this?
Scan the following barcodes to enable/disable the beep.
Try this:
Symbol.Barcode.Reader reader = new Symbol.Barcode.Reader();
// Other initialization
reader.Parameters.Feedback.Success.BeepTime = 0;
You may want to just adjust the level of the sound:
Symbol.Audio.Device MyDevice = (Symbol.Audio.Device)Symbol.StandardForms.SelectDevice.Select(
Symbol.Audio.Controller.Title,
Symbol.Audio.Device.AvailableDevices);
Symbol.Audio.StandardAudio MyAudioDevice = new Symbol.Audio.StandardAudio(MyDevice);
// set the volume of the audio from the settings file.
MyAudioDevice.BeeperVolume = NewLevel;
// set the audio device to nothing
MyAudioDevice.Dispose();
MyAudioDevice = null;
MyDevice = null;