PostThreadMessage <==> Thread Message Map:: ON_THREAD_MESSAGE 因為 CWinApp 繼承 CWinThread // in CxxxApp.h class CxxxApp.h: public CWinApp { public: CkkkApp(); // 覆寫 public: virtual BOOL InitInstance(); void GoBabyGo(WPARAM wP, LPARAM lP); // <<< --- 加入 prototype // 程式碼實作 DECLARE_MESSAGE_MAP() }; // in CxxxApp.cpp 在 CxxxApp class 的 Message-Loop 加上 ON_THREAD_MESSAGE(WM_USER+1,GoBabyGo) BEGIN_MESSAGE_MAP(CkkkApp, CWinApp) ON_COMMAND(ID_HELP, CWinApp::OnHelp) ON_THREAD_MESSAGE(WM_USER+1,GoBabyGo) END_MESSAGE_MAP() void CxxxApp::GoBabyGo(WPARAM wP, LPARAM lParam){ int y=HIWORD(lParam); int x=LOWORD(lParam); } 參考資料: #define WM_THR_CANCEL WM_APP+3 #define WM_THR_START WM_APP+6 class CMyThread : public CWinThread { DECLARE_DYNCREATE(CMyThread) public: void OnEnd(); CWnd * m_pWnd; CMyThread(); virtual ~CMyThread(); void SetWindow(CWnd * wnd); BOOL CMyThread::InitInstance(); int CMyThread::ExitInstance(); protected: DECLARE_MESSAGE_MAP() private: void OnUpdateStatus(WPARAM wP, LPARAM lP); void GoBabyGo(); }; IMPLEMENT_DYNCREATE(CMyThread, CWinThread) CMyThread::CMyThread() { m_pWnd=NULL; } CMyThread::~CMyThread() { } BOOL CMyThread::InitInstance() { return TRUE; } int CMyThread::ExitInstance() { return CMyThread::ExitInstance(); } /************************************************************************ * Add message maps telling the procedures what to do when the * certain messages are received from the windows queue. ************************************************************************/ BEGIN_MESSAGE_MAP(CMyThread, CWinThread) ON_THREAD_MESSAGE(WM_THR_START,GoBabyGo) ON_THREAD_MESSAGE(WM_THR_CANCEL,OnEnd) END_MESSAGE_MAP() void CMyThread::GoBabyGo(){ } void CMyThread::OnEnd(){ }