Fenhler bei PostMessage
-
hi,
ich weiss nicht was da falsch ist, ich send aus einem thread eine PostMessage an den Hauptdialog: CClient_mfc_02_Dlg ...
cu
Haeder-Datei: --------------------------------------------------------- class CClient_mfc_02Dlg : public CDialog { .......... .......... // Implementation protected: CMenu m_Popup; HICON m_hIcon; // Generated message map functions //{{AFX_MSG(CClient_mfc_02Dlg) virtual BOOL OnInitDialog(); ............... ............... afx_msg void OnMessage(int i, LPSTR lparam); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; Cpp-Datei: --------------------------------------------------------- global: #define WM_MSG_RECEIVED (WM_USER + 1) BEGIN_MESSAGE_MAP(CClient_mfc_02Dlg, CDialog) ..... ..... ON_MESSAGE(WM_MSG_RECEIVED, OnMessage) END_MESSAGE_MAP() hier regt er sich auf bei ON_MESSAGE(....): error C2440: 'static_cast' : cannot convert from 'void (__thiscall CClient_mfc_02Dlg::* )(int,WPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' None of the functions with this name in scope match the target type void CClient_mfc_02Dlg::OnMessage(int i, LPSTR lparam) { .... m_vec[i].ptr_dialog_send_recv->m_edit_msg_recvCtrl.SetWindowText(lparam); } senden der PostMessage: // Message schicken an Hauptdialog PostMessage(h_hauptdialog, WM_MSG_RECEIVED, l, reinterpret_cast<LPARAM>(string_vec[2].c_str())); // string_vec[2] ist der Text der in dialog_send_recv geschrieben werden soll
-
Hi,
void CClient_mfc_02Dlg::OnMessage(int i, LPSTR lparam) { .... m_vec[i].ptr_dialog_send_recv->m_edit_msg_recvCtrl.SetWindowText(lparam); }
muss so aussehen:
LRESULT CClient_mfc_02Dlg::OnMessage(WPARAM wp, LPARAM lp) { .... m_vec[i].ptr_dialog_send_recv->m_edit_msg_recvCtrl.SetWindowText(lparam); }
im header:
afx_msg LRESULT OnMessage(WPARAM wp, LPARAM lp);
Gruss
EB
-
michael1 schrieb:
m_vec[i].ptr_dialog_send_recv->m_edit_msg_recvCtrl.SetWindowText(lparam);
...du schreibst die Wörter aus, nimmst richtig lange Bezeichner, oder machst es ganz kurz. So ist das Mist.
-
hi,
habs geändert...aber funzt noch nicht;-(cpp-Datei: ------------------------------ gobale var: HWND h_HauptdialogDlg; die message map: BEGIN_MESSAGE_MAP(Client_HauptdialogDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_NOTIFY(NM_RCLICK, IDC_ListControl_LIST1, OnNMRclickList1) ON_NOTIFY(NM_CUSTOMDRAW, IDC_ListControl_LIST1, OnNMCustomdrawList1) ON_MESSAGE(WM_MSG_RECEIVED, On_Create_Open_MessageDlg) END_MESSAGE_MAP() error C2440: 'static_cast' : cannot convert from 'void (__thiscall Client_HauptdialogDlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' BOOL Client_HauptdialogDlg::OnInitDialog() { h_HauptdialogDlg = GetSafeHwnd(); ..... } so sende ich die POSTMESSAGE aus dem thread: unsigned int l = 10; PostMessage(h_HauptdialogDlg, WM_MSG_RECEIVED, l, l); // funktion die von PostMessage aufgerufen wird: void Client_HauptdialogDlg::On_Create_Open_MessageDlg(WPARAM wp, LPARAM lp) { cout << "PostMessage erfolgreich" << endl; cout << "Client_HauptdialogDlg::On_Create_Open_MessageDlg" << endl; } Haeder-Datei: ------------------------------ class Client_HauptdialogDlg : public CDialog { // Konstruktion public: Client_HauptdialogDlg(CWnd* pParent = NULL); // Standardkonstruktor // Dialogfelddaten enum { IDD = IDD_CLIENT_HAUPTDIALOG_DIALOG }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV-Unterstützung // Implementierung protected: afx_msg HCURSOR OnQueryDragIcon(); DECLARE_MESSAGE_MAP() public: afx_msg void On_Create_Open_MessageDlg(WPARAM wp, LPARAM lp); };
-
Hi,
hast du nicht!
michael1 schrieb:
void Client_HauptdialogDlg::On_Create_Open_MessageDlg(WPARAM wp, LPARAM lp) { cout << "PostMessage erfolgreich" << endl; cout << "Client_HauptdialogDlg::On_Create_Open_MessageDlg" << endl; }
ich schrieb:
LRESULT CClient_mfc_02Dlg::OnMessage(WPARAM wp, LPARAM lp) { .... m_vec[i].ptr_dialog_send_recv->m_edit_msg_recvCtrl.SetWindowText(lparam); }
Zudem ist es absolut wichtig, die Meldungen des Compilers zu verstehen.
Compiler schrieb:
error C2440: 'static_cast' : cannot convert from 'void (__thiscall Client_HauptdialogDlg:: )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd:: )(WPARAM,LPARAM)'
Das ist eigentlich eine eindeutige Beschreibung deines Fehlers.
Gruss
EB