{"id":2459,"date":"2010-10-06T11:21:36","date_gmt":"2010-10-06T03:21:36","guid":{"rendered":"http:\/\/www.killtest.com.tw\/?p=2459"},"modified":"2010-10-06T11:22:29","modified_gmt":"2010-10-06T03:22:29","slug":"mfc","status":"publish","type":"post","link":"https:\/\/www.killtest.com.tw\/?p=2459","title":{"rendered":"MFC\u5b78\u7fd2\u7b46\u8a18\u4e4b\u591a\u7dda\u7a0b\u7684\u61c9\u7528"},"content":{"rendered":"<p>\u58f9. \u4f7f\u7528\u7dda\u7a0b\u6b65\u9a5f\uff1a<\/p>\n<p>\u3000\u30001. \u5b9a\u7fa9\u7dda\u7a0b\u51fd\u6578\u50b3\u905e\u53c3\u6578\u7d50\u69cb<\/p>\n<p>\u3000\u3000\u5982\uff1a<\/p>\n<p>\u3000\u3000typedef struct tagTHREADParmS<\/p>\n<p>\u3000\u3000{<\/p>\n<p>\u3000\u3000\/\/CString content;<\/p>\n<p>\u3000\u3000HWND hwnd;<\/p>\n<p>\u3000\u3000int window;<\/p>\n<p>\u3000\u3000int state;<\/p>\n<p>\u3000\u3000Monitor *mm;<\/p>\n<p>\u3000\u3000int thread_id;<\/p>\n<p>\u3000\u3000}THREADParmS;<\/p>\n<p>\u3000\u30002. \u5b9a\u7fa9\u7dda\u7a0b\u51fd\u6578\uff1a<\/p>\n<p>\u3000\u3000\u5982\uff1a<\/p>\n<p>\u3000\u3000UINT read(LPVOID pParam)<\/p>\n<p>\u3000\u3000{<\/p>\n<p>\u3000\u3000THREADPARMS *p=(THREADParmS*)pParam;<\/p>\n<p>\u3000\u3000HWND hwnd=p-&gt;hwnd;<\/p>\n<p>\u3000\u3000int edit=p-&gt;window;<\/p>\n<p>\u3000\u3000Monitor *mon=p-&gt;mm;<\/p>\n<p>\u3000\u3000mon-&gt;add_reader(p);<\/p>\n<p>\u3000\u3000SetDlgItemText(hwnd,p-&gt;state,&#8221;\u6b63\u5728\u8b80\u53d6&#8221;);<\/p>\n<p>\u3000\u3000Sleep(2000);<\/p>\n<p>\u3000\u3000char * str=new char[1000];<\/p>\n<p>\u3000\u3000GetDlgItemText(hwnd,IDC_DISPLAY,str,1000);<\/p>\n<p>\u3000\u3000SetDlgItemText(hwnd,edit,str);<\/p>\n<p>\u3000\u3000mon-&gt;complete_reader(p);<\/p>\n<p>\u3000\u3000SetDlgItemText(hwnd,p-&gt;state,&#8221;\u8b80\u53d6\u5b8c\u6210&#8221;);<\/p>\n<p>\u3000\u3000delete p;<\/p>\n<p>\u3000\u3000return 0;<\/p>\n<p>\u3000\u3000}<\/p>\n<p>\u3000\u30003. \u555f\u52d5\u7dda\u7a0b<\/p>\n<p>\u3000\u3000\u5982\uff1a<\/p>\n<p>\u3000\u3000THREADPARMS *ptp=new THREADParmS;\/\/\u521d\u59cb\u5316\u7dda\u7a0b\u53c3\u6578\u7d50\u69cb<\/p>\n<p>\u3000\u3000ptp-&gt;hwnd=m_hWnd;\/\/\u5c0dPTP\u7d50\u69cb\u8ce6\u503c<\/p>\n<p>\u3000\u3000\/\/ptp-&gt;content=str;<\/p>\n<p>\u3000\u3000ptp-&gt;mm=mm;<\/p>\n<p>\u3000\u3000ptp-&gt;window=window;<\/p>\n<p>\u3000\u3000ptp-&gt;thread_id=thead_id;<\/p>\n<p>\u3000\u3000ptp-&gt;state=state;<\/p>\n<p>\u3000\u3000AfxBeginThread(read,ptp);\/\/\u555f\u52d5\u7dda\u7a0b<\/p>\n<p>\u3000\u3000\u4e8c. \u7dda\u7a0b\u7684\u639b\u8d77\u548c\u91cd\u555f<\/p>\n<p>\u3000\u30001. \u639b\u8d77\u7dda\u7a0b<\/p>\n<p>\u3000\u3000SuspendThread(HANDLE);<\/p>\n<p>\u3000\u3000\u8a3b\u610f\uff1a\u7dda\u7a0b\u66ab\u505c\u5f8c\u4fbf\u505c\u6b62\u904b\u884c\uff0c\u4e5f\u5c31\u662f\u8aaa\u7dda\u7a0b\u53ef\u4ee5\u81ea\u5df1\u639b\u8d77\u81ea\u5df1\uff0c\u4f46\u7121\u6cd5\u81ea\u5df1\u559a\u9192\u81ea\u5df1\u3002<\/p>\n<p>\u3000\u30002.\u559a\u9192\u7dda\u7a0b<\/p>\n<p>\u3000\u3000ResumeThread(HANDLE);<\/p>\n<p>\u3000\u3000\u5c0d\u65bcCWinThread \u985e\uff0c\u53ea\u8981\u4f7f\u7528m_hThread\u6210\u54e1\uff0c\u5373\u70baHANDLE\u8b8a\u91cf\u3002<\/p>\n<p>\u3000\u3000\u8d85\u7d1a\u8a3b\u610f\uff1aGetCurrentThread()\u5f97\u5230\u7684\u662f\u58f9\u500b\u7576\u524d\u7684\u7dda\u7a0b\u7684handle\uff0c\u5176\u5be6\u662f\u58f9\u500b\u507dHANDLE\uff0c\u662f\u7576\u524d\u6240\u6709\u904b\u884c\u7684\u7dda\u7a0b\u74b0\u5883\u7684HANDLE\u3002\u7121\u6cd5\u76f4\u63a5\u4f7f\u7528\u6b64\u51fd\u6578\u5f97\u5230\u7684handle\u559a\u9192\u7dda\u7a0b\u3002\u4f46\u662f\u4f7f\u7528\u58f9\u4e9b\u5176\u4ed6\u51fd\u6578\u5f8c\u53ef\u4ee5\uff0c\u6211\u6c92\u6709\u5617\u8a66\u3002<\/p>\n<p>\u3000\u3000\u9084\u6709\uff0cMFC\u4e2d\u7684\u7dda\u7a0b\u662f\u4e0d\u5b89\u5168\u7684\u3002\u4e0d\u5b89\u5168\u7684\u542b\u7fa9\u662f\uff1a\u7576\u5169\u500b\u7dda\u7a0b\u540c\u6642\u8a2a\u554f\u540c\u58f9\u500b\u81e8\u754c\u8cc7\u6e90\u6642\uff0c\u7cfb\u7d71\u6703\u5141\u8a31\u3002\u9019\u5c31\u6703\u7522\u751f\u58f9\u4e9b\u4e0d\u53ef\u9810\u77e5\u7684\u932f\u8aa4\u3002<\/p>\n<p>\u3000\u3000\u89e3\u6c7a\u7684\u65b9\u6cd5\u6642\u4f7f\u7528\u9032\u7a0b\u7684\u540c\u6b65\u985e\u6216\u8005\u81ea\u5df1\u7de8\u5beb\u4ee3\u78bc\u5be6\u73fe\u7dda\u7a0b\u4e92\u65a5\u8a2a\u554f\u548c\u540c\u6b65\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u58f9. \u4f7f\u7528\u7dda\u7a0b\u6b65\u9a5f\uff1a \u3000\u30001. \u5b9a\u7fa9\u7dda\u7a0b\u51fd\u6578\u50b3\u905e\u53c3\u6578\u7d50\u69cb \u3000\u3000\u5982\uff1a \u3000\u3000typedef struct tagTHREADParmS \u3000\u3000{ \u3000\u3000\/\/CString content; \u3000\u3000HWND hwnd; \u3000\u3000int window; \u3000\u3000int state; \u3000\u3000Monitor *mm; \u3000\u3000int thread_id; \u3000\u3000}THREADParmS; \u3000\u30002. \u5b9a\u7fa9\u7dda\u7a0b\u51fd\u6578\uff1a \u3000\u3000\u5982\uff1a \u3000\u3000UINT read(LPVOID pParam) \u3000\u3000{ \u3000\u3000THREADPARMS *p=(THREADParmS*)pParam; \u3000\u3000HWND hwnd=p-&gt;hwnd; \u3000\u3000int edit=p-&gt;window; \u3000\u3000Monitor *mon=p-&gt;mm; \u3000\u3000mon-&gt;add_reader(p); \u3000\u3000SetDlgItemText(hwnd,p-&gt;state,&#8221;\u6b63\u5728\u8b80\u53d6&#8221;); \u3000\u3000Sleep(2000); \u3000\u3000char * str=new char[1000]; \u3000\u3000GetDlgItemText(hwnd,IDC_DISPLAY,str,1000); \u3000\u3000SetDlgItemText(hwnd,edit,str); \u3000\u3000mon-&gt;complete_reader(p); \u3000\u3000SetDlgItemText(hwnd,p-&gt;state,&#8221;\u8b80\u53d6\u5b8c\u6210&#8221;); \u3000\u3000delete p; \u3000\u3000return 0; \u3000\u3000} \u3000\u30003. \u555f\u52d5\u7dda\u7a0b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[708,710,709],"class_list":["post-2459","post","type-post","status-publish","format-standard","hentry","category-killtest","tag-mfc","tag-710","tag-709"],"_links":{"self":[{"href":"https:\/\/www.killtest.com.tw\/index.php?rest_route=\/wp\/v2\/posts\/2459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.killtest.com.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.killtest.com.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.killtest.com.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.killtest.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2459"}],"version-history":[{"count":3,"href":"https:\/\/www.killtest.com.tw\/index.php?rest_route=\/wp\/v2\/posts\/2459\/revisions"}],"predecessor-version":[{"id":2462,"href":"https:\/\/www.killtest.com.tw\/index.php?rest_route=\/wp\/v2\/posts\/2459\/revisions\/2462"}],"wp:attachment":[{"href":"https:\/\/www.killtest.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.killtest.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.killtest.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}