triumphost 120 Posting Whiz

I have the following code which tracks the mouse movements on a control and if the mouse hovers it will beep. I want it to draw specific images on Hover and when it leaves, draw a different image. How can I accomplish this?

I subclassed the buttons to figure out if the mouse is over them and if the mouse clicked them but now I need to know how to paint. I've tried WM_PAINT events and WM_DRAWITEM events but I cannot figure out why it doesn't draw and I think I'm just drawing wrong. Does anyone have an example of how I can accomplish this task?

In my main WindowProc, I loaded the images already, I just need to know how to blit them to the specific button.

void TrackMouse(HWND hwnd)
{
    TRACKMOUSEEVENT tme;
    tme.cbSize = sizeof(TRACKMOUSEEVENT);
    tme.dwFlags = TME_HOVER | TME_LEAVE;
    tme.dwHoverTime = 1;
    tme.hwndTrack = hwnd;
    TrackMouseEvent(&tme);
}

LRESULT CALLBACK OwnerDrawButtonProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    static WNDPROC OrigBtnProc = (WNDPROC)(static_cast<LONG_PTR>(GetWindowLongPtr(hwnd, GWLP_USERDATA)));
    switch (uMsg)
    {
        case WM_MOUSEMOVE:
        {
            if (!MouseEntered)
            {
                TrackMouse(hwnd);
            }
            return CallWindowProc(OrigBtnProc, hwnd, uMsg, wParam, lParam);
        }
        break;

        case WM_MOUSEHOVER:
            MouseEntered = true;
            MessageBeep(0);  //After Beeping, I want to draw Image1.
            return CallWindowProc(OrigBtnProc, hwnd, uMsg, wParam, lParam);
        break;

        case WM_MOUSELEAVE:
            MouseEntered = false; //If the mouse Leaves, I want to draw Image2.
            return CallWindowProc(OrigBtnProc, hwnd, uMsg, wParam, lParam);
        break;

        default:
            return CallWindowProc(OrigBtnProc, hwnd, uMsg, wParam, lParam);
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.