CBitmapButton mouseover change bitmap? (vc++ 6.0)
-
hi, im sure this question is a regular one. i'm making an app with bitmapbuttons and want to change bitmap on the button when hovering over them can't seem to find any good articles about this subject. heres a code i've been trying out, cant seem to get it to work. //loaded the default button bitmaps in OnInitDialog() m_btn1.LoadBitmaps(IDB_MYBUTTON_DEFAULT); //this works and sets the bitmaps on my buttons //something like this is what i want to do void CMyDlg::OnMouseMove(UINT nFlags, CPoint point) { CRect m_Rect; m_btn1.GetWindowRect(m_Rect); if (m_Rect.PtInRect(point)) { //when mouse is over button change to this bitmap m_btn1.LoadBitmaps(IDB_MYBUTTON_OVER); } } any solutions? tanx :-)
-
hi, im sure this question is a regular one. i'm making an app with bitmapbuttons and want to change bitmap on the button when hovering over them can't seem to find any good articles about this subject. heres a code i've been trying out, cant seem to get it to work. //loaded the default button bitmaps in OnInitDialog() m_btn1.LoadBitmaps(IDB_MYBUTTON_DEFAULT); //this works and sets the bitmaps on my buttons //something like this is what i want to do void CMyDlg::OnMouseMove(UINT nFlags, CPoint point) { CRect m_Rect; m_btn1.GetWindowRect(m_Rect); if (m_Rect.PtInRect(point)) { //when mouse is over button change to this bitmap m_btn1.LoadBitmaps(IDB_MYBUTTON_OVER); } } any solutions? tanx :-)
You won't get a WM_MOUSEMOVE message in the dialog when the cursor is moved over a button. You need to check for WM_MOUSEMOVE in the button class. In your button class' OnMouseMove(), the first time it's called when the cursor enters the button, you can use TrackMouseEvent() with the TME_LEAVE flag. Then you'll get a WM_MOUSELEAVE message when the cursor is moved off the button so you can set the bitmaps back to the original. Also, after your LoadBitmaps() calls, you may need to call UpdateWindow() on the button(s) to get them to redraw (maybe not, but if the button bitmaps aren't changing, it's worth a try :)). Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
You won't get a WM_MOUSEMOVE message in the dialog when the cursor is moved over a button. You need to check for WM_MOUSEMOVE in the button class. In your button class' OnMouseMove(), the first time it's called when the cursor enters the button, you can use TrackMouseEvent() with the TME_LEAVE flag. Then you'll get a WM_MOUSELEAVE message when the cursor is moved off the button so you can set the bitmaps back to the original. Also, after your LoadBitmaps() calls, you may need to call UpdateWindow() on the button(s) to get them to redraw (maybe not, but if the button bitmaps aren't changing, it's worth a try :)). Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
tanx, i'll try that! :)