Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Windows
I'm trying to draw a button based on the images. The button should have 3 pictures:
- 1.png - normal state,
- 2.png - mouse hover state,
- 3.png - mouse down state.
Also in the handler for WM_MOUSEMOVE I set _TrackMouseEvent.
 
Ok. To do that I write the following code in the window procedure:
- For the normal button state:
case WM_PAINT:
{
    PAINTSTRUCT ps;
    BeginPaint(hwnd, &ps);
    Gdiplus::Graphics  *normal_state = new Gdiplus::Graphics(ps.hdc);
    Image *img = new Image(L"d:/images/1.png",false);
    normal_state->DrawImage(img,5,5);
    delete img;
    delete normal_state;
    EndPaint(hwnd, &ps);
}
It works perfectly.
And now I'm trying to to make realization for mouse hover state:
case WM_MOUSEHOVER:
{
    PAINTSTRUCT ps;
    BeginPaint(hwnd,&ps);
    Gdiplus::Graphics *mousehover_state = new Gdiplus::Graphics(ps.hdc);
    Image *img = new Image(L"d:/images/2.png",false);
    mousehover_state->DrawImage(img,5,5);
    delete img;
    delete mousehover_state;
    EndPaint(hwnd,&ps);
}
But in the final result WM_MOUSEHOVER fired, but the new picture is not drawn - this is a problem number 1.
Problem number 2 - how to erase the image of the old button state before the painting image for new button state?
Thanks!
Posted 28-Jun-13 11:11am
Igor-84468

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Change the image in your data used in rendering via WM_PAINT and call InvalidateRect on the rectangle of proper size and position: http://msdn.microsoft.com/en-us/library/windows/desktop/dd145002%28v=vs.85%29.aspx[^] or http://msdn.microsoft.com/en-us/library/2f3csed3%28v=vs.80%29.aspx[^].
 
—SA

 
The only place for drawing the image is WM_PAINT; select the image to draw in the other cases.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 535
1 OriginalGriff 275
2 BillWoodruff 260
3 Shweta N Mishra 244
4 Deepu S Nair 230
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,818
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,755


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 29 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100