Tag Archives: news

MFC:: error C2065: “IDD_DIALOG1”: undeclared identifier Sending and handling custom messages in MFC threads

Just add the resource header file.

#include "Resource.h"

Send message in MFC thread

1. Write the meaning first and accept it

#define WM_SET_FOCUS WM_USER+100



BEGIN_MESSAGE_MAP(CWriteSnDlg, CDialogEx)
    //
	ON_MESSAGE(WM_SET_FOCUS, OnSetFocus)
END_MESSAGE_MAP()



	afx_msg LRESULT OnSetFocus(WPARAM wP, LPARAM lp);


LRESULT CWriteSnDlg::OnSetFocus(WPARAM wP, LPARAM lp)
{
	UNREFERENCED_PARAMETER(wP);
	UNREFERENCED_PARAMETER(lp);
	GetDlgItem(IDC_EDIT1)->SetFocus();
	return 0;
}

2. Send message

UINT  WriteSNProc(LPVOID  lParam){
    CWriteSnDlg *pWnd = (CWriteSnDlg *)lParam; 
    PostMessage(*pWnd,WM_SET_FOCUS, NULL,NULL);
    //SendMessage(*pWnd,WM_SET_FOCUS, NULL,NULL);
}



 PostMessage(this,WM_SET_FOCUS, NULL,NULL);