radio button

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

    • radio button

      Hi,

      I want to display radio button of two options, in that two options I want only one to be highlighted that is even if I touch other one it should not be selected. Please do help asap.

      Regards,
      Saieesh.
    • Hi,

      Like this?

      C Source Code

      1. #include "DIALOG.h"
      2. /*********************************************************************
      3. *
      4. * Static code
      5. *
      6. **********************************************************************
      7. */
      8. /*********************************************************************
      9. *
      10. * _cbBk
      11. */
      12. static void _cbBk(WM_MESSAGE * pMsg) {
      13. WM_HWIN hItem;
      14. int NCode;
      15. int Id;
      16. GUI_RECT Rect;
      17. int Selection;
      18. char acBuffer[32];
      19. switch (pMsg->MsgId) {
      20. case WM_PAINT:
      21. GUI_SetBkColor(GUI_LIGHTGRAY);
      22. GUI_Clear();
      23. Rect.x0 = 0;
      24. Rect.y0 = 0;
      25. Rect.x1 = LCD_GetXSize() - 1;
      26. Rect.y1 = LCD_GetYSize() - 1;
      27. hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_RADIO0);
      28. Selection = RADIO_GetValue(hItem);
      29. RADIO_GetText(hItem, Selection, acBuffer, sizeof(acBuffer));
      30. GUI_SetColor(GUI_BLACK);
      31. GUI_DispStringInRect(acBuffer, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
      32. break;
      33. case WM_NOTIFY_PARENT:
      34. NCode = pMsg->Data.v;
      35. Id = WM_GetId(pMsg->hWinSrc);
      36. switch (Id) {
      37. case GUI_ID_RADIO0:
      38. switch (NCode) {
      39. case WM_NOTIFICATION_VALUE_CHANGED:
      40. WM_InvalidateWindow(WM_HBKWIN);
      41. break;
      42. }
      43. break;
      44. }
      45. break;
      46. default:
      47. WM_DefaultProc(pMsg);
      48. break;
      49. }
      50. }
      51. /*********************************************************************
      52. *
      53. * Public code
      54. *
      55. **********************************************************************
      56. */
      57. /*********************************************************************
      58. *
      59. * MainTask
      60. */
      61. void MainTask(void) {
      62. WM_HWIN hRadio;
      63. GUI_Init();
      64. WM_SetCallback(WM_HBKWIN, _cbBk);
      65. hRadio = RADIO_CreateEx(20, 20, 80, 80, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_RADIO0, 2, 20);
      66. RADIO_SetText(hRadio, "Option 1", 0);
      67. RADIO_SetText(hRadio, "Option 2", 1);
      68. while (1) {
      69. GUI_Delay(100);
      70. }
      71. }
      72. /*************************** End of file ****************************/
      Display All
      Regards,
      Sven
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.