{"id":3481,"date":"2016-01-22T17:00:46","date_gmt":"2016-01-22T09:00:46","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=3481"},"modified":"2016-01-23T15:29:27","modified_gmt":"2016-01-23T07:29:27","slug":"%e6%8a%80%e5%b7%a7-%e8%a7%a3%e5%86%b3-windows-8-10-%e6%97%a0%e6%b3%95%e9%80%9a%e8%bf%87-screen-%e7%9a%84-imes-%e6%ad%a3%e7%a1%ae%e8%8e%b7%e5%8f%96%e5%bd%93%e5%89%8d%e5%ae%89%e8%a3%85%e7%9a%84","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=3481","title":{"rendered":"[\u6280\u5de7] \u89e3\u51b3 Windows 8 \/ 10 \u65e0\u6cd5\u901a\u8fc7 Screen \u7684 Imes \u6b63\u786e\u83b7\u53d6\u5f53\u524d\u5b89\u88c5\u7684\u8f93\u5165\u6cd5\u5217\u8868\u7684\u95ee\u9898"},"content":{"rendered":"<h4>\u3010\u95ee\u9898\u539f\u56e0\u3011<\/h4>\n<p>\u8be5\u95ee\u9898\u662f\u7531\u4e8e\u5fae\u8f6f\u4ece Windows 8 \u00a0\u5f00\u59cb\uff0cGetKeyboadLayouts \u51fd\u6570\u4e0d\u518d\u6709\u6548\uff0c\u800c VCL \u4e2d\u4ecd\u7136\u662f\u901a\u8fc7\u8be5\u65b9\u6cd5\u83b7\u53d6\u8f93\u5165\u6cd5\u5217\u8868\u9020\u6210\u7684\u3002\u5e0c\u671b\u4e0b\u4e2a\u7248\u672c\u7684 Delphi\/C++ Builder \u80fd\u591f\u89e3\u51b3\u3002<\/p>\n<h4>\u3010\u89e3\u51b3\u529e\u6cd5\u3011<\/h4>\n<p>\u5982\u679c\u662f Win8+\uff0c\u5219\u81ea\u5df1\u4ece\u6ce8\u518c\u8868\u8bfb\uff0c\u5982\u679c\u662fWin 7 \u7b49\u4ee5\u524d\u7684\u7248\u672c\uff0c\u5219\u76f4\u63a5\u53d6 Screen.Imes\u3002\u8fd9\u4e2a\u51fd\u6570\u505a\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u5c01\u88c5\u3002<\/p>\n<pre class=\"lang:delphi decode:true \">procedure EnumImeNames(AList: TStrings);\r\nvar\r\n  AReg: TRegistry;\r\n  AKeyList: TStringList;\r\n  I: Integer;\r\n  ALayout: Cardinal;\r\n  function NameByLayout: String;\r\n  const\r\n    KbLayoutRegkeyFmt =\r\n      'System\\CurrentControlSet\\Control\\Keyboard Layouts\\%.8x';\r\n    KbLayoutRegSubkey = 'layout text';\r\n  var\r\n    AIMEReg: TRegistry;\r\n  begin\r\n    SetLength(Result, 0);\r\n    AIMEReg := TRegistry.Create;\r\n    try\r\n      AIMEReg.RootKey := HKEY_LOCAL_MACHINE;\r\n      if AIMEReg.OpenKeyReadOnly(Format(KbLayoutRegkeyFmt, [ALayout])) then\r\n      begin\r\n        if AIMEReg.ValueExists(KbLayoutRegSubkey) then\r\n          Result := AIMEReg.ReadString(KbLayoutRegSubkey)\r\n      end;\r\n    finally\r\n      FreeAndNil(AIMEReg);\r\n    end;\r\n  end;\r\n\r\n  function NameByClsId(AClsId: String): String;\r\n  var\r\n    AIMEReg: TRegistry;\r\n  begin\r\n    SetLength(Result, 0);\r\n    AIMEReg := TRegistry.Create;\r\n    try\r\n      AIMEReg.RootKey := HKEY_CLASSES_ROOT;\r\n      if AIMEReg.OpenKeyReadOnly('CLSID\\' + AClsId) then\r\n        Result := AIMEReg.ReadString('');\r\n    finally\r\n      FreeAndNil(AIMEReg);\r\n    end;\r\n  end;\r\n\r\nconst\r\n  CnImeRoot =\r\n    'Software\\Microsoft\\CTF\\SortOrder\\AssemblyItem\\0x00000804\\{34745C63-B2F0-4784-8B67-5E12C8701A31}';\r\nbegin\r\nif CheckWin32Version(6,2) then\r\n  begin\r\n  AKeyList := TStringList.Create;\r\n  AReg := TRegistry.Create;\r\n  AList.BeginUpdate;\r\n  try\r\n    AReg.RootKey := HKEY_CURRENT_USER;\r\n    if AReg.OpenKeyReadOnly(CnImeRoot) then\r\n    begin\r\n      AReg.GetKeyNames(AKeyList);\r\n      AReg.CloseKey;\r\n      for I := 0 to AKeyList.Count - 1 do\r\n      begin\r\n        if AReg.OpenKeyReadOnly(CnImeRoot+'\\'+AKeyList[I]) then\r\n        begin\r\n          if AReg.ValueExists('KeyboardLayout') then\r\n            ALayout := AReg.ReadInteger('KeyboardLayout')\r\n          else\r\n            ALayout := 0;\r\n          if ALayout &gt; 0 then\r\n            AList.Add(NameByLayout)\r\n          else if AReg.ValueExists('CLSID') then\r\n            AList.Add(NameByClsId(AReg.ReadString('CLSID')));\r\n          AReg.CloseKey;\r\n        end;\r\n      end;\r\n    end;\r\n  finally\r\n    FreeAndNil(AReg);\r\n    FreeAndNil(AKeyList);\r\n    AList.EndUpdate;\r\n  end;\r\n  end\r\nelse\r\n  AList.Assign(Screen.Imes);\r\nend;<\/pre>\n<h4>\u3010\u53e6\u9644\u3011<\/h4>\n<p>\u9ed1\u591c\u6740\u624b\u63d0\u4f9b\u7684\u4e00\u4e2a\u8bbe\u7f6e\u9ed8\u8ba4\u8f93\u5165\u6cd5\u7684\u51fd\u6570\uff0c\u63d0\u4f9b\u7ed9\u9700\u8981\u7684\u670b\u53cb\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">procedure SetDefaultCNIME(AForm: TForm; IMEKeyStr: string = '\u4e94\u7b14');\r\nvar\r\n  I, idx: Integer;\r\n  IMESList: TStringList;\r\nbegin\r\n  IMESList := TStringList.Create;\r\n  EnumImeNames(IMESList);\r\n  try\r\n    if IMESList.Count &gt; 0 then\r\n    begin\r\n      { \u5f00\u59cb\u521d\u59cb\u5316\u9ed8\u8ba4\u4e2d\u6587\u8f93\u5165\u6cd5 }\r\n      idx := -1;\r\n      for I := 0 to IMESList.Count - 1 do\r\n      begin\r\n        if IMESList[I].Contains(IMEKeyStr) then\r\n        begin\r\n          idx := I;\r\n          Break;\r\n        end;\r\n      end;\r\n      if idx = -1 then\r\n      begin\r\n        for I := 0 to IMESList.Count - 1 do\r\n        begin\r\n          if IMESList[I].Contains('\u62fc\u97f3') then\r\n          \/\/ \u5982\u679c\u627e\u4e0d\u5230\u6307\u5b9a\u7684\u8f93\u5165\u6cd5\uff0c\u5219\u8bbe\u7f6e\u4e3a\u62fc\u97f3\r\n          begin\r\n            idx := I;\r\n            Break;\r\n          end;\r\n        end;\r\n      end;\r\n      if idx = -1 then\r\n      begin\r\n        if IMESList.Count &gt; 0 then\r\n        begin\r\n          idx := 0;\r\n        end\r\n        else\r\n        begin\r\n          exit;\r\n        end;\r\n      end;\r\n      for I := 0 to AForm.ComponentCount - 1 do\r\n      begin\r\n        if AForm.Components[I] is TMemo then\r\n          TMemo(AForm.Components[I]).ImeName := IMESList[idx];\r\n        if AForm.Components[I] is TEdit then\r\n          TEdit(AForm.Components[I]).ImeName := IMESList[idx];\r\n        if AForm.Components[I] is TLabeledEdit then\r\n          TEdit(AForm.Components[I]).ImeName := IMESList[idx];\r\n      end;\r\n      { \u7ed3\u675f\u521d\u59cb\u5316\u9ed8\u8ba4\u4e2d\u6587\u8f93\u5165\u6cd5 }\r\n    end; \r\n  finally\r\n    IMESList.Free;\r\n  end;\r\nend;<\/pre>\n<p><strong><span style=\"color: #ff0000;\">\u3010\u6ce8\u610f\u3011<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #ff0000;\">\u5728\u6267\u884c\u4e0a\u8ff0\u64cd\u4f5c\u4e4b\u524d\uff0c\u8bf7\u786e\u8ba4\u5df2\u7ecf\u4fee\u6539\u6ce8\u518c\u8868\uff0c\u5141\u8bb8\u6bcf\u4e2a\u5e94\u7528\u72ec\u7acb\u63a7\u5236\u8f93\u5165\u6cd5\uff0c\u9ed1\u591c\u6740\u624b\u63d0\u4f9b\u7684\u53c2\u8003\u4ee3\u7801\u5982\u4e0b\uff1a<\/span><\/strong><\/p>\n<pre class=\"lang:delphi decode:true \">procedure SetDiffInputMethodInSeperateApp;\r\n\/\/http:\/\/superuser.com\/questions\/839993\/find-registry-key-for-windows-8-per-application-input-method-setting\r\nvar\r\n  AReg: TRegistry;\r\n  MyValue: array [0 .. 7] of Byte;\r\n  \/\/ =[$9e,$1e,$07,$80,$92,$00,$00,$00]; on\r\n  \/\/ =[$9e,$1e,$07,$80,$12,$00,$00,$00]; off\r\nconst\r\n  ImeMethodSetRoot =\r\n    'Control Panel\\Desktop';\r\nbegin\r\n  if CheckWin32Version(6, 2) then\r\n  begin\r\n    AReg := TRegistry.Create;\r\n    try\r\n      AReg.RootKey := HKEY_CURRENT_USER;\r\n      if AReg.OpenKey(ImeMethodSetRoot, False) then\r\n      begin\r\n        if AReg.ValueExists('UserPreferencesMask') then\r\n        begin\r\n          AReg.ReadBinaryData('UserPreferencesMask', MyValue, 8);\r\n          MyValue[4] := $92;\r\n          AReg.WriteBinaryData('UserPreferencesMask', MyValue, 8);\r\n        end;\r\n        AReg.CloseKey;\r\n      end;\r\n    finally\r\n      FreeAndNil(AReg);\r\n    end;\r\n  end;\r\nend;\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3010\u95ee\u9898\u539f\u56e0\u3011 \u8be5\u95ee\u9898\u662f\u7531\u4e8e\u5fae\u8f6f\u4ece Win [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[69,8],"tags":[543,542,237,28,436,544],"class_list":["post-3481","post","type-post","status-publish","format-standard","hentry","category-c-builder","category-delphi","tag-543","tag-542","tag-vcl","tag-windows","tag-436","tag-544"],"views":6113,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/3481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3481"}],"version-history":[{"count":5,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/3481\/revisions"}],"predecessor-version":[{"id":3502,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/3481\/revisions\/3502"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}