Programmatically listing all supported locales in Windows 10 - c#

Windows 10 supports custom locales, locales that do not have an LCID like older locales from older versions of Windows. In each update to Windows 10, Microsoft has been adding lesser used locales for minority and indigenous languages.
A recent update to Windows 10 added the the Võro kiil (vro) locale. When using EnumSystemLocalesEx to enumerate all supported locales, vro does not appear in any form. However, in the system settings UI for adding a new language or keyboard, Võro kiil does appear.
However, if the user then enables this language, when you call EnumSystemLocalesEx, vro, vro-Latn and vro-Latn-001 are now listed. If the user then removes this locale from the UI, it no longer appears in the results of this function call.
The question: is there a way (supported or otherwise) to get a list of all the known locales to the operating system regardless of whether the user has enabled them or not?
I find it very bizarre that this output includes other minority languages like Skolt Sami without requiring the user to enable it in advance.
I will quite happily accept an answer that uses the .NET framework if the API does not exist in the C/C++ APIs, so long as I can actually get this data.
Example code to generate the locale output:
#include <cstdio>
#include "stdafx.h"
#include "windows.h"
BOOL CALLBACK Callback(LPWSTR pStr, DWORD dwFlags, LPARAM lparam)
{
wprintf(L"%ls\n", pStr);
return TRUE;
}
int main()
{
EnumSystemLocalesEx(Callback, 0, 0, 0);
return 0;
}
With Võro kiil enabled from the "Region and Language" screen in System Settings, the final three results are vro-Latn, vro-Latn-001 and vro. When not enabled, they do not appear in the output at all.
Using .NET APIs seems to have the same behaviour.
#include "stdafx.h"
using namespace System;
using namespace System::Globalization;
int main()
{
System::Collections::IEnumerator^ enum0 = CultureInfo::GetCultures(CultureTypes::AllCultures)->GetEnumerator();
while (enum0->MoveNext())
{
CultureInfo^ ci = safe_cast<CultureInfo^>(enum0->Current);
Console::WriteLine("{0}", ci->Name);
}
}

In effect, the new language model for Windows means that there is no "list" beyond those that have historical LCIDs.
The Windows 8.1 and 10 settings tools link to bcp47langs.dll and winlangdb.dll, which provide functions for enabling languages and input methods so long as the provided input is a valid ISO 639-3 language code.
In some cases, if you want your language to appear in the UI or via these APIs, you must provide at least the script and sometimes the region. An example is myv-Cyrl for the Erzya language.
Using these APIs
Using an MSIL disassembler on a cmdlet bundled with PowerShell, I found a p/invoke definition that has allowed me to successfully use these APIs from C# and Rust code.
Here it is, for posterity:
// Decompiled with JetBrains decompiler
// Type: Microsoft.InternationalSettings.Commands.LPAPIWrapper
// Assembly: Microsoft.InternationalSettings.Commands, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// MVID: E0B49792-544F-4FBD-8C35-D4DA177385AF
// Assembly location: C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.InternationalSettings.Commands\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.InternationalSettings.Commands.dll
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace Microsoft.InternationalSettings.Commands
{
internal class LPAPIWrapper
{
public static uint GEO_NATION = 1;
public static uint GEO_FRIENDLYNAME = 8;
public static uint GEOCLASS_NATION = 16;
public static uint GEOCLASS_REGION = 14;
[DllImport("kernelbase.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int NlsUpdateLocale(string LocaleName, int Flags);
[DllImport("intl.cpl", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int IntlUpdateSystemLocale(string LocaleName, int dwFlags);
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int SystemParametersInfo(
uint Action,
uint UnsignedParam,
IntPtr Param,
uint WinIni);
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int SendNotifyMessage(
IntPtr wWwnd,
uint Msg,
IntPtr wParam,
string lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetSystemDefaultLocaleName(
StringBuilder LocaleName,
int LocaleNameSize);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetUserGeoID(uint GeoClass);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int SetUserGeoID(int GeoId);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetGeoInfo(
int Location,
uint GeoType,
StringBuilder GeoData,
int Length,
ushort LangID);
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetUserLanguages(char Delimiter, [MarshalAs(UnmanagedType.HString)] ref string UserLanguages);
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetUserLanguageInputMethods(
string Language,
char Delimiter,
[MarshalAs(UnmanagedType.HString)] ref string InputMethods);
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int LcidFromBcp47([MarshalAs(UnmanagedType.HString)] string LanguageTag, ref int Lcid);
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetPendingUserDisplayLanguage([MarshalAs(UnmanagedType.HString)] ref string language);
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetUserDisplayLanguageOverride([MarshalAs(UnmanagedType.HString)] ref string language);
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int SetUserDisplayLanguageOverride(string LanguageTag);
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int ClearUserDisplayLanguageOverride();
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetHttpAcceptLanguageOptOut(ref bool IsOptOut);
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int SetHttpAcceptLanguageOptOut();
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int ClearHttpAcceptLanguageOptOut();
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetUserLocaleFromLanguageProfileOptOut(ref bool IsOptOut);
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int SetUserLocaleFromLanguageProfileOptOut();
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int ClearUserLocaleFromLanguageProfileOptOut();
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int RemoveInputsForAllLanguagesInternal();
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int SetInputMethodOverride(string TipString);
[DllImport("bcp47langs.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int Bcp47GetIsoLanguageCode([MarshalAs(UnmanagedType.HString)] string languageTag, [MarshalAs(UnmanagedType.HString)] ref string isoLanguageCode);
[DllImport("ext-ms-win-globalization-input-l1-1-2.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int WGIGetDefaultInputMethodForLanguage(
[MarshalAs(UnmanagedType.HString)] string Language,
[MarshalAs(UnmanagedType.HString)] ref string DefaultTipString);
[DllImport("ext-ms-win-globalization-input-l1-1-2.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int WGITransformInputMethodsForLanguage(
[MarshalAs(UnmanagedType.HString)] string TipString,
[MarshalAs(UnmanagedType.HString)] string Language,
[MarshalAs(UnmanagedType.HString)] ref string TransformedTipString);
[DllImport("winlangdb.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int SetUserLanguages(char Delimiter, [MarshalAs(UnmanagedType.HString)] string UserLanguages);
[DllImport("winlangdb.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetLanguageNames(
string Language,
StringBuilder Autonym,
StringBuilder EnglishName,
StringBuilder LocalName,
StringBuilder ScriptName);
[DllImport("ext-ms-win-globalization-input-l1-1-2.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int WGIIsImeInputMethod([MarshalAs(UnmanagedType.HString)] string TipString, ref int result);
[DllImport("winlangdb.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int EnsureLanguageProfileExists();
[DllImport("input.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int InstallLayoutOrTip(string TipString, int Flags);
[DllImport("input.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int SetDefaultLayoutOrTip(string TipString, int Flags);
[DllImport("input.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetLayoutDescription(
string LayoutId,
StringBuilder LayoutDescription,
ref int DescriptionLength);
private LPAPIWrapper()
{
}
}
}

Related

c# unmanaged PInvoke AccessViolation

I have C++ DLL.
When call method from this DLL in C# AccessViolation was been throwing.
What in my code is wrong? Can someone help me?
C++ Header part:
typedef PVOID X_HANDLE;
XREADER_API BOOL ReaderOpen(X_HANDLE *pxHandle);
XREADER_API BOOL ReaderReceiveW26(X_HANDLE xHandle, LPVOID pBuffer, DWORD nBufferSize);
Working Example part C++:
X_HANDLE hReader;
unsigned char xKeyBuffer[3];
ReaderOpen(&hReader);
ReaderReceiveW26(hReader,xKeyBuffer,sizeof(xKeyBuffer));
My C# Code:
[DllImport("reader.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
public static extern bool ReaderOpen(IntPtr reference);
[DllImport("reader.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
public static extern bool ReaderReceiveW26(IntPtr hReader, IntPtr pBuffer, uint xKeyBuffer);
static void Main(string[] args)
{
byte[] received = new byte[3];
IntPtr unmanagedPointer = Marshal.AllocHGlobal(received.Length);
Marshal.Copy(received, 0, unmanagedPointer, received.Length);
IntPtr hReader = Marshal.AllocHGlobal(sizeof(uint));
var qqq = uint.Parse((Marshal.SizeOf(typeof(byte)) * received.Length).ToString());
ReaderOpen(hReader);
while (true)
{
if (ReaderReceiveW26(hReader, unmanagedPointer, qqq))
{
Console.WriteLine("!");
}
}
}
AccessViolation throwing at ReaderReceiveW26(hReader, unmanagedPointer, qqq)
Thanks for your patience!
Thanks to Hast Passant comment!
If we want use IntPtr or smth which edited by unmanaged code we need use
out paramName
For PVOID we can pass real c# type.
Working example:
[DllImport("reader.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
public static extern bool ReaderOpen(out IntPtr reference);
[DllImport("reader.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
public static extern bool ReaderReceiveW26(IntPtr hReader, byte[] pBuffer, uint xKeyBuffer);

How to use esc/pos command with c#?

How to use ESC/POS command with C#? I need format like this
but I cannot achieve this format.
I tried some codes ,but no use.
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
// Reset the printer bws (NV images are not cleared)
bw.Write(AsciiControlChars.Escape);
bw.Write('#');
bw.Write(AsciiControlChars.Newline);
bw.Write(AsciiControlChars.Escape);
bw.Write("_______________________________________________");
bw.Write(AsciiControlChars.Newline);
bw.Write("Service Price Qty Total");
bw.Write("------------------------------------------------");
bw.Write(AsciiControlChars.GroupSeparator);
bw.Write('V');
bw.Write((byte)66);
bw.Write((byte)3);
bw.Flush();
// Send the converted ANSI string to the printer.
}
You can check this link. I now using that and It's Works!!
http://www.codeproject.com/Tips/704989/Print-Direct-To-Windows-Printer-EPOS-Receipt
Use with careful, you must know ESC/POS command for thermal printer. If I'm not mistaken, the manual command must exit on the CD that came with the printer.
Kind Regards
Bonus:
http://www.developerfusion.com/tools/convert/vb-to-csharp/
I know that this is not exactly an answer to the question of how to use escape codes, but it would be much better to create a PDF file (P for Portable). You'll have a better chance to have it rendered exactly as intended on most printers.
You can generate a PDF with PDFsharp. It's open source and free and it's quite simple to use.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace Apteka.Printer
{
public class RawPrinterHelper
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class DOCINFOA
{
[MarshalAs(UnmanagedType.LPStr)]
public string pDocName;
[MarshalAs(UnmanagedType.LPStr)]
public string pOutputFile;
[MarshalAs(UnmanagedType.LPStr)]
public string pDataType;
}
[DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, ref IntPtr hPrinter, IntPtr pd);
[DllImport("winspool.Drv", EntryPoint = "ClosePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool ClosePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "StartDocPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool StartDocPrinter(IntPtr hPrinter, Int32 level, [In()][MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di);
[DllImport("winspool.Drv", EntryPoint = "EndDocPrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool EndDocPrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "StartPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool StartPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "EndPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool EndPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, ref Int32 dwWritten);
private IntPtr hPrinter = new IntPtr(0);
private DOCINFOA di = new DOCINFOA();
private bool PrinterOpen = false;
public bool PrinterIsOpen
{
get
{
return PrinterOpen;
}
}
public bool OpenPrint(string szPrinterName)
{
if (PrinterOpen == false)
{
di.pDocName = ".NET RAW Document";
di.pDataType = "RAW";
if (OpenPrinter(szPrinterName.Normalize(), ref hPrinter, IntPtr.Zero))
{
if (StartDocPrinter(hPrinter, 1, di))
{
if (StartPagePrinter(hPrinter))
PrinterOpen = true;
}
}
}
return PrinterOpen;
}
public void ClosePrint()
{
if (PrinterOpen)
{
EndPagePrinter(hPrinter);
EndDocPrinter(hPrinter);
ClosePrinter(hPrinter);
PrinterOpen = false;
}
}
public bool SendStringToPrinter(string szPrinterName, string szString)
{
if (PrinterOpen)
{
IntPtr pBytes;
Int32 dwCount;
Int32 dwWritten = 0;
dwCount = szString.Length;
pBytes = Marshal.StringToCoTaskMemAnsi(szString);
var res= WritePrinter(hPrinter, pBytes, dwCount, ref dwWritten);
Marshal.FreeCoTaskMem(pBytes);
return res;
}
else
return false;
}
}
}
I was working on thermal printer and I came across to ESC/POS commands like you do.After Googling I found ThermalDotNet very useful for me.This class also supports image printing as well as letter printing.
I hope this helps ;)

How can I get a list of processes running across multiple virtual desktops?

I am working on Window 7 and I have multiple desktops by using the Sysinternals Desktops utility. I just want to list all the processes running across all the desktops.
Process[] processlist = Process.GetProcesses();
foreach (Process p in processlist)
{
listBox1.Items.Add(p.ProcessName + " " + p.Id + " " + p.MainWindowTitle);
}
With this code I am able to get all the processes running on the current desktop, but I am not able to get the processes running inside different desktops.
Only Desktops is showing as a single process.
How can I get the child processes inside multiple desktops?
Yup i got it.. after doing RnD.
I am using user32.dll and some of these methods.
If you also want to achieve some thing use these functions.
[DllImport("user32.dll", EntryPoint = "EnumDesktopWindows", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDelegate lpEnumCallbackFunction, IntPtr lParam);
[DllImport("user32.dll", EntryPoint = "GetWindowText", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
private static extern int _GetWindowText(IntPtr hWnd, StringBuilder lpWindowText, int nMaxCount);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool EnumDesktops(IntPtr hwinsta, EnumDesktopProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SetActiveWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = false)]
private static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
private static extern IntPtr GetProcessWindowStation();
[DllImport("user32.dll")]
private static extern IntPtr OpenDesktop(string lpszDesktop, uint dwFlags, bool fInherit, uint dwDesiredAccess);
[DllImport("user32.dll")]
private static extern bool SwitchDesktop(IntPtr hDesktop);
By using these methods I am able to list down all the running processes on all the virtual desktop.

WinCE registry value monitor

Evening all,
I need some advice on monitoring a registry value in WinCE. I am writing a Windows Forms application which needs to monitor a value in registry, and fire an event when it changes, can anyone point me in the right direction as to how to accomplish this?
Many thanks in advance.
I managed to implement this using PInvoke code:
[DllImport("coredll.dll", SetLastError = true)]
static extern int RegOpenKeyEx(UIntPtr hKey, string lpSubKey, uint ulOptions, int samDesired, out UIntPtr phkResult);
[DllImport("coredll.dll", SetLastError = true)]
static extern UIntPtr CeFindFirstRegChange(UIntPtr hKey, [In, MarshalAs(UnmanagedType.Bool)] bool bWatchSubtree, uint dwNotifyFilter);
[DllImport("coredll.dll", SetLastError = true)]
public static extern UInt32 WaitForSingleObject(UIntPtr Handle, UInt32 Wait);
[DllImport("coredll.dll", SetLastError = true)]
static extern Int32 CeFindNextRegChange(UIntPtr hChangeHandle);
[DllImport("coredll.dll", SetLastError = true)]
static extern Int32 CeFindCloseRegChange(UIntPtr hChangeHandle);
[DllImport("coredll.dll", SetLastError = true)]
public static extern int RegCloseKey(UIntPtr hKey);
and by using WaitForSingleObject.

HDMI TV sometimes not detected in windows 7? Possible to invoke Detect in code?

i have a standalone public kiosk pc that startups automatically everyday. It is connected to a HD TV and sometimes it is not detected. i have to personally go down to the PC, go to Screen Resolution and press Detect which it works.
my question is how do i know if the monitor i want it to display is connected properly in code?
thanks
I did manage to find some code on the MSDN site where a user is using code to determine which type of monitor is connected. I hope this may be a good starting point for you.
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace CRT
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public class NativeMethods
{
[DllImport("user32.dll", EntryPoint = "MonitorFromWindow", SetLastError = true)]
public static extern IntPtr MonitorFromWindow(
[In] IntPtr hwnd, uint dwFlags);
[DllImport("dxva2.dll", EntryPoint = "GetNumberOfPhysicalMonitorsFromHMONITOR", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetNumberOfPhysicalMonitorsFromHMONITOR(
IntPtr hMonitor, ref uint pdwNumberOfPhysicalMonitors);
[DllImport("dxva2.dll", EntryPoint = "GetPhysicalMonitorsFromHMONITOR", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetPhysicalMonitorsFromHMONITOR(
IntPtr hMonitor,
uint dwPhysicalMonitorArraySize,
[Out] NativeStructures.PHYSICAL_MONITOR[] pPhysicalMonitorArray);
[DllImport("dxva2.dll", EntryPoint = "DestroyPhysicalMonitors", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DestroyPhysicalMonitors(
uint dwPhysicalMonitorArraySize, [Out] NativeStructures.PHYSICAL_MONITOR[] pPhysicalMonitorArray);
[DllImport("dxva2.dll", EntryPoint = "GetMonitorTechnologyType", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetMonitorTechnologyType(
IntPtr hMonitor, ref NativeStructures.MC_DISPLAY_TECHNOLOGY_TYPE pdtyDisplayTechnologyType);
[DllImport("dxva2.dll", EntryPoint = "GetMonitorCapabilities", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetMonitorCapabilities(
IntPtr hMonitor, ref uint pdwMonitorCapabilities, ref uint pdwSupportedColorTemperatures);
}
public class NativeConstants
{
public const int MONITOR_DEFAULTTOPRIMARY = 1;
public const int MONITOR_DEFAULTTONEAREST = 2;
public const int MONITOR_DEFAULTTONULL = 0;
}
public class NativeStructures
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct PHYSICAL_MONITOR
{
public IntPtr hPhysicalMonitor;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string szPhysicalMonitorDescription;
}
public enum MC_DISPLAY_TECHNOLOGY_TYPE
{
MC_SHADOW_MASK_CATHODE_RAY_TUBE,
MC_APERTURE_GRILL_CATHODE_RAY_TUBE,
MC_THIN_FILM_TRANSISTOR,
MC_LIQUID_CRYSTAL_ON_SILICON,
MC_PLASMA,
MC_ORGANIC_LIGHT_EMITTING_DIODE,
MC_ELECTROLUMINESCENT,
MC_MICROELECTROMECHANICAL,
MC_FIELD_EMISSION_DEVICE,
}
}
public Window1() { InitializeComponent(); }
private void Button_Click(object sender, RoutedEventArgs e)
{
WindowInteropHelper helper = new WindowInteropHelper(this);
IntPtr hMonitor = NativeMethods.MonitorFromWindow(helper.Handle, NativeConstants.MONITOR_DEFAULTTOPRIMARY);
int lastWin32Error = Marshal.GetLastWin32Error();
uint pdwNumberOfPhysicalMonitors = 0u;
bool numberOfPhysicalMonitorsFromHmonitor = NativeMethods.GetNumberOfPhysicalMonitorsFromHMONITOR(
hMonitor, ref pdwNumberOfPhysicalMonitors);
lastWin32Error = Marshal.GetLastWin32Error();
NativeStructures.PHYSICAL_MONITOR[] pPhysicalMonitorArray =
new NativeStructures.PHYSICAL_MONITOR[pdwNumberOfPhysicalMonitors];
bool physicalMonitorsFromHmonitor = NativeMethods.GetPhysicalMonitorsFromHMONITOR(
hMonitor, pdwNumberOfPhysicalMonitors, pPhysicalMonitorArray);
lastWin32Error = Marshal.GetLastWin32Error();
uint pdwMonitorCapabilities = 0u;
uint pdwSupportedColorTemperatures = 0u;
var monitorCapabilities = NativeMethods.GetMonitorCapabilities(
pPhysicalMonitorArray[0].hPhysicalMonitor, ref pdwMonitorCapabilities, ref pdwSupportedColorTemperatures);
lastWin32Error = Marshal.GetLastWin32Error();
NativeStructures.MC_DISPLAY_TECHNOLOGY_TYPE type =
NativeStructures.MC_DISPLAY_TECHNOLOGY_TYPE.MC_SHADOW_MASK_CATHODE_RAY_TUBE;
var monitorTechnologyType = NativeMethods.GetMonitorTechnologyType(
pPhysicalMonitorArray[0].hPhysicalMonitor, ref type);
lastWin32Error = Marshal.GetLastWin32Error();
var destroyPhysicalMonitors = NativeMethods.DestroyPhysicalMonitors(
pdwNumberOfPhysicalMonitors, pPhysicalMonitorArray);
lastWin32Error = Marshal.GetLastWin32Error();
this.lbl.Content = type;
}
}
}

Categories