locked
How to change bitmap "buttons" with WM_LBUTTONUP and WM_LBUTTONDOWN ? RRS feed

  • Question

  • Hi

    I have 2 bit maps for a button, say Bitmaps A and B.
    In the buttonProc callback, I have 2 swtich cases for WM_LBUTTONUP and WM_LBUTTONDOWN.
    For WM_LBUTTONDOWN, I created a window class, create and store the bitmap handle for B.
    I then paint it and then moveWindow this bitmap B where the 1st bitmap A is located.
    Question: what did I do wrong that the bitmap "button" didn't change to the another bitmap ?
    Also: How do I process WM_LBUTTONUP ?
    What do I use SendMessage for in this case ? It's the same case where I have to redraw the button bitmap A
    from bitmap B. How do I do that exactly ?

    Only Win32 solution.
    Saturday, May 9, 2009 5:39 AM

Answers

  • Yes, one of the possible approaches is instead of launching the app from the mouse event handler, you insteasd post a predefined message (e.g. WM_USER) and launch the app from message handler (WndProc). This will also require you to call UpdateWindow right after InvalidateRect.

    Finally, do not call ShellExecute (or PostMessage) from LBUTTONDOWN. Do it in LBUTTONUP
    Alex Feinman. MVP .NET Compact Framework
    Sunday, May 10, 2009 8:09 PM

All replies

  • Hi

    I have 2 bit maps for a button, say Bitmaps A and B.
    In the buttonProc callback, I have 2 swtich cases for WM_LBUTTONUP and WM_LBUTTONDOWN.
    For WM_LBUTTONDOWN, I created a window class, create and store the bitmap handle for B.
    I then paint it and then moveWindow this bitmap B where the 1st bitmap A is located.
    Question: what did I do wrong that the bitmap "button" didn't change to the another bitmap ?
    Also: How do I process WM_LBUTTONUP ?
    What do I use SendMessage for in this case ? It's the same case where I have to redraw the button bitmap A
    from bitmap B. How do I do that exactly ?

    Only Win32 solution.
    Saturday, May 9, 2009 5:40 AM
  • When you detect mouse down or mouse up, change internal flag (e.g. BOOL fButtonDown) and invalidate button window. In your paint routine choose one or another bitmap based on this flag
    Alex Feinman. MVP .NET Compact Framework
    Saturday, May 9, 2009 7:11 AM
  • Hi Alex

    I did what you said.

    case WM_PAINT:
    ....
    BeginPaintI(hWnd,&p);
    ..
    EndPaint(hWnd,&p);


    case WM_LBUTTONDOWN:

    fButtonDown = TRUE;

     

    InvalidateRect(hwnd, NULL, TRUE);

    ShellExecute(Str);

    break;


    A side problem is that the ShellExecute invokes another application too soon that the user cannot see the change in button bitmaps.
    It appears that application Str gets kicked off first before the bitmap can be repainted in WM_PAINT.
    Is there a way to show the changed bitmap before kicking off this application Str ?

    Saturday, May 9, 2009 11:24 PM
  • Yes, one of the possible approaches is instead of launching the app from the mouse event handler, you insteasd post a predefined message (e.g. WM_USER) and launch the app from message handler (WndProc). This will also require you to call UpdateWindow right after InvalidateRect.

    Finally, do not call ShellExecute (or PostMessage) from LBUTTONDOWN. Do it in LBUTTONUP
    Alex Feinman. MVP .NET Compact Framework
    Sunday, May 10, 2009 8:09 PM
  • Hi,

    I think you'll need to share a little bit more of your code. Reading your description still leaves it quite unclear in my mind exactly what you are doing/wanting to achieve.

    If you are creating a window (calling CreateWindow) and then painting to it outside of a WM_PAINT message handler, this may explain why the contents disappears when you call MoveWindow. Your window contents could become invalidated and your window procedure will get a WM_PAINT request to repaint the window (which i assume you are not handling).

    What are you aiming to achieve? Do you simply want a bitmap button that shows one bitmap while the stylus is held down, and another when the stylus is lifted up?

    Hope this helps,
    Christopher Fairbairn
    Visit my blog at http://www.christec.co.nz/blog/
    Sunday, May 10, 2009 11:29 PM
  • Hi Chris
    Thanks for the reply.
    This is what I have. Any comments, do you think I did it right. All these are in the CALLBACK function of my button proc.

    It didn't seem to make a difference. The button did change its bitmap from bitmap A to B and then invokes the application. However the bitmap didn't change back to bitmap A as soon as I released the "button". It stays, displaying bitmap B and I kill the app, then I see bitmap A.
    I like to see bitmaps changing from bitmap A to B and back to A when I release the button before the shell execute the app.

     

    if(hwnd == Bwnd)

     

     

     

    InvalidateRect(hwnd, NULL, TRUE);

    UpdateWindow (hwnd) ;

     

     

     

     

    }


     

    case WM_LBUTTONUP:

     

    if(hwnd == Bwnd)

     

     

     

    InvalidateRect(hwnd, NULL, TRUE);

    ShellExecute(_T(

     

    "....."));

     


    WM_PAINT:

     

    if (Press == TRUE)

     

    Press = FALSE;

    }

     

    {

    // paint button and then ...

     

     

    }

     

     

    {

     

     

    Press = FALSE;

     

     

     

     

    {

     

    Monday, May 11, 2009 5:04 PM