microsoft/TypeAgent

Public

mirrored fromhttps://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
e41f2419e507de4f652d438c799efcaab3deca61

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

dotnet/autoShell/AutoShell_Win32.cs

595lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using System;
5using System.Collections.Generic;
6using System.Linq;
7using System.Runtime.InteropServices;
8using System.Text;
9using System.Threading.Tasks;
10using System.Windows;
11
12namespace autoShell
13{
14 internal unsafe partial class AutoShell
15 {
16 private const int SPI_SETDESKWALLPAPER = 20;
17 private const int SPIF_UPDATEINIFILE = 0x01;
18 private const int SPIF_SENDCHANGE = 0x02;
19 private const uint LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
20
21 // Text scaling constants
22 private const uint WM_SETTINGCHANGE = 0x001A;
23 private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);
24
25 // window rect structure
26 internal struct RECT
27 {
28 public int Left; // x position of upper-left corner
29 public int Top; // y position of upper-left corner
30 public int Right; // x position of lower-right corner
31 public int Bottom; // y position of lower-right corner
32 }
33
34 internal struct Size
35 {
36 public int x;
37 public int y;
38 }
39
40 // import GetWindowRect
41 [DllImport("user32.dll")]
42 static extern bool GetWindowRect(IntPtr hWnd, ref RECT Rect);
43
44 // import GetShellWindow
45 [DllImport("user32.dll")]
46 static extern IntPtr GetShellWindow();
47
48 // import GetDesktopWindow
49 [DllImport("user32.dll")]
50 static extern IntPtr GetDesktopWindow();
51
52 // import SetForegroundWindow
53 [System.Runtime.InteropServices.DllImport("user32.dll")]
54 private static extern bool SetForegroundWindow(IntPtr hWnd);
55
56 [DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true)]
57 static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, UInt32 wParam, IntPtr lParam);
58
59 [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
60 static extern IntPtr SendMessageTimeout(
61 IntPtr hWnd,
62 uint Msg,
63 IntPtr wParam,
64 string lParam,
65 uint fuFlags,
66 uint uTimeout,
67 out IntPtr lpdwResult);
68
69 // import SetWindowPos
70 [DllImport("user32.dll")]
71 static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
72
73 // import ShowWindow
74 [DllImport("user32.dll")]
75 static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
76
77 // import FindWindowEx
78 [DllImport("user32.dll")]
79 internal static extern IntPtr FindWindowEx(IntPtr hWndParent, IntPtr hWndChildAfter, string lpClassName, string lpWindowName);
80
81 [DllImport("user32.dll", CharSet = CharSet.Auto)]
82 private static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
83
84 [System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError = true)]
85 private static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile, uint dwFlags);
86
87 [System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError = true)]
88 private static extern bool FreeLibrary(IntPtr hModule);
89
90 [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
91 private static extern int LoadString(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax);
92
93 #region Virtual Desktop APIs
94
95 public enum APPLICATION_VIEW_CLOAK_TYPE : int
96 {
97 AVCT_NONE = 0,
98 AVCT_DEFAULT = 1,
99 AVCT_VIRTUAL_DESKTOP = 2
100 }
101
102 public enum APPLICATION_VIEW_COMPATIBILITY_POLICY : int
103 {
104 AVCP_NONE = 0,
105 AVCP_SMALL_SCREEN = 1,
106 AVCP_TABLET_SMALL_SCREEN = 2,
107 AVCP_VERY_SMALL_SCREEN = 3,
108 AVCP_HIGH_SCALE_FACTOR = 4
109 }
110
111 // Virtual Desktop COM Interface GUIDs
112 public static readonly Guid CLSID_ImmersiveShell = new Guid("C2F03A33-21F5-47FA-B4BB-156362A2F239");
113 public static readonly Guid CLSID_VirtualDesktopManagerInternal = new Guid("C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B");
114 public static readonly Guid CLSID_VirtualDesktopManager = new Guid("AA509086-5CA9-4C25-8F95-589D3C07B48A");
115 public static readonly Guid CLSID_VirtualDesktopPinnedApps = new Guid("B5A399E7-1C87-46B8-88E9-FC5747B171BD");
116
117 // IServiceProvider COM Interface
118 [ComImport]
119 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
120 [Guid("6D5140C1-7436-11CE-8034-00AA006009FA")]
121 private interface IServiceProvider
122 {
123 [return: MarshalAs(UnmanagedType.IUnknown)]
124 void QueryService(ref Guid guidService, ref Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObject);
125 }
126
127 // IVirtualDesktopManager COM Interface
128 [ComImport]
129 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
130 [Guid("A5CD92FF-29BE-454C-8D04-D82879FB3F1B")]
131 internal interface IVirtualDesktopManager
132 {
133 bool IsWindowOnCurrentVirtualDesktop(IntPtr topLevelWindow);
134 Guid GetWindowDesktopId(IntPtr topLevelWindow);
135 void MoveWindowToDesktop(IntPtr topLevelWindow, ref Guid desktopId);
136 }
137
138 // IVirtualDesktop COM Interface (Windows 10/11)
139 [ComImport]
140 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
141 [Guid("3F07F4BE-B107-441A-AF0F-39D82529072C")]
142 internal interface IVirtualDesktop
143 {
144 bool IsViewVisible(IApplicationView view);
145 Guid GetId();
146 // TODO: proper HSTRING custom marshaling
147 [return: MarshalAs(UnmanagedType.HString)]
148 string GetName();
149 [return: MarshalAs(UnmanagedType.HString)]
150 string GetWallpaperPath();
151 bool IsRemote();
152 }
153
154 // IVirtualDesktopManagerInternal COM Interface
155 [ComImport]
156 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
157 [Guid("53F5CA0B-158F-4124-900C-057158060B27")]
158 internal interface IVirtualDesktopManagerInternal_BUGBUG
159 {
160 int GetCount();
161 void MoveViewToDesktop(IApplicationView view, IVirtualDesktop desktop);
162 bool CanViewMoveDesktops(IApplicationView view);
163 IVirtualDesktop GetCurrentDesktop();
164 void GetDesktops(out IObjectArray desktops);
165 [PreserveSig]
166 int GetAdjacentDesktop(IVirtualDesktop from, int direction, out IVirtualDesktop desktop);
167 void SwitchDesktop(IVirtualDesktop desktop);
168 IVirtualDesktop CreateDesktop();
169 void MoveDesktop(IVirtualDesktop desktop, int nIndex);
170 void RemoveDesktop(IVirtualDesktop desktop, IVirtualDesktop fallback);
171 IVirtualDesktop FindDesktop(ref Guid desktopid);
172 void GetDesktopSwitchIncludeExcludeViews(IVirtualDesktop desktop, out IObjectArray unknown1, out IObjectArray unknown2);
173 void SetDesktopName(IVirtualDesktop desktop, [MarshalAs(UnmanagedType.HString)] string name);
174 void SetDesktopWallpaper(IVirtualDesktop desktop, [MarshalAs(UnmanagedType.HString)] string path);
175 void UpdateWallpaperPathForAllDesktops([MarshalAs(UnmanagedType.HString)] string path);
176 void CopyDesktopState(IApplicationView pView0, IApplicationView pView1);
177 void CreateRemoteDesktop([MarshalAs(UnmanagedType.HString)] string path, out IVirtualDesktop desktop);
178 void SwitchRemoteDesktop(IVirtualDesktop desktop, IntPtr switchtype);
179 void SwitchDesktopWithAnimation(IVirtualDesktop desktop);
180 void GetLastActiveDesktop(out IVirtualDesktop desktop);
181 void WaitForAnimationToComplete();
182 }
183
184 // IVirtualDesktopManagerInternal COM Interface
185 [ComImport]
186 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
187 [Guid("53F5CA0B-158F-4124-900C-057158060B27")]
188 internal interface IVirtualDesktopManagerInternal
189 {
190 int GetCount();
191 void MoveViewToDesktop(IApplicationView view, IVirtualDesktop desktop);
192 bool CanViewMoveDesktops(IApplicationView view);
193 IVirtualDesktop GetCurrentDesktop();
194 void GetDesktops(out IObjectArray desktops);
195 [PreserveSig]
196 int GetAdjacentDesktop(IVirtualDesktop from, int direction, out IVirtualDesktop desktop);
197 void SwitchDesktop(IVirtualDesktop desktop);
198 void SwitchDesktopAndMoveForegroundView(IVirtualDesktop desktop);
199 IVirtualDesktop CreateDesktop();
200 void MoveDesktop(IVirtualDesktop desktop, int nIndex);
201 void RemoveDesktop(IVirtualDesktop desktop, IVirtualDesktop fallback);
202 IVirtualDesktop FindDesktop(ref Guid desktopid);
203 void GetDesktopSwitchIncludeExcludeViews(IVirtualDesktop desktop, out IObjectArray unknown1, out IObjectArray unknown2);
204 void SetDesktopName(IVirtualDesktop desktop, [MarshalAs(UnmanagedType.HString)] string name);
205 void SetDesktopWallpaper(IVirtualDesktop desktop, [MarshalAs(UnmanagedType.HString)] string path);
206 void UpdateWallpaperPathForAllDesktops([MarshalAs(UnmanagedType.HString)] string path);
207 void CopyDesktopState(IApplicationView pView0, IApplicationView pView1);
208 void CreateRemoteDesktop([MarshalAs(UnmanagedType.HString)] string path, out IVirtualDesktop desktop);
209 void SwitchRemoteDesktop(IVirtualDesktop desktop, IntPtr switchtype);
210 void SwitchDesktopWithAnimation(IVirtualDesktop desktop);
211 void GetLastActiveDesktop(out IVirtualDesktop desktop);
212 void WaitForAnimationToComplete();
213 }
214
215 // IObjectArray COM Interface
216 [ComImport]
217 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
218 [Guid("92CA9DCD-5622-4BBA-A805-5E9F541BD8C9")]
219 internal interface IObjectArray
220 {
221 void GetCount(out int pcObjects);
222 void GetAt(int uiIndex, ref Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv);
223 }
224
225 [ComImport]
226 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
227 [Guid("372E1D3B-38D3-42E4-A15B-8AB2B178F513")]
228 internal interface IApplicationView
229 {
230 int SetFocus();
231 int SwitchTo();
232 int TryInvokeBack(IntPtr /* IAsyncCallback* */ callback);
233 int GetThumbnailWindow(out IntPtr hwnd);
234 int GetMonitor(out IntPtr /* IImmersiveMonitor */ immersiveMonitor);
235 int GetVisibility(out int visibility);
236 int SetCloak(APPLICATION_VIEW_CLOAK_TYPE cloakType, int unknown);
237 int GetPosition(ref Guid guid /* GUID for IApplicationViewPosition */, out IntPtr /* IApplicationViewPosition** */ position);
238 int SetPosition(ref IntPtr /* IApplicationViewPosition* */ position);
239 int InsertAfterWindow(IntPtr hwnd);
240 int GetExtendedFramePosition(out Rect rect);
241 int GetAppUserModelId([MarshalAs(UnmanagedType.LPWStr)] out string id);
242 int SetAppUserModelId(string id);
243 int IsEqualByAppUserModelId(string id, out int result);
244 int GetViewState(out uint state);
245 int SetViewState(uint state);
246 int GetNeediness(out int neediness);
247 int GetLastActivationTimestamp(out ulong timestamp);
248 int SetLastActivationTimestamp(ulong timestamp);
249 int GetVirtualDesktopId(out Guid guid);
250 int SetVirtualDesktopId(ref Guid guid);
251 int GetShowInSwitchers(out int flag);
252 int SetShowInSwitchers(int flag);
253 int GetScaleFactor(out int factor);
254 int CanReceiveInput(out bool canReceiveInput);
255 int GetCompatibilityPolicyType(out APPLICATION_VIEW_COMPATIBILITY_POLICY flags);
256 int SetCompatibilityPolicyType(APPLICATION_VIEW_COMPATIBILITY_POLICY flags);
257 int GetSizeConstraints(IntPtr /* IImmersiveMonitor* */ monitor, out Size size1, out Size size2);
258 int GetSizeConstraintsForDpi(uint uint1, out Size size1, out Size size2);
259 int SetSizeConstraintsForDpi(ref uint uint1, ref Size size1, ref Size size2);
260 int OnMinSizePreferencesUpdated(IntPtr hwnd);
261 int ApplyOperation(IntPtr /* IApplicationViewOperation* */ operation);
262 int IsTray(out bool isTray);
263 int IsInHighZOrderBand(out bool isInHighZOrderBand);
264 int IsSplashScreenPresented(out bool isSplashScreenPresented);
265 int Flash();
266 int GetRootSwitchableOwner(out IApplicationView rootSwitchableOwner);
267 int EnumerateOwnershipTree(out IObjectArray ownershipTree);
268 int GetEnterpriseId([MarshalAs(UnmanagedType.LPWStr)] out string enterpriseId);
269 int IsMirrored(out bool isMirrored);
270 int Unknown1(out int unknown);
271 int Unknown2(out int unknown);
272 int Unknown3(out int unknown);
273 int Unknown4(out int unknown);
274 int Unknown5(out int unknown);
275 int Unknown6(int unknown);
276 int Unknown7();
277 int Unknown8(out int unknown);
278 int Unknown9(int unknown);
279 int Unknown10(int unknownX, int unknownY);
280 int Unknown11(int unknown);
281 int Unknown12(out Size size1);
282 }
283
284 [ComImport]
285 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
286 [Guid("1841C6D7-4F9D-42C0-AF41-8747538F10E5")]
287 internal interface IApplicationViewCollection
288 {
289 int GetViews(out IObjectArray array);
290 int GetViewsByZOrder(out IObjectArray array);
291 int GetViewsByAppUserModelId(string id, out IObjectArray array);
292 int GetViewForHwnd(IntPtr hwnd, out IApplicationView view);
293 int GetViewForApplication(object application, out IApplicationView view);
294 int GetViewForAppUserModelId(string id, out IApplicationView view);
295 int GetViewInFocus(out IntPtr view);
296 int Unknown1(out IntPtr view);
297 void RefreshCollection();
298 int RegisterForApplicationViewChanges(object listener, out int cookie);
299 int UnregisterForApplicationViewChanges(int cookie);
300 }
301
302 [ComImport]
303 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
304 [Guid("4CE81583-1E4C-4632-A621-07A53543148F")]
305 internal interface IVirtualDesktopPinnedApps
306 {
307 bool IsAppIdPinned(string appId);
308 void PinAppID(string appId);
309 void UnpinAppID(string appId);
310 bool IsViewPinned(IApplicationView applicationView);
311 void PinView(IApplicationView applicationView);
312 void UnpinView(IApplicationView applicationView);
313 }
314
315 [ComImport]
316 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
317 [Guid("6D5140C1-7436-11CE-8034-00AA006009FA")]
318 internal interface IServiceProvider10
319 {
320 [return: MarshalAs(UnmanagedType.IUnknown)]
321 object QueryService(ref Guid service, ref Guid riid);
322 }
323
324 #endregion Virtual Desktop APIs
325
326 [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
327 private static extern IntPtr GetCommandLineW();
328
329
330 #region Window Functions
331
332 // Delegate for EnumWindows callback
333 internal delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
334
335 [DllImport("user32.dll")]
336 [return: MarshalAs(UnmanagedType.Bool)]
337 static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
338
339 [DllImport("user32.dll", CharSet = CharSet.Unicode)]
340 internal static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
341
342 [DllImport("user32.dll")]
343 [return: MarshalAs(UnmanagedType.Bool)]
344 static extern bool IsWindowVisible(IntPtr hWnd);
345
346 [DllImport("user32.dll")]
347 static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
348
349 // get handle of active window
350 [DllImport("user32.dll")]
351 private static extern IntPtr GetForegroundWindow();
352
353 #endregion Window Functions
354
355 [DllImport("shell32.dll", CharSet = CharSet.Unicode)]
356 private static extern IntPtr ShellExecute(
357 IntPtr hwnd,
358 string lpOperation,
359 string lpFile,
360 string lpParameters,
361 string lpDirectory,
362 int nShowCmd);
363
364
365 [DllImport("combase.dll")]
366 internal static extern int WindowsCreateString(char* sourceString, int length, out IntPtr hstring);
367
368 [DllImport("combase.dll")]
369 internal static extern int WindowsDeleteString(IntPtr hstring);
370
371 [DllImport("combase.dll")]
372 internal static extern char* WindowsGetStringRawBuffer(IntPtr hstring, out uint length);
373
374 // Add these COM interface definitions for Radio Management API
375
376 // GUIDs for Radio Management API
377 internal static readonly Guid CLSID_RadioManagementAPI = new Guid(0x581333f6, 0x28db, 0x41be, 0xbc, 0x7a, 0xff, 0x20, 0x1f, 0x12, 0xf3, 0xf6);
378 internal static readonly Guid IID_IRadioManager = new Guid(0xdb3afbfb, 0x08e6, 0x46c6, 0xaa, 0x70, 0xbf, 0x9a, 0x34, 0xc3, 0x0a, 0xb7);
379
380 [ComImport]
381 [Guid("db3afbfb-08e6-46c6-aa70-bf9a34c30ab7")]
382 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
383 internal interface IRadioManager
384 {
385 [PreserveSig]
386 int IsRMSupported(out uint pdwState);
387
388 [PreserveSig]
389 int GetUIRadioInstances([MarshalAs(UnmanagedType.IUnknown)] out object ppCollection);
390
391 [PreserveSig]
392 int GetSystemRadioState(out int pbEnabled, out int param2, out int pChangeReason);
393
394 [PreserveSig]
395 int SetSystemRadioState(int bEnabled);
396
397 [PreserveSig]
398 int Refresh();
399
400 [PreserveSig]
401 int OnHardwareSliderChange(int param1, int param2);
402 }
403
404 #region WiFi
405
406 // WLAN API P/Invoke declarations
407 [DllImport("wlanapi.dll")]
408 static extern int WlanOpenHandle(uint dwClientVersion, IntPtr pReserved, out uint pdwNegotiatedVersion, out IntPtr phClientHandle);
409
410 [DllImport("wlanapi.dll")]
411 static extern int WlanCloseHandle(IntPtr hClientHandle, IntPtr pReserved);
412
413 [DllImport("wlanapi.dll")]
414 static extern int WlanEnumInterfaces(IntPtr hClientHandle, IntPtr pReserved, out IntPtr ppInterfaceList);
415
416 [DllImport("wlanapi.dll")]
417 static extern int WlanGetAvailableNetworkList(IntPtr hClientHandle, ref Guid pInterfaceGuid, uint dwFlags, IntPtr pReserved, out IntPtr ppAvailableNetworkList);
418
419 [DllImport("wlanapi.dll")]
420 static extern int WlanScan(IntPtr hClientHandle, ref Guid pInterfaceGuid, IntPtr pDot11Ssid, IntPtr pIeData, IntPtr pReserved);
421
422 [DllImport("wlanapi.dll")]
423 static extern void WlanFreeMemory(IntPtr pMemory);
424
425 [DllImport("wlanapi.dll")]
426 static extern int WlanConnect(IntPtr hClientHandle, ref Guid pInterfaceGuid, ref WLAN_CONNECTION_PARAMETERS pConnectionParameters, IntPtr pReserved);
427
428 [DllImport("wlanapi.dll")]
429 static extern int WlanDisconnect(IntPtr hClientHandle, ref Guid pInterfaceGuid, IntPtr pReserved);
430
431 [DllImport("wlanapi.dll")]
432 static extern int WlanSetProfile(IntPtr hClientHandle, ref Guid pInterfaceGuid, uint dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string strProfileXml, [MarshalAs(UnmanagedType.LPWStr)] string strAllUserProfileSecurity, bool bOverwrite, IntPtr pReserved, out uint pdwReasonCode);
433
434 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
435 struct WLAN_INTERFACE_INFO
436 {
437 public Guid InterfaceGuid;
438 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
439 public string strInterfaceDescription;
440 public int isState;
441 }
442
443 [StructLayout(LayoutKind.Sequential)]
444 struct WLAN_INTERFACE_INFO_LIST
445 {
446 public uint dwNumberOfItems;
447 public uint dwIndex;
448 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
449 public WLAN_INTERFACE_INFO[] InterfaceInfo;
450 }
451
452 [StructLayout(LayoutKind.Sequential)]
453 struct DOT11_SSID
454 {
455 public uint SSIDLength;
456 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
457 public byte[] SSID;
458 }
459
460 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
461 struct WLAN_AVAILABLE_NETWORK
462 {
463 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
464 public string strProfileName;
465 public DOT11_SSID dot11Ssid;
466 public int dot11BssType;
467 public uint uNumberOfBssids;
468 public bool bNetworkConnectable;
469 public uint wlanNotConnectableReason;
470 public uint uNumberOfPhyTypes;
471 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
472 public int[] dot11PhyTypes;
473 public bool bMorePhyTypes;
474 public uint wlanSignalQuality;
475 public bool bSecurityEnabled;
476 public int dot11DefaultAuthAlgorithm;
477 public int dot11DefaultCipherAlgorithm;
478 public uint dwFlags;
479 public uint dwReserved;
480 }
481
482 [StructLayout(LayoutKind.Sequential)]
483 struct WLAN_AVAILABLE_NETWORK_LIST
484 {
485 public uint dwNumberOfItems;
486 public uint dwIndex;
487 }
488
489 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
490 struct WLAN_CONNECTION_PARAMETERS
491 {
492 public WLAN_CONNECTION_MODE wlanConnectionMode;
493 [MarshalAs(UnmanagedType.LPWStr)]
494 public string strProfile;
495 public IntPtr pDot11Ssid;
496 public IntPtr pDesiredBssidList;
497 public DOT11_BSS_TYPE dot11BssType;
498 public uint dwFlags;
499 }
500
501 enum WLAN_CONNECTION_MODE
502 {
503 wlan_connection_mode_profile = 0,
504 wlan_connection_mode_temporary_profile = 1,
505 wlan_connection_mode_discovery_secure = 2,
506 wlan_connection_mode_discovery_unsecure = 3,
507 wlan_connection_mode_auto = 4
508 }
509
510 enum DOT11_BSS_TYPE
511 {
512 dot11_BSS_type_infrastructure = 1,
513 dot11_BSS_type_independent = 2,
514 dot11_BSS_type_any = 3
515 }
516
517 #endregion WiFi
518
519 #region Display Resolution
520
521 private const int ENUM_CURRENT_SETTINGS = -1;
522 private const int ENUM_REGISTRY_SETTINGS = -2;
523 private const int DISP_CHANGE_SUCCESSFUL = 0;
524 private const int DISP_CHANGE_RESTART = 1;
525 private const int DISP_CHANGE_FAILED = -1;
526 private const int DISP_CHANGE_BADMODE = -2;
527 private const int DISP_CHANGE_NOTUPDATED = -3;
528 private const int DISP_CHANGE_BADFLAGS = -4;
529 private const int DISP_CHANGE_BADPARAM = -5;
530 private const int DISP_CHANGE_BADDUALVIEW = -6;
531
532 private const int DM_PELSWIDTH = 0x80000;
533 private const int DM_PELSHEIGHT = 0x100000;
534 private const int DM_BITSPERPEL = 0x40000;
535 private const int DM_DISPLAYFREQUENCY = 0x400000;
536
537 private const int CDS_UPDATEREGISTRY = 0x01;
538 private const int CDS_TEST = 0x02;
539 private const int CDS_FULLSCREEN = 0x04;
540 private const int CDS_GLOBAL = 0x08;
541 private const int CDS_SET_PRIMARY = 0x10;
542 private const int CDS_RESET = 0x40000000;
543
544 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
545 internal struct DEVMODE
546 {
547 private const int CCHDEVICENAME = 32;
548 private const int CCHFORMNAME = 32;
549
550 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)]
551 public string dmDeviceName;
552 public ushort dmSpecVersion;
553 public ushort dmDriverVersion;
554 public ushort dmSize;
555 public ushort dmDriverExtra;
556 public uint dmFields;
557 public int dmPositionX;
558 public int dmPositionY;
559 public uint dmDisplayOrientation;
560 public uint dmDisplayFixedOutput;
561 public short dmColor;
562 public short dmDuplex;
563 public short dmYResolution;
564 public short dmTTOption;
565 public short dmCollate;
566 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)]
567 public string dmFormName;
568 public ushort dmLogPixels;
569 public uint dmBitsPerPel;
570 public uint dmPelsWidth;
571 public uint dmPelsHeight;
572 public uint dmDisplayFlags;
573 public uint dmDisplayFrequency;
574 public uint dmICMMethod;
575 public uint dmICMIntent;
576 public uint dmMediaType;
577 public uint dmDitherType;
578 public uint dmReserved1;
579 public uint dmReserved2;
580 public uint dmPanningWidth;
581 public uint dmPanningHeight;
582 }
583
584 [DllImport("user32.dll", CharSet = CharSet.Ansi)]
585 internal static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE devMode);
586
587 [DllImport("user32.dll", CharSet = CharSet.Ansi)]
588 internal static extern int ChangeDisplaySettings(ref DEVMODE devMode, int flags);
589
590 [DllImport("user32.dll", CharSet = CharSet.Ansi)]
591 internal static extern int ChangeDisplaySettingsEx(string deviceName, ref DEVMODE devMode, IntPtr hwnd, int dwFlags, IntPtr lParam);
592
593 #endregion Display Resolution
594 }
595}