{"id":3145,"date":"2020-08-21T10:23:36","date_gmt":"2020-08-21T02:23:36","guid":{"rendered":"https:\/\/www.aoisnow.net\/blog\/?p=3145"},"modified":"2020-08-21T10:23:36","modified_gmt":"2020-08-21T02:23:36","slug":"tont-34893-es_oemconvert-%e6%98%af%e5%81%9a%e4%bb%80%e4%b9%88%e7%94%a8%e7%9a%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.aoisnow.net\/blog\/archives\/3145","title":{"rendered":"TONT 34893 ES_OEMCONVERT \u662f\u505a\u4ec0\u4e48\u7528\u7684\uff1f"},"content":{"rendered":"<p>\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050719-12\/?p=34893\" target=\"_blank\" rel=\"noopener\">https:\/\/devblogs.microsoft.com\/oldnewthing\/20050719-12\/?p=34893<\/a><\/p>\n<p>The ES_OEMCONVERT edit control style is a holdover from 16-bit Windows. This ancient MSDN article from the Windows 3.1 SDK describes the flag thus:<\/p>\n<p>\u7f16\u8f91\u63a7\u4ef6\u7684 ES_OEMCONVERT \u6837\u5f0f\u662f\u4ece 16 \u4f4d Windows \u4e2d\u7ee7\u627f\u4e0b\u6765\u7684\u3002\u4e0b\u9762\u8fd9\u7bc7\u5728 Windows 3.1 SDK \u4e2d\u53e4\u8001\u7684 MSDN \u6587\u7ae0\u5bf9\u8fd9\u4e2a\u6807\u5fd7\u662f\u8fd9\u6837\u63cf\u8ff0\u7684\uff1a<\/p>\n<blockquote><p>ES_OEMCONVERT causes text entered into the edit control to be converted from ANSI to OEM and then back to ANSI. This ensures proper character conversion when the application calls the AnsiToOem function to convert a Windows string in the edit control to OEM characters. ES_OEMCONVERT is most useful for edit controls that contain filenames.<\/p>\n<p>ES_OEMCONVERT \u6807\u8bb0\u4f1a\u5c06\u8f93\u5165\u5230\u7f16\u8f91\u63a7\u4ef6\u7684\u6587\u5b57\u4ece ANSI \u7f16\u7801\u8f6c\u6362\u5230 OEM \u7f16\u7801\uff0c\u7136\u540e\u518d\u8f6c\u56de ANSI \u7f16\u7801\u3002\u901a\u8fc7\u8fd9\u6837\u64cd\u4f5c\uff0c\u53ef\u4ee5\u4fdd\u8bc1\u5e94\u7528\u7a0b\u5e8f\u8c03\u7528AnsiToOem \u5c06\u7f16\u8f91\u63a7\u4ef6\u4e2d\u7684\u5b57\u7b26\u8f6c\u6362\u4e3a OEM \u7f16\u7801\u7684\u5b57\u7b26\u65f6\uff0c\u53ef\u4ee5\u83b7\u5f97\u6070\u5f53\u7684\u7ed3\u679c\u3002ES_OEMCONVERT\u00a0 \u5728\u5305\u542b\u6587\u4ef6\u540d\u7684\u7f16\u8f91\u63a7\u4ef6\u4e2d\u6700\u6709\u88e8\u76ca\u3002<\/p><\/blockquote>\n<p>Set the wayback machine to, well, January 31, 1992, the date of the article.<\/p>\n<p>\u8ba9\u6211\u4eec\u628a\u65f6\u95f4\u5012\u56de1992\u5e741\u670831\u65e5\uff0c\u4e5f\u5c31\u662f\u4e0a\u9762\u90a3\u6bb5\u6587\u5b57\u90a3\u65f6\u5019\u3002<\/p>\n<p>At this time, the predominant Windows platform was Windows 3.0. Windows 3.1 was still a few months away from release, and Windows NT 3.1 was over a year away. The predominant file system was 16-bit FAT, and the relevant feature of FAT of this era for the purpose of this discussion is that file names were stored on disk in the OEM character set. (We discussed the history behind the schism between the OEM and ANSI code pages in an earlier article.)<\/p>\n<p>\u90a3\u4e2a\u65f6\u5019\uff0c\u5360\u636e\u4e3b\u5bfc\u5730\u4f4d\u7684 Windows \u5e73\u53f0\u662f Windows 3.0\u3002Windows 3.1 \u8fd8\u5f97\u518d\u8fc7\u51e0\u4e2a\u6708\u624d\u4f1a\u53d1\u5e03\uff0c\u800c Windows NT 3.1 \u8fd8\u5f97\u518d\u7b49\u4e00\u5e74\u3002\u90a3\u65f6\u5360\u4e3b\u5bfc\u5730\u4f4d\u7684\u6587\u4ef6\u7cfb\u7edf\u662f 16 \u4f4d FAT\uff0c\u800c\u4e0e\u6b64\u5904\u8ba8\u8bba\u76f8\u5173\u7684 FAT \u6587\u4ef6\u7cfb\u7edf\u7684\u8bbe\u8ba1\uff0c\u5219\u662f\u78c1\u76d8\u4e0a\u5b58\u50a8\u7684\u6587\u4ef6\u540d\u4f7f\u7528\u7684\u662f OEM \u5b57\u7b26\u96c6\u3002\uff08\u6211\u4eec\u5728\u65e9\u5148\u7684\u4e00\u7bc7\u6587\u7ae0\u4e2d\u8ba8\u8bba\u8fc7\u6709\u5173 OEM \u548c ANSI \u4ee3\u7801\u9875\u4e4b\u95f4\u7684\u5206\u5d29\u79bb\u6790\u3002\uff09\uff08\u8bd1\u6ce8\uff1a\u94fe\u63a5\u5df2\u5931\u6548\uff0c\u65e0\u6cd5\u67e5\u8bc1\uff09<\/p>\n<p>Since GUI programs used the ANSI character set, but file names were stored in the OEM character set, the only characters that could be used in file names from GUI programs were those that exist in both character sets. If a character existed in the ANSI character set but not the OEM character set, then there would be no way of using it as a file name; and if a character existed in the OEM character set but not the ANSI character set, the GUI program couldn\u2019t manipulate it.<\/p>\n<p>\u7531\u4e8e GUI \u7a0b\u5e8f\u7528\u7684\u662f ANSI \u5b57\u7b26\u96c6\uff0c\u800c\u6587\u4ef6\u540d\u662f\u7528 OEM \u5b57\u7b26\u96c6\u5b58\u50a8\u7684\uff0c\u6240\u4ee5\u5728 GUI \u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u7684\u6587\u4ef6\u540d\uff0c\u5176\u5b57\u7b26\u96c6\u53ea\u80fd\u662f\u5728\u4e24\u79cd\u5b57\u7b26\u96c6\u4e2d\u5171\u5b58\u7684\u90a3\u4e9b\u3002\u5982\u679c\u67d0\u4e2a\u5b57\u7b26\u5728 ANSI \u5b57\u7b26\u96c6\u4e2d\u5b58\u5728\uff0c\u4f46\u5e76\u4e0d\u5b58\u5728\u4e8e OEM \u5b57\u7b26\u96c6\u4e2d\uff0c\u90a3\u4e48\u5c31\u4e0d\u80fd\u8bb2\u8fd9\u4e2a\u5b57\u7b26\u7528\u5728\u6587\u4ef6\u540d\u4e2d\uff1b\u53cd\u4e4b\uff0c\u5982\u679c\u67d0\u4e2a\u5b57\u7b26\u5728 OEM \u5b57\u7b26\u96c6\u4e2d\u5b58\u5728\uff0c\u4f46\u5728 ANSI \u5b57\u7b26\u96c6\u4e2d\u4e0d\u5b58\u5728\uff0c\u90a3\u4e48 GUI \u5e94\u7528\u7a0b\u5e8f\u4e5f\u641e\u4e0d\u5b9a\u5b83\u3002<\/p>\n<p>The ES_OEMCONVERT flag on a edit control ensures that only characters that exist in both the ANSI and OEM character sets are used, hence the remark \u201cES_OEMCONVERT is most useful for edit controls that contain filenames\u201d.<\/p>\n<p>\u7f16\u8f91\u63a7\u4ef6\u4e2d\u7684 ES_OEMCONVERT \u6837\u5f0f\u53ef\u4ee5\u4fdd\u8bc1\u53ea\u6709\u5728 ANSI \u548c OEM \u4e24\u79cd\u5b57\u7b26\u96c6\u4e2d\u5171\u5b58\u7684\u5b57\u7b26\u624d\u80fd\u4f7f\u7528\uff0c\u4e5f\u5c31\u5370\u8bc1\u4e86\u300eES_OEMCONVERT\u00a0 \u5728\u5305\u542b\u6587\u4ef6\u540d\u7684\u7f16\u8f91\u63a7\u4ef6\u4e2d\u6700\u6709\u88e8\u76ca\u300f\u7684\u8bf4\u6cd5\u3002<\/p>\n<p>Fast-forward to today.<\/p>\n<p>\u56de\u5230\u73b0\u5728\u3002<\/p>\n<p>All the popular Windows file systems support Unicode file names and have for ten years. There is no longer a data loss converting from the ANSI character set to the character set used by the file system. Therefore, there is no need to filter out any characters to forestall the user typing a character that will be lost during the conversion to a file name. In other words, the ES_OEMCONVERT flag is pointless today. It\u2019s a leftover from the days before Unicode.<\/p>\n<p>\u5982\u4eca\u6240\u6709\u6d41\u884c\u7684 Windows \u6587\u4ef6\u7cfb\u7edf\u90fd\u652f\u6301 Unicode \u6587\u4ef6\u540d\uff0c\u5e76\u4e14\u5df2\u7ecf\u5982\u6b64\u5341\u5e74\u4e86\uff08\u8bd1\u6ce8\uff1a\u539f\u6587\u53d1\u5e03\u65f6\u95f4\u4e3a2005\u5e747\u670819\u65e5\uff0cWindows 3.0 \u53d1\u5e03\u65f6\u95f4\u4e3a1990\u5e745\u670822\u65e5\uff09\uff0c\u5728\u5c06\uff08\u6587\u4ef6\u540d\u4e2d\u7684\u5b57\u7b26\u4ece\uff09ANSI \u5b57\u7b26\u96c6\u8f6c\u6362\u4e3a\u6587\u4ef6\u7cfb\u7edf\u4f7f\u7528\u7684\u5b57\u7b26\u96c6\uff08Unicode\uff09\u4e0d\u4f1a\u518d\u6709\u6570\u636e\u4e22\u5931\u7684\u95ee\u9898\u4e86\u3002\u56e0\u6b64\u4e5f\u6ca1\u6709\u5fc5\u8981\u518d\u9884\u5148\u5c06\u7528\u6237\u5f55\u5165\u6587\u4ef6\u540d\u65f6\uff0c\u53ef\u80fd\u5728\u540e\u671f\u8f6c\u6362\u4e2d\u4e22\u5931\u7684\u5b57\u7b26\u8fc7\u6ee4\u6389\u4e86\u3002\u6362\u53e5\u8bdd\u8bf4\uff0cES_OEMCONVERT \u8fd9\u4e2a\u6837\u5f0f\u6807\u8bb0\u5df2\u7ecf\u6beb\u65e0\u610f\u4e49\u4e86\uff0c\u53ea\u662f\u4e00\u4e2a\u5728 Unicode \u5e74\u4ee3\u4e4b\u524d\u7684\u9057\u7559\u800c\u5df2\u3002<\/p>\n<p>Indeed, if you use this flag, you make your program worse, not better, because it unnecessarily restricts the set of characters that the user will be allowed to use in file names. A user running the US-English version of Windows would not be allowed to enter Chinese characters as a file name, for example, even though the file system is perfectly capable of creating files whose names contain those characters.<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0c\u5982\u679c\u4f60\u975e\u8981\u7528\u8fd9\u4e2a\u6837\u5f0f\u6807\u8bb0\u4e0d\u53ef\uff0c\u53ea\u4f1a\u8ba9\u4f60\u7684\u7a0b\u5e8f\u66f4\u7cdf\u7cd5\u800c\u4e0d\u662f\u66f4\u4f18\u79c0\uff0c\u56e0\u4e3a\u5bf9\u7528\u6237\u5728\u6587\u4ef6\u540d\u4e2d\u5141\u8bb8\u4f7f\u7528\u8fc7\u7684\u5b57\u7b26\u96c6\u8fdb\u884c\u9650\u5236\u5df2\u7ecf\u6beb\u65e0\u5fc5\u8981\u3002\u4f8b\u5982\uff0c\uff08\u5728\u4f60\u7ecf\u8fc7\u8fd9\u6837\u8bbe\u8ba1\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\uff09\u4f7f\u7528\u7f8e\u56fd\u82f1\u8bed\u7248\u672c Windows \u7684\u7528\u6237\u5c31\u4e0d\u80fd\u8f93\u5165\u4e2d\u6587\u5b57\u7b26\u4f5c\u4e3a\u6587\u4ef6\u540d\u4e86\uff0c\u5373\u4fbf\u662f\u6587\u4ef6\u7cfb\u7edf\u53ef\u4ee5\u5b8c\u7f8e\u652f\u6301\u521b\u5efa\u5305\u542b\u90a3\u4e9b\uff08\u4e2d\u6587\uff09\u5b57\u7b26\u7684\u6587\u4ef6\u540d\u4e5f\u4e00\u6837\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u94fe\u63a5\uff1ahttps:\/\/devblogs.microsoft.com\/oldnewthing\/2005071 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-3145","post","type-post","status-publish","format-standard","hentry","category-tont_history"],"_links":{"self":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/3145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/comments?post=3145"}],"version-history":[{"count":0,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/3145\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/media?parent=3145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/categories?post=3145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/tags?post=3145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}