MFC_Post 이벤트 만들
1. 이벤트 함수 만들기
클래스 마법사를 통해 DefWindowProc 함수 를 추가한다
LRESULT CMfcOpencvTemplateDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다.
return CDialogEx::DefWindowProc(message, wParam, lParam);
}
2. 이벤트 명령어 추가한다
사용자가 사용할수 있는 명령어 보다 커야 하므로 WM_USER +1 형식으로 추가한다.
#define PostMessageLED WM_USER+1
3. 메세지 호출한다.
PostMessage(PostMessageLED);
4. 가상함수에서 메세지에 따른 기능을 수행한다
LRESULT CMfcOpencvTemplateDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다.
if (message == PostMessageLED)
{
SendSerial_Device("01ON1");
waitKey(10);
SendSerial_Device("01ON0");
}
return CDialogEx::DefWindowProc(message, wParam, lParam);
}
5. 추가 메시지 파라미터
#define UM_MSG_SEND WM_USER+100
// Generated message map functions
//AFX_MSG
afx_msg LRESULT OnMessage(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(CMsgTestDlg, CDialog)
//AFX_MSG_MAP
ON_MESSAGE(UM_MSG_SEND, OnMessage)
END_MESSAGE_MAP()
// Send
void CMsgTestDlg::OnButton1()
{
CString str = "Hello";
SendMessage(UM_MSG_SEND, NULL, LPARAM(&str));
char* str_message;
str_message = "파라미터 적용 확인";
pDlg->PostMessage(PostMessageLOG,0,(LPARAM)str_message);
}
// Receive
LRESULT CMsgTestDlg::OnMessage(WPARAM wParam, LPARAM lParam)
{
CString* str = (CStirng*)lParam;
AfxMessageBox(*str);
//char 복사
char destination[150];
strcpy(destination, (char*)lParam);
write_log_file(destination);
}
참고 링크
https://luckygg.tistory.com/174
- 파라미터 관련 https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=picbuddy&logNo=80107681082
댓글남기기