{"id":1255,"date":"2024-05-12T18:23:40","date_gmt":"2024-05-12T10:23:40","guid":{"rendered":"https:\/\/blog.5danyuan.com\/?p=1255"},"modified":"2024-05-12T18:23:40","modified_gmt":"2024-05-12T10:23:40","slug":"c-%e5%88%87%e6%8d%a2%e5%a4%9a%e5%b1%8f%e5%b9%95%e6%98%be%e7%a4%ba%e6%a8%a1%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/blog.5danyuan.com\/?p=1255","title":{"rendered":"C# \u5207\u6362\u591a\u5c4f\u5e55\u663e\u793a\u6a21\u5f0f"},"content":{"rendered":"\n<p>\u7f51\u4e0a\u641c\u7d22\u4e86\u4e0b\uff0c\u67092\u79cd\u65b9\u5f0f\u3002<\/p>\n\n\n\n<p>\u4e00\u3001\u76f4\u63a5\u6267\u884c\u7cfb\u7edf\u81ea\u5e26\u7684\u7a0b\u5e8f DisplaySwitch.exe\uff0c\u5b83\u5728 windows\\system32 \u76ee\u5f55\u4e0b\u3002\u5bf9\u5e94\u7684 C# \u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using (var proc = new Process())\n{\nproc.StartInfo.FileName = @\"DisplaySwitch.exe\";\nproc.StartInfo.Arguments = \"\/external\";\nproc.Start();\n}<\/code><\/pre>\n\n\n\n<p>\u4e8c\u3001\u8c03\u7528\u7cfb\u7edf API SetDisplayConfig \u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>private const uint SDC_APPLY = 0x00000080;\nprivate const uint SDC_TOPOLOGY_INTERNAL = 0x00000001;\nprivate const uint SDC_TOPOLOGY_CLONE = 0x00000002;\nprivate const uint SDC_TOPOLOGY_EXTERNAL = 0x00000008;\nprivate const uint SDC_TOPOLOGY_EXTEND = 0x00000004;\n\n&#91;DllImport(\"user32.dll\", CharSet = CharSet.Unicode)]\npublic static extern long SetDisplayConfig(uint numPathArrayElements, IntPtr pathArray, uint numModeArrayElements,IntPtr modeArray, uint flags);\n\n\/\/\/ \/\/\/ \u8bbe\u7f6e\u5c4f\u5e55\u7684\u663e\u793a\u6a21\u5f0f \/\/\/\n\/\/\/ \u6a21\u5f0f(0 - \u4e3b\u5c4f 1 - \u53cc\u5c4f\u590d\u5236 2 - \u53cc\u5c4f\u6269\u5c55 3 - \u7b2c\u4e8c\u5c4f\u5e55\n\/\/\/\npublic void SetScreenMode(int type)\n{\nuint mode;\n\nswitch (type)\n{\n    case 0:\n        mode = SDC_APPLY | SDC_TOPOLOGY_INTERNAL;\n        break;\n    case 1:\n        mode = SDC_APPLY | SDC_TOPOLOGY_CLONE;\n        break;\n    case 2:\n        mode = SDC_APPLY | SDC_TOPOLOGY_EXTEND;\n        break;\n    case 3:\n        mode = SDC_APPLY | SDC_TOPOLOGY_EXTERNAL;\n        break;\n    default:\n        mode = SDC_APPLY | SDC_TOPOLOGY_INTERNAL;\n        break;\n}\n\nSetDisplayConfig(0, IntPtr.Zero, 0, IntPtr.Zero, mode);\n\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7f51\u4e0a\u641c\u7d22\u4e86\u4e0b\uff0c\u67092\u79cd\u65b9\u5f0f\u3002 \u4e00\u3001\u76f4\u63a5\u6267\u884c\u7cfb\u7edf\u81ea\u5e26\u7684\u7a0b\u5e8f DisplaySwitch.exe\uff0c\u5b83\u5728 window [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[120],"class_list":["post-1255","post","type-post","status-publish","format-standard","hentry","category-a-short-word","tag-c-sharp"],"_links":{"self":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts\/1255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1255"}],"version-history":[{"count":0,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts\/1255\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}