{"id":161,"date":"2009-08-11T09:12:32","date_gmt":"2009-08-11T01:12:32","guid":{"rendered":"http:\/\/115.29.108.60\/?p=161"},"modified":"2011-09-26T21:36:34","modified_gmt":"2011-09-26T13:36:34","slug":"win%e9%aa%a8%e5%b9%b2%e4%bb%a3%e7%a0%81-2","status":"publish","type":"post","link":"http:\/\/115.29.108.60\/?p=161","title":{"rendered":"Win\u9aa8\u5e72\u4ee3\u7801"},"content":{"rendered":"<p>#include <windows .h>\/\/Windows\u7a0b\u5e8f\u8bbe\u8ba1\u5934\u6587\u4ef6<\/p>\n<p>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);\/\/\u7a97\u53e3\u6d88\u606f\u5904\u7406\u7a0b\u5e8f\uff0c\u56fa\u5b9a\u5f62\u5f0f\u3002<\/p>\n<p>int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)\/\/Windows\u7a0b\u5e8f\u5165\u53e3<br \/>\n{<br \/>\n\tstatic TCHAR szAppName[] = TEXT(&#8220;HelloWin&#8221;);<br \/>\n\tHWND hwnd;\/\/\u7a97\u53e3\u53e5\u67c4<br \/>\n\tWNDCLASS wndclass;\/\/\u7a97\u53e3\u7c7b\u522b\u7ed3\u6784<br \/>\n\tMSG msg;\/\/\u6d88\u606f\u7ed3\u6784<br \/>\n\t\/\/\u8bbe\u7f6e\u7a97\u53e3\u7c7b\u522b\u7ed3\u6784<br \/>\n\twndclass.style = CS_HREDRAW | CS_VREDRAW;\/\/\u7a97\u53e3\u7c7b\u522b\u6837\u5f0f\u3002CS_HREDRAW\u6c34\u5e73\u65b9\u5411\u3001CS_VREDRAW\u5782\u76f4\u65b9\u5411\u5927\u5c0f\u6539\u53d8\u65f6\uff0c\u7a97\u53e3\u91cd\u7ed8\u3002<br \/>\n\twndclass.lpfnWndProc = WndProc;\/\/\u8bbe\u5b9aWndProc\u4e3a\u6b64\u7a97\u53e3\u7c7b\u522b\u7684\u7a97\u53e3\u6d88\u606f\u5904\u7406\u7a0b\u5e8f<br \/>\n\t\/\/\u9884\u7559\u989d\u5916\u7a7a\u95f4<br \/>\n\twndclass.cbClsExtra = 0;<br \/>\n\twndclass.cbWndExtra = 0;<br \/>\n\t\/\/<br \/>\n\twndclass.hInstance = hInstance;\/\/\u7a0b\u5e8f\u6267\u884c\u7684\u5b9e\u4f53\u53e5\u67c4<br \/>\n\twndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);\/\/\u52a0\u8f7d\u3001\u8bbe\u7f6e\u56fe\u6807<br \/>\n\twndclass.hCursor = LoadCursor(NULL, IDC_ARROW);\/\/\u52a0\u8f7d\u3001\u8bbe\u7f6e\u9f20\u6807\u5149\u6807<br \/>\n\twndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);\/\/\u80cc\u666f\u8272<br \/>\n\twndclass.lpszMenuName = NULL;\/\/\u83dc\u5355<br \/>\n\twndclass.lpszClassName = szAppName;\/\/\u7a97\u53e3\u7c7b\u522b\u540d<br \/>\n\t\/*RegisterClass\u51fd\u6570\u53ea\u6709\u4e00\u4e2a\u53c2\u6570\uff0c\u5373\u6307\u5411WNDCLASS\u7ed3\u6784\u7684\u6307\u9488\u3002<br \/>\n\t  \u5b9e\u9645\u4e0a\uff0cRegisterClassA\u51fd\u6570\u5c06\u83b7\u5f97\u4e00\u4e2a\u6307\u5411WNDCLASSA\u7ed3\u6784\u7684\u6307\u9488\uff0c\u800cRegisterClassW\u51fd\u6570\u5c06\u83b7\u5f97\u4e00\u4e2a\u6307\u5411WNDCLASSW\u7ed3\u6784\u7684\u6307\u9488\u3002<br \/>\n\t  \u7a0b\u5e8f\u8981\u4f7f\u7528\u54ea\u4e2a\u51fd\u6570\u6765\u6ce8\u518c\u7a97\u53e3\u7c7b\u522b\uff0c\u53d6\u51b3\u4e8e\u53d1\u9001\u7ed9\u7a97\u53e3\u7684\u6d88\u606f\u5305\u542bASCII\u6587\u5b57\u8fd8\u662fUnicode\u6587\u5b57\u3002<\/p>\n<p>      \u73b0\u5728\u6709\u4e00\u4e2a\u95ee\u9898\uff1a\u5982\u679c\u7528\u5b9a\u4e49\u7684UNICODE\u6807\u8bc6\u7b26\u7f16\u8bd1\u4e86\u7a0b\u5e8f\uff0c\u7a0b\u5e8f\u5c06\u547c\u53ebRegisterClassW\u3002<br \/>\n\t  \u8be5\u7a0b\u5e8f\u53ef\u4ee5\u5728Microsoft Windows NT\u4e2d\u6267\u884c\u826f\u597d\u3002<br \/>\n\t  \u4f46\u5982\u679c\u6b64\u7a0b\u5e8f\u5728Windows 98\u4e0a\u6267\u884c\uff0cRegisterClassW\u51fd\u6570\u5e76\u672a\u771f\u5730\u88ab\u6267\u884c\u5230\u3002\u51fd\u6570\u6709\u4e00\u4e2a\u8fdb\u5165\u70b9\uff0c\u4f46\u51fd\u6570\u547c\u53eb\u540e\u53ea\u4f20\u56de0\uff0c\u8868\u660e\u9519\u8bef\u3002<\/p>\n<p>\t  \u7531\u4e8eMessageBoxW\u662f\u53ef\u5728Windows 98\u73af\u5883\u4e0b\u6267\u884c\u7684\u51e0\u4e2aUnicode\u51fd\u6570\u4e4b\u4e00\uff0c\u6240\u4ee5\u4e0b\u9762\u8fc7\u7a0b\u5176\u6267\u884c\u6b63\u5e38\u3002<br \/>\n\t*\/<br \/>\n\tif(!RegisterClass(&#038;wndclass))\/\/\u6ce8\u518c\u7a97\u53e3\u7c7b\u522b<br \/>\n\t{<br \/>\n\t\tMessageBox(NULL, TEXT(&#8220;This program requires Windows NT!&#8221;), szAppName, MB_ICONERROR);<br \/>\n\t\treturn 0;<br \/>\n\t}<br \/>\n\t\/\/CreateWindow\u53d1\u9001WM_CREATE\u6d88\u606f<br \/>\n\thwnd = CreateWindow(szAppName,\t\/\/ window class name<br \/>\n        TEXT (&#8220;The Hello Program&#8221;),\t\/\/ window caption<br \/>\n        WS_OVERLAPPEDWINDOW,\t\/\/ window style<br \/>\n\t\tCW_USEDEFAULT,\t\/\/ initial x position<br \/>\n\t\tCW_USEDEFAULT,\t\/\/ initial y position<br \/>\n\t\tCW_USEDEFAULT,\t\/\/ initial x size<br \/>\n\t\tCW_USEDEFAULT,\t\/\/ initial y size<br \/>\n\t\tNULL,\t\/\/ parent window handle<br \/>\n\t\tNULL,\t\/\/ window menu handle<br \/>\n\t\thInstance,\t\/\/ program instance handle<br \/>\n\t\tNULL) ;\t\/\/ creation parameters<br \/>\n\tShowWindow(hwnd, iCmdShow);\/\/\u663e\u793a\u7a97\u53e3<br \/>\n\tUpdateWindow(hwnd);\/\/\u66f4\u65b0\u7a97\u53e3\u3002\u53d1\u9001WM_PAINT\u6d88\u606f\u91cd\u7ed8\u3002<br \/>\n\t\/\/\u6d88\u606f\u5faa\u73af<br \/>\n\twhile(GetMessage(&#038;msg, NULL, 0, 0))<br \/>\n\t{<br \/>\n\t\tTranslateMessage(&#038;msg);<br \/>\n\t\tDispatchMessage(&#038;msg);<br \/>\n\t}<br \/>\n\treturn msg.wParam;<br \/>\n}<\/p>\n<p>LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)<br \/>\n{<br \/>\n\tHDC hdc;<br \/>\n\tPAINTSTRUCT ps;<br \/>\n\tRECT rect;<br \/>\n\tswitch(message)<br \/>\n\t{<br \/>\n\t\tcase WM_CREATE:<br \/>\n\t\t\tPlaySound(TEXT(&#8220;hellowin.wav&#8221;), NULL, SND_FILENAME | SND_ASYNC);<br \/>\n\t\t\treturn 0;<br \/>\n\t\tcase WM_PAINT:<br \/>\n\t\t\thdc = BeginPaint(hwnd, &#038;ps);<br \/>\n\t\t\tGetClientRect(hwnd, &#038;rect);<br \/>\n\t\t\tDrawText(hdc, TEXT(&#8220;Hello Windows XP!&#8221;), -1, &#038;rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);<br \/>\n\t\t\tEndPaint(hwnd, &#038;ps);<br \/>\n\t\t\treturn 0;<br \/>\n\t\tcase WM_DESTROY:<br \/>\n\t\t\tPostQuitMessage(0);<br \/>\n\t\t\treturn 0;<br \/>\n\t}<br \/>\n\treturn DefWindowProc(hwnd, message, wParam, lParam);<br \/>\n}<\/windows><\/p>\n","protected":false},"excerpt":{"rendered":"<p>#include \/\/Windows\u7a0b\u5e8f\u8bbe\u8ba1\u5934\u6587\u4ef6 LRESULT CALLBACK WndProc(HWND [&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-161","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\/161","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=161"}],"version-history":[{"count":2,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":858,"href":"http:\/\/115.29.108.60\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions\/858"}],"wp:attachment":[{"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/115.29.108.60\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}