mausposition innerhalb eines fenster ausgeben
-
hallo.
ich bin ein anfänger in mfc und möchte in einem fenster immer die aktuelle maus position ausgeben.
wie declariere ich die OnMouseMove in message map ?
hier der code:// The application class class CBannerHelloApp : public CWinApp { public: virtual BOOL InitInstance(); }; // The main window of the application class CMainWindow : public CFrameWnd { private: CString message; int nX, nX2, nWidth; CFont font; CString maus_pos; CPoint m_CMousePos; public: CMainWindow(); protected: afx_msg void OnPaint(); afx_msg void OnMouseMove( UINT nFlags, CPoint point ); DECLARE_MESSAGE_MAP() };
#include <afxwin.h> #include <limits.h> #include "BannerHello.h" // The singleton application object CBannerHelloApp theApp; ///////////////////////////////////////////////////////////////////////// // CBannerHelloApp member functions BOOL CBannerHelloApp::InitInstance () { m_pMainWnd = new CMainWindow; m_pMainWnd->ShowWindow (m_nCmdShow); m_pMainWnd->UpdateWindow (); return TRUE; } ///////////////////////////////////////////////////////////////////////// // CMainWindow message map and member functions BEGIN_MESSAGE_MAP(CMainWindow, CFrameWnd) ON_WM_PAINT() OnMouseMove() END_MESSAGE_MAP() CMainWindow::CMainWindow () { Create (NULL, _T ("BannerHello")); message = _T("Hello MFC!"); } void CMainWindow::OnPaint () { char buf[10]; CRect rect; CPaintDC dc (this); GetClientRect(rect); //dc.DrawText(message,-1,rect, DT_SINGLELINE| DT_CENTER| DT_VCENTER); //dc.DrawText(maus_pos,-1,rect, DT_SINGLELINE| DT_CENTER| DT_VCENTER); // Mausposition fuer Ausgabe in ASCII wandeln wsprintf(buf,"X:%d, Y:%d",m_CMousePos.x,m_CMousePos.y); // Mausposition ausgeben dc.TextOut(10,10,buf,strlen(buf)); } void CMainWindow::OnMouseMove( UINT nFlags, CPoint point ) { m_CMousePos = point; // und Fensterinhalt neu darstellen Invalidate(); }
kennt ihr ein online buch oder guten tutorial für anfänger
dankejoy
-
Du benutzt doch sicher das Visual Studio.
Dann wuerde ich dir empfehlen fuer solche Sachen den Klassenassistenten zu benutzen (strg+w).Gute Buecher sind die MSDN und vll. noch "MFC (oder Visual C) in 21 Tagen".