How to change mouse cursor when move mouse pass the button?
-
How to change mouse cursor to "IDC_IBEAM" when move mouse pass the button? This is my easy win32 code, please edit or modify this code below. Thank you. #include "afxwin.h" #define IDC_BUTTON1 100 class CApp:public CWinApp{ public: virtual BOOL InitInstance(); }; CApp app; class CWin:public CFrameWnd{ CButton *button; public: CWin(); ~CWin(); }; BOOL CApp::InitInstance(){ m_pMainWnd=new CWin(); m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return TRUE; }; CWin::CWin(){ Create(NULL,"Hello", WS_OVERLAPPEDWINDOW,CRect(0,0,200,200)); button=new CButton(); button->Create("OK", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(50,50,100,100),this,IDC_BUTTON1); } CWin::~CWin(){ delete button; }
-
How to change mouse cursor to "IDC_IBEAM" when move mouse pass the button? This is my easy win32 code, please edit or modify this code below. Thank you. #include "afxwin.h" #define IDC_BUTTON1 100 class CApp:public CWinApp{ public: virtual BOOL InitInstance(); }; CApp app; class CWin:public CFrameWnd{ CButton *button; public: CWin(); ~CWin(); }; BOOL CApp::InitInstance(){ m_pMainWnd=new CWin(); m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return TRUE; }; CWin::CWin(){ Create(NULL,"Hello", WS_OVERLAPPEDWINDOW,CRect(0,0,200,200)); button=new CButton(); button->Create("OK", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(50,50,100,100),this,IDC_BUTTON1); } CWin::~CWin(){ delete button; }
Don't quote me on this BUT I think you could try setting the cursor using SetCursor in OnSetCursor - WM_SETCURSOR.
-
How to change mouse cursor to "IDC_IBEAM" when move mouse pass the button? This is my easy win32 code, please edit or modify this code below. Thank you. #include "afxwin.h" #define IDC_BUTTON1 100 class CApp:public CWinApp{ public: virtual BOOL InitInstance(); }; CApp app; class CWin:public CFrameWnd{ CButton *button; public: CWin(); ~CWin(); }; BOOL CApp::InitInstance(){ m_pMainWnd=new CWin(); m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return TRUE; }; CWin::CWin(){ Create(NULL,"Hello", WS_OVERLAPPEDWINDOW,CRect(0,0,200,200)); button=new CButton(); button->Create("OK", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(50,50,100,100),this,IDC_BUTTON1); } CWin::~CWin(){ delete button; }
There are two possible ways of implementing this (that I know of). Both of them include trapping either one or both of the MOUSEMOVE or SETCURSOR messages. You can either trap them at level of the main FrameWnd or in the Button (I would personally prefer to subclass the Button and trap it in there so I could reuse that new button in other parts of my code). In the case of trapping it in the FrameWnd (probably trapping MOUSEMOVE after you know the cursor is in the FrameWnd - using SETCURSOR to set some flag) you then need to work out if the mouse is over the button to change to the IBEAM cursor - as well as not over the button to change it back!!). There are probably other pitfalls to worry about that my simple explanation doesn't cover but they would be the two basic approaches to consider. Regards, Gary Menzel ================== The original message was: How to change mouse cursor to "IDC_IBEAM" when move mouse pass the button?