首页 文章 精选 留言 我的

精选列表

搜索[c 14],共10000篇文章
优秀的个人博客,低调大师

C#: Get current keyboard layout\input language

原文https://yal.cc/csharp-get-current-keyboard-layout/ On some occasions, you may want to get a "global" input language - that is, the keyboard layout used by the current foreground window\application\whatever. Basically, simulating the behaviour of the language panel on Windows. The common use cases are on-screen keyboards, fullscreen applications, and widgets. While I wasn't able to find a premade function that get this particular thing during my searches, it turned out not to be too hard to assemble: [DllImport("user32.dll")] static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr hwnd, IntPtr proccess); [DllImport("user32.dll")] static extern IntPtr GetKeyboardLayout(uint thread); public CultureInfo GetCurrentKeyboardLayout() { try { IntPtr foregroundWindow = GetForegroundWindow(); uint foregroundProcess = GetWindowThreadProcessId(foregroundWindow, IntPtr.Zero); int keyboardLayout = GetKeyboardLayout(foregroundProcess).ToInt32() & 0xFFFF; return new CultureInfo(keyboardLayout); } catch (Exception _) { return new CultureInfo(1033); // Assume English if something went wrong. } } So, first, we import a couple of functions from user32.dll: GetForegroundWindow, to get the current foreground\active window' pointer. GetWindowThreadProcessId, to get the ID of the thread that created the particular window. GetKeyboardLayout, to get the keyboard layout ID currently used by the given thread. The actual function then proceeds to combine these in a straightforward manner to obtain the keyboard layout ID for the current active window. Then a System.Globalization.CultureInfo is created based on ID, permitting to conveniently get the language name in various formats and a handful of other useful information. If there's no foreground window available, GetKeyboardLayout will return 0 (which is not a valid ID for CultureInfo), and the catch-block will return En-US as a fallback language (alternatively, you can return null and handle that separately). And that's it. Have fun!

优秀的个人博客,低调大师

C#:在AnyCPU模式下使用CefSharp

------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客讲述如何在AnyCPU模式下使用CefSharp 因为在某些情况下,不得不用AnyCPU,但是CefSharp支持的是86和64位俩种模式,所以在我查阅了很多国内外的资料下,总结出来的一些精华 参考地址: https://ourcodeworld.com/articles/read/173/how-to-use-cefsharp-chromium-embedded-framework-csharp-in-a-winforms-application https://github.com/cefsharp/CefSharp/issues/1714 https://github.com/cefsharp/CefSharp.MinimalExample/blob/demo/anycpu/CefSharp.MinimalExample.Wpf/App.xaml.cs 三篇结合就可以实现在AnyCPU下使用CefSharp 简单步骤记录 第一篇博客取其第二个,更改配置的那一块,这块不改,下面的没用,项目起不起来 简述一下: 1.修改为首选32位, 2.在你项目名.csproj文件下,加一段 <CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport> 位置如下: 3.在App.config下加一端 <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="x86"/> </assemblyBinding> </runtime> 位置如下: 第二篇博客取的精髓在这块,我给放过来 public partial class App : Application { public App() { //Add Custom assembly resolver AppDomain.CurrentDomain.AssemblyResolve += Resolver; //Any CefSharp references have to be in another method with NonInlining // attribute so the assembly rolver has time to do it's thing. InitializeCefSharp(); } [MethodImpl(MethodImplOptions.NoInlining)] private static void InitializeCefSharp() { var settings = new CefSettings(); // Set BrowserSubProcessPath based on app bitness at runtime settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", "CefSharp.BrowserSubprocess.exe"); // Make sure you set performDependencyCheck false Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null); } // Will attempt to load missing assembly from either x86 or x64 subdir // Required by CefSharp to load the unmanaged dependencies when running using AnyCPU private static Assembly Resolver(object sender, ResolveEventArgs args) { if (args.Name.StartsWith("CefSharp")) { string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll"; string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", assemblyName); return File.Exists(archSpecificPath) ? Assembly.LoadFile(archSpecificPath) : null; } return null; } } 第三篇博客 就是告诉你using指令怎么引,以及详细的写法,要用的话,还是用第二篇博客的这段代码 using System; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Windows; namespace CefSharp.MinimalExample.Wpf { public partial class App : Application { public App() { //Add Custom assembly resolver AppDomain.CurrentDomain.AssemblyResolve += Resolver; //Any CefSharp references have to be in another method with NonInlining // attribute so the assembly rolver has time to do it's thing. InitializeCefSharp(); } [MethodImpl(MethodImplOptions.NoInlining)] private static void InitializeCefSharp() { //Perform dependency check to make sure all relevant resources are in our output directory. var settings = new CefSettings(); settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", "CefSharp.BrowserSubprocess.exe"); Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler:null); } // Will attempt to load missing assembly from either x86 or x64 subdir // Required by CefSharp to load the unmanaged dependencies when running using AnyCPU private static Assembly Resolver(object sender, ResolveEventArgs args) { if (args.Name.StartsWith("CefSharp")) { string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll"; string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", assemblyName); return File.Exists(archSpecificPath) ? Assembly.LoadFile(archSpecificPath) : null; } return null; } } } 三套组合拳打完,CefSharp就可以在AnyCPU模式下使用了

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码