{"id":212,"date":"2013-01-31T15:31:21","date_gmt":"2013-01-31T07:31:21","guid":{"rendered":"http:\/\/blog.sorayuki.net\/?p=212"},"modified":"2014-02-10T17:49:43","modified_gmt":"2014-02-10T09:49:43","slug":"%e8%a7%a3%e5%86%b3%e5%b8%9d%e5%9b%bd2%e5%9c%a8win7%e4%b8%8b%e9%a2%9c%e8%89%b2%e4%b8%8d%e6%ad%a3%e7%a1%ae%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/blog.sorayuki.net\/?p=212","title":{"rendered":"\u89e3\u51b3\u5e1d\u56fd\u65f6\u4ee32\u5728Win7\u4e0b\u989c\u8272\u4e0d\u6b63\u786e\u7684\u95ee\u9898"},"content":{"rendered":"<p>\u5e1d\u56fd\u65f6\u4ee32\u5728Windows7\u4e0b\u9762\u8fd0\u884c\u7684\u65f6\u5019\uff0c\u4f1a\u51fa\u73b0\u989c\u8272\u4e0d\u6b63\u786e\u7684\u95ee\u9898\uff1a\u8349\u5730\u672c\u6765\u5e94\u8be5\u662f\u7eff\u7684\uff0c\u4f46\u662f\u5b83\u5374\u5145\u6ee1\u4e86\u6591\u6591\u70b9\u70b9\u7684\u7ea2\u8272\uff0c\u770b\u8d77\u6765\u5341\u5206\u6076\u5fc3\uff0c\u4e0d\u8fc7\u9664\u4e86\u989c\u8272\u4ee5\u5916\u5012\u662f\u4e5f\u6ca1\u6709\u5176\u4ed6\u592a\u5927\u7684\u95ee\u9898\u3002<\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6e38\u620f\u6765\u8bf4\uff0c\u770b\u8d77\u6765\u5f88\u96be\u53d7\u662f\u5341\u5206\u81f4\u547d\u7684\u3002\u4f60\u770b\u6709\u591a\u5c11\u6e38\u620f\u754c\u9762\u8981\u641e\u5f97\u5f88\u534e\u4e3d\u2026\u2026\u7f51\u4e0a\u641c\u7d22\u4ee5\u540e\uff0c\u5404\u79cd\u89e3\u51b3\u65b9\u6cd5\u597d\u51e0\u79cd\uff0c\u4f46\u662f\u5206\u6790\u4e00\u4e0b\uff0c\u5927\u591a\u662f\u8ba9\u4f60\u5f88\u96be\u53d7\u7684\u90a3\u79cd\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p><!--more--><\/p>\n<ol>\n<li>\u7ed3\u675fexplorer.exe\u8fdb\u7a0b\u7136\u540e\u518d\u8fdb\u5165\u6e38\u620f\u3002\u95ee\u9898\u786e\u5b9e\u80fd\u89e3\u51b3\uff0c\u4e0d\u8fc7\u2026\u2026\u96be\u53d7\u4e0d\uff1f<\/li>\n<li>\u7cfb\u7edf\u4e3b\u9898\u66f4\u6362\u6210Windows\u7ecf\u5178\u3002\u6bd4\u521a\u624d\u90a3\u4e2a\u4e0d\u96be\u53d7\u4e00\u70b9\u3002\u4f46\u662f\u8bf4\u771f\u7684\u633a\u8ba8\u538c\u7684\u2026\u2026\u5207\u6362\u6765\u5207\u6362\u53bb<\/li>\n<li>\u6709\u4eba\u5199\u4e86\u4e00\u4e2a\u5de5\u5177\uff0c\u68c0\u6d4b\u5230\u6e38\u620f\u8fd0\u884c\u5c31\u628aexplorer.exe csrss.exe\u8fd9\u7c7b\u8fdb\u7a0b\u7ed9suspend\u6389\u3002\u6bd4\u8d77\u7ed3\u675f\u8fdb\u7a0b\u8981\u201c\u6e29\u67d4\u201d\u4e00\u4e9b\uff0c\u4e0d\u8fc7\u6e38\u620f\u8fc7\u7a0b\u4e2dalt+tab\u5207\u6362\u51fa\u6765\uff0c\u5c31\u77e5\u9053\u6709\u591a\u96be\u53d7\u4e86\u3002<\/li>\n<li>\u627e\u4e86\u534a\u5929\u8fd9\u4e2a\u6700\u9760\u8c31\uff1a<a title=\"http:\/\/blog.macuyiko.com\/2009\/07\/solving-color-problem-red-grass-purple.html\" href=\"http:\/\/blog.macuyiko.com\/2009\/07\/solving-color-problem-red-grass-purple.html\">http:\/\/blog.macuyiko.com\/2009\/07\/solving-color-problem-red-grass-purple.html<\/a><\/li>\n<\/ol>\n<p>\u4e3a\u4e86\u9632\u6b62\u90a3\u4e2a\u535a\u5ba2\u4ec0\u4e48\u65f6\u5019\u5c31\u5f00\u4e0d\u5f00\u4e86\uff0c\u6211\u8fd8\u662f\u628a\u91cd\u8981\u5185\u5bb9\u590d\u5236\u51fa\u6765\u2026\u2026<\/p>\n<blockquote><p><strong>(9 - reliable)<\/strong> Thanks to this <a href=\"http:\/\/blog.macuyiko.com\/2009\/07\/solving-color-problem-red-grass-purple.html?showComment=1280788386634#c2672861145655342118\">comment<\/a> I found out that Windows 7 actually provides a compatibility hack build in to allow running old DirectDraw games in all their glorious colors. The <tt>HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\DirectDraw\\Compatibility\\<\/tt> registry entry (or <tt>HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\DirectDraw\\Compatibility\\<\/tt> for 64bit Windows) contains entries for some popular games, such as Age Of Empires and Starcraft.<\/p>\n<p>&nbsp;<\/p>\n<p>Take a look at <tt>HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\DirectDraw\\MostRecentApplication<\/tt> to find out the correct application ID and edit the registry entry manually accordingly.<\/p>\n<p>&nbsp;<\/p>\n<h3>Technical explanation<\/h3>\n<div>If you're interested in a little background on why this problem is happening, read on.<\/div>\n<div>When I first encountered this problem, I already knew a little about <a href=\"http:\/\/en.wikipedia.org\/wiki\/DirectX\">DirectX<\/a>, the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Graphics_Device_Interface\">GDI<\/a> and the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Windows_API\">Windows API<\/a>. Basically, back in the day, DirectX (which handles a lot of the graphics and multimedia workload in games and other program) included a component called Directdraw, used for rendering 2D graphics.<\/div>\n<div>PCs back then weren't really powerful. Everything had to be as fast as possible, even color handling. So something which Directdraw did for you was maintaining a palette of 256 colors. Like a painter, programmers could fill this palette with 256 colors they would use: ten greens for grass, 6 blues for water, and so on. Some of these 256 colors are static (but then again, not always) and cannot be changed. If you're interested in the deep and dirty details: <a href=\"http:\/\/www.compuphase.com\/palette.htm\">this page<\/a> does a good job explaining it.<\/div>\n<div>Now this is the thing: if you're a fullscreen game, you don't want other programs screwing up the system palette, changing your beautiful chosen colors to ugly greens and reds. And this is what's happening in Windows 7. If you read <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd145128(VS.85).aspx\">System Palette and Static Colors<\/a> on MSDN, it states that \"However, because changing the static colors can have an immediate and dramatic effect on all windows on the display, an application should not call SetSystemPaletteUse, unless it has a maximized window and the input focus.\" Alas, this is not enforced by Windows, and thus <tt>explorer.exe<\/tt> (which comes from Microsoft mind you) and other programs will happily call <tt>SetSystemPaletteUse<\/tt> and mess the poor fullscreen DirectDraw game up.<\/div>\n<div>I googled a bit around to see if I could find any clues. <a href=\"http:\/\/stackoverflow.com\/questions\/1054365\/exclusive-directdraw-palette-isnt-actually-exclusive\">This message<\/a> at Stackoverflow describes the same problem. This message is actually posted by the maintainers of Worms: Armageddon. No-one provided an answer though. I opened up Visual Studio (which was still installed) to quickly throw something together in VB.NET to intercept the <tt>WM_SYSCOLORCHANGE<\/tt>, <tt>WM_PALETTECHANGED<\/tt>, <tt>WM_PALETTEISCHANGING<\/tt> and <tt>WM_QUERYNEWPALETTE<\/tt> messages and look at where they're coming from. Basically, three processes are fighting:<\/div>\n<p><code>CHANGING from (0)\u00a0 CHANGED from Age of Empires II Expansion (135458)\u00a0 Device context: 16847861\u00a0 Process: 4508: age2_x1\u00a0 Got 256 palette size scr\u00a0 [...]\u00a0 CHANGED from GDI+ Window (917744)\u00a0 Device context: 184626156\u00a0 Process: 2452: explorer\u00a0 Got 256 palette size scr\u00a0 CHANGED from (65552)\u00a0 Device context: 1744905863\u00a0 Process: 540: csrss\u00a0 Got 256 palette size scr\u00a0 [...]<\/code><\/p>\n<p>&nbsp;<\/p>\n<p>The game itself, <tt>explorer.exe<\/tt>, and <tt>csrss.exe<\/tt>.<\/p><\/blockquote>\n<p>\u597d\uff0c\u6211\u5c31\u7528\u8fd9\u4e2a\u6700\u9760\u8c31\u7684\u3002\u9760\u8c31\u662f\u9760\u8c31\uff0c\u5bf9\u6211\u6765\u8bf4\u64cd\u4f5c\u4e5f\u4e0d\u4f1a\u6709\u592a\u5927\u95ee\u9898\uff0c\u4f46\u662f\u5176\u4ed6\u4eba\u5462\uff1f\u6e38\u620f\u5f88\u591a\u4eba\u90fd\u4f1a\u73a9\uff0c\u6539\u6ce8\u518c\u8868\u5c31\u4e0d\u662f\u6bcf\u4e2a\u4eba\u90fd\u4f1a\u6539\u4e86\u3002\u4e8e\u662f\u6211\u5199\u4e2a\u5de5\u5177\u6765\u81ea\u52a8\u6539\u6ce8\u518c\u8868\u3002<\/p>\n<p>\u95f2\u7740\u6ca1\u4e8b\u60f3\u8bd5\u4e00\u4e0bwpf\uff0c\u7ed3\u679c\u8fd9\u5de5\u5177\u7684\u754c\u9762\u5c31\u7528wpf\u6765\u5199\u4e86\u3002\u5173\u4e8e\u6ce8\u518c\u8868\u91cc\u9762\u7684\u90a3\u4e9b\u4e2aflags\u503c\uff0c\u5176\u5b9e\u6211\u4e0d\u77e5\u9053\u5b83\u662f\u4ec0\u4e48\uff0c\u4e0d\u8fc7\u65e2\u7136\u4eba\u5bb6\u752800080000\u53ef\u4ee5\u6b63\u5e38\u90a3\u6211\u4e5f\u752800080000\u5c31\u662f\u4e86\u3002<\/p>\n<p>\u4f7f\u7528\u65b9\u6cd5\u5f88\u7b80\u5355\uff0c\u9996\u5148\u542f\u52a8\u4e00\u4e0b\u6709\u95ee\u9898\u7684\u6e38\u620f\uff08\u5e1d\u56fd2\uff09\uff0c\u7136\u540e\u9000\u51fa\u6e38\u620f\uff0c\u6253\u5f00\u8fd9\u4e2a\u5de5\u5177\uff0c\u4f1a\u53d1\u73b0\u6700\u8fd1\u8fd0\u884c\u7684DirectDraw\u7a0b\u5e8f\u662f\u521a\u521a\u5f00\u7684\u90a3\u4e2a\u6e38\u620f\u3002OK\uff0c\u70b9Add\u6309\u94ae\u6dfb\u52a0\u5230\u4e0b\u9762\u90a3\u4e2a\u5217\u8868\u3002\u95ee\u9898\u89e3\u51b3\uff0c\u518d\u542f\u52a8\u5e1d\u56fd2\uff0c\u8fdb\u5165\u6e38\u620f\uff0c\u8349\u5730\u7684\u989c\u8272\u6b63\u5e38\u4e86\u3002<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u6ce8\u610f\uff1a\u6e38\u620f\u548c\u8fd9\u4e2a\u5de5\u5177\u90fd\u8981\u7528\u7ba1\u7406\u5458\u8eab\u4efd\u8fd0\u884c\u3002\u5982\u679c\u4e0d\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u8fd0\u884c\uff0c\u56e0\u4e3a\u6743\u9650\u4e0d\u8db3\uff0c\u53ef\u80fd\u65e0\u6cd5\u6b63\u786e\u66f4\u65b0\u6ce8\u518c\u8868\u952e\u503c\uff0c\u6700\u7ec8\u9020\u6210\u65e0\u6cd5\u8bfb\u53d6\u6700\u8fd1\u542f\u52a8\u7684DirectDraw\u7a0b\u5e8f\u548c\u65e0\u6cd5\u5199\u5165\u4fee\u6b63\u952e\u503c\u3002<\/span><\/strong><\/p>\n<p>\u6700\u540e\uff1a\u4e3a\u4ec0\u4e48\u662f\u82f1\u6587\u7684\uff1f\u6211\u5728\u60f3\u4f1a\u4e0d\u4f1a\u4ec0\u4e48\u65f6\u5019\u6709\u56fd\u9645\u53cb\u4eba\u4f1a\u9700\u8981\u8fd9\u4e1c\u897f\u5462\uff08\u6bb4<\/p>\n<div class=\"wlWriterEditableSmartContent\" id=\"scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:f281e2cf-2857-4e3f-ae5c-e708781cb877\" style=\"float: none; margin: 0px; display: inline; padding: 0px;\">\n<p>\u70b9\u51fb <a href=\"https:\/\/blog.sorayuki.net\/wp-content\/uploads\/2013\/10\/DirectDrawFixer1.7z\" target=\"_blank\">\u4e0b\u8f7d<\/a><\/p>\n<\/div>\n<p>\u5185\u6709\u7a0b\u5e8f\u548c\u6e90\u4ee3\u7801\uff0c32\u4f4d\u7cfb\u7edf\u7528\u7684\uff0c64\u4f4d\u7cfb\u7edf\u5bf9\u5e94\u7684\u4ee3\u7801\u867d\u7136\u6709\u5199\u4f46\u662f\u662f\u672a\u7ecf\u6d4b\u8bd5\u7684\u2026\u2026\u6211\u6ca1\u6709\u73af\u5883\u3002<\/p>\n<p>memo\uff1a\u90a3\u4e2aID\u5176\u5b9e\u662fEXE\u7684PE\u5934\u91cc\u9762\u7684timestamp\uff08from riatre\uff09<\/p>\n<p>\u66f4\u65b0\uff1a<br \/>\n\u56e0\u4e3a\u65e2\u7136\u77e5\u9053\u4e86\u90a3\u4e2aID\u662f\u4ec0\u4e48\uff0c\u6240\u4ee5\u6211\u5c31\u53c8\u5199\u4e86\u4e2a\u7a0b\u5e8f\uff0c<br \/>\n\u8fd9\u6b21\u53ef\u4ee5\u4e0d\u7528\u5148\u8fd0\u884c\u4e00\u6b21\u7a0b\u5e8f\uff0c\u800c\u662f\u53ef\u4ee5\u76f4\u63a5\u6dfb\u52a0\u7a0b\u5e8f\u4e86<br \/>\n\u4e5f\u6539\u7528C++\u6765\u5199\uff0cC++\u548cATL\uff0c\u6240\u4ee5\u751f\u6210\u7684EXE\u4f53\u79ef\u5f88\u5c0f\u3002<\/p>\n<p>\u70b9\u51fb\u4e0b\u8f7d\uff1a<a href=\"https:\/\/blog.sorayuki.net\/wp-content\/uploads\/2013\/01\/directDrawFix.7z\">directDrawFix<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e1d\u56fd\u65f6\u4ee32\u5728Windows7\u4e0b\u9762\u8fd0\u884c\u7684\u65f6\u5019\uff0c\u4f1a\u51fa\u73b0\u989c\u8272\u4e0d\u6b63\u786e\u7684\u95ee\u9898\uff1a\u8349\u5730\u672c\u6765\u5e94\u8be5\u662f\u7eff\u7684\uff0c\u4f46\u662f\u5b83\u5374\u5145\u6ee1\u4e86\u6591\u6591\u70b9\u70b9 &hellip; <a href=\"https:\/\/blog.sorayuki.net\/?p=212\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u89e3\u51b3\u5e1d\u56fd\u65f6\u4ee32\u5728Win7\u4e0b\u989c\u8272\u4e0d\u6b63\u786e\u7684\u95ee\u9898<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-212","post","type-post","status-publish","format-standard","hentry","category-15"],"_links":{"self":[{"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=\/wp\/v2\/posts\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=212"}],"version-history":[{"count":0,"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=\/wp\/v2\/posts\/212\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sorayuki.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}