{"id":182,"date":"2009-09-02T16:47:13","date_gmt":"2009-09-02T08:47:13","guid":{"rendered":"http:\/\/115.29.108.60\/?p=182"},"modified":"2011-09-26T21:37:26","modified_gmt":"2011-09-26T13:37:26","slug":"lockworkstation","status":"publish","type":"post","link":"http:\/\/115.29.108.60\/?p=182","title":{"rendered":"LockWorkStation"},"content":{"rendered":"<p>\u4eca\u5929\u5728\u7f51\u4e0a\u67e5\u6302\u673a\u9501\u7684\u539f\u7406\uff0c\u5176\u4e2d\u6709\u4eba\u63d0\u5230\u4e86\u4e00\u4e2a\u51fd\u6570LockWorkStation\u3002<\/p>\n<p>\u67e5\u770bSDK\uff0c\u5176\u539f\u578b\u5982\u4e0b\uff1a<\/p>\n<p>BOOL WINAPI LockWorkStation(void);<\/p>\n<p>\u770b\u4f3c\u5f88\u7b80\u5355\u7684\u51fd\u6570\uff0c\u771f\u6b63\u7528\u8d77\u6765\u5374\u4e0d\u662f\u90a3\u4e48\u5bb9\u6613\u3002\u8d34\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>#include &lt;windows.h&gt;<\/p>\n<p>int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)<br \/>\n{<br \/>\n\u00a0if(IDOK == MessageBox(NULL, TEXT(&#8220;\u60a8\u786e\u5b9a\u8981\u9501\u5b9a\u8ba1\u7b97\u673a\u5417\uff1f&#8221;), TEXT(&#8220;\u9501\u5b9a\u8ba1\u7b97\u673a&#8221;), MB_OKCANCEL | MB_ICONQUESTION))<br \/>\n\u00a0{<br \/>\n\u00a0\u00a0if(!LockWorkStation())<br \/>\n\u00a0\u00a0{<br \/>\n\u00a0\u00a0\u00a0TCHAR* szError = {0};<br \/>\n\u00a0\u00a0\u00a0wsprintf(szError, &#8220;LockWorkStation failed with %d\\n&#8221;, GetLastError());<br \/>\n\u00a0\u00a0\u00a0MessageBox(NULL, szError, &#8220;Error&#8221;, MB_OK | MB_ICONSTOP);<br \/>\n\u00a0\u00a0}<br \/>\n\u00a0}<br \/>\n\u00a0return 0;<br \/>\n}<\/p>\n<p>\u7f16\u8bd1\uff0c\u5374\u4e0d\u80fd\u901a\u8fc7\u3002\u9519\u8bef\u7adf\u7136\u662f&#8217;LockWorkStation&#8217; was not declared in this scope\uff01\u770bSDK\uff0c\u201cDeclared in Winuser.h; include Windows.h.\u201d\u6ca1\u9519\uff0c\u201cRequires Windows\u00a0Vista, Windows\u00a0XP, or Windows\u00a02000 Professional.\u201d\u6ca1\u9519\uff0clib\u548cdll\u90fd\u6ca1\u9519\u3002\u5230\u5e95\u600e\u4e48\u56de\u4e8b\u5462\uff1f\u8df3\u81f3LockWorkStation\u7684\u5b9a\u4e49\uff0c\u53d1\u73b0\uff1a<\/p>\n<p>#if (_WIN32_WINNT &gt;= 0x0500)<br \/>\nWINUSERAPI BOOL WINAPI LockWorkStation(void);<br \/>\n#endif<\/p>\n<p>\u539f\u6765\u8981\u6c42_WIN32_WINNT \u7684\u5b8f\u5927\u4e8e\u7b49\u4e8e 0x0500\u3002\u4e8e\u662f\u5728#include &lt;windows.h&gt;\u540e\u52a0\u4e0a#define _WIN32_WINNT 0x0500\uff0c\u7f16\u8bd1\uff0c\u8fd8\u662f\u51fa\u9519\uff01\u8fd8\u52a0\u4e0a\u4e86_WIN32_WINNT\u91cd\u590d\u5b9a\u4e49\u7684\u9519\u4e86\u3002<\/p>\n<p>\u6c42\u52a9\u767e\u5ea6\u548c\u8c37\u6b4c\uff0c\u53d1\u73b0\u4e0d\u5c11\u4eba\u9047\u5230\u8fd9\u4e2a\u95ee\u9898\uff0c\u6709\u4eba\u8bf4\u52a0\u4e0a#define\u5c31\u80fd\u6210\u529f\u4e86\uff0c\u6709\u4eba\u8bf4\u8981\u52a0\u5728stdafx.h\u4e2d\u2026\u2026\u4e0d\u8fc7\uff0c\u5168\u662f\u5728MFC\u91cc\u7684\u89e3\u51b3\u65b9\u6cd5\u3002\u6cc4\u6c14\uff0c\u53ea\u80fd\u81ea\u5df1\u7ee7\u7eed\u3002\u67e5\u627e_WIN32_WINNT\u7ed3\u679c\u53d1\u73b0\uff1a<\/p>\n<p>#ifndef WINVER<br \/>\n#define WINVER 0x0400<br \/>\n\/*<br \/>\n\u00a0* If you need Win32 API features newer the Win95 and WinNT then you must<br \/>\n\u00a0* define WINVER before including windows.h or any other method of including<br \/>\n\u00a0* the windef.h header.<br \/>\n\u00a0*\/<br \/>\n#endif<br \/>\n#ifndef _WIN32_WINNT<br \/>\n#define _WIN32_WINNT WINVER<br \/>\n\/*<br \/>\n\u00a0* There may be the need to define _WIN32_WINNT to a value different from<br \/>\n\u00a0* the value of WINVER.\u00a0 I don&#8217;t have any example of why you would do that.<br \/>\n\u00a0* However, if you must then define _WIN32_WINNT to the value required before<br \/>\n\u00a0* including windows.h or any other method of including the windef.h header.<br \/>\n\u00a0*\/<br \/>\n#endif<\/p>\n<p>\u660e\u767d\u4e86\u3002\u539f\u6765_WIN32_WINNT\u88ab\u5b9a\u4e49\u4e3aWINVER\uff0c\u800cWINVER\u53c8\u88ab\u5b9a\u4e49\u4e3a0x0400\uff0c\u800c\u4e14\u8981\u6539\u53d8\u4e24\u4e2a\u7684\u503c\u9700\u8981\u5728#include &lt;windows.h&gt;\u4e4b\u524d\u3002\u628a#define WINVER 0x0500\uff08\u6216\u8005#define\u00a0_WIN32_WINNT 0x0500\uff09\u653e\u5728\u6700\u524d\u9762\uff0c\u7f16\u8bd1\uff0c\u95ee\u9898\u89e3\u51b3\u3002\uff08\u5efa\u8bae\u4f7f\u7528#define WINVER 0x0500\uff0c\u56e0\u4e3a_WIN32_WINNT\u7684\u8bf4\u660e\u4e2d\u8981\u6c42\u5c3d\u91cf\u4fdd\u6301\u548cWINVER\u7684\u4e00\u81f4\u3002\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u5728\u7f51\u4e0a\u67e5\u6302\u673a\u9501\u7684\u539f\u7406\uff0c\u5176\u4e2d\u6709\u4eba\u63d0\u5230\u4e86\u4e00\u4e2a\u51fd\u6570LockWorkStation\u3002 \u67e5\u770bSDK\uff0c\u5176\u539f\u578b\u5982\u4e0b\uff1a B [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-182","post","type-post","status-publish","format-standard","hentry","category-windows"],"_links":{"self":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=182"}],"version-history":[{"count":2,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/182\/revisions"}],"predecessor-version":[{"id":862,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/182\/revisions\/862"}],"wp:attachment":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=182"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}