button with image

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • New

      Hi Sridhar,

      what you want to do is give a button a custom look, if I understand you correctly? You can do this by overwriting the widget's callback function and do the custom drawing in the WM_PAINT case of the callback.

      Note that the bitmap you draw should have the same dimensions as your button so that it fits.

      C Source Code

      1. /*********************************************************************
      2. *
      3. * Static code
      4. *
      5. **********************************************************************
      6. */
      7. /*********************************************************************
      8. *
      9. * _cbButton
      10. */
      11. static void _cbButton(WM_MESSAGE * pMsg) {
      12. switch (pMsg->MsgId) {
      13. case WM_PAINT:
      14. GUI_SetBkColor(GUI_BLACK);
      15. GUI_Clear();
      16. //
      17. // Draw a bitmap
      18. //
      19. GUI_DrawBitmap(&bmBitmap, 0, 0);
      20. break;
      21. default:
      22. BUTTON_Callback(pMsg);
      23. break;
      24. }
      25. }
      26. /*********************************************************************
      27. *
      28. * Public code
      29. *
      30. **********************************************************************
      31. */
      32. /*********************************************************************
      33. *
      34. * MainTask
      35. */
      36. void MainTask(void) {
      37. WM_HWIN hButton;
      38. GUI_Init();
      39. //
      40. // Create a button
      41. //
      42. hButton = BUTTON_CreateEx(10, 10, 80, 20, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_BUTTON0);
      43. //
      44. // Set callback to button
      45. //
      46. WM_SetCallback(hButton, _cbButton);
      47. while (1) {
      48. GUI_Delay(100);
      49. }
      50. }
      Display All

      Best regards,

      Florian
    • New

      Hi
      Thanks Florian
      With your sample code ,I made the button with image.
      I used ICONVIEW from GUI Builder and converted a bitmap image
      into .dta file using Bitmap convertor tool. Then I saved the file
      with .dta extension.Now it is working fine.
      But unable to rectify the white stripes at corner.
      Do you have any suggestions for this?