Radio button linked to text box

This is a discussion on Radio button linked to text box within the Windows Programming forums, part of the Platform Specific Boards category; Hi All, How do I go about linking a text box to a radio button. What I need is this: ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    18

    Radio button linked to text box

    Hi All,
    How do I go about linking a text box to a radio button.
    What I need is this:
    I have 2 radio buttons in the same group: Yes and NO
    When Yes is clicked I want a text box to be enabled. If No is clicked, then the textbox will stay disabled.

    Any help would be great
    Thanks,
    Donal

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Declare 3 HWND's (ie: hYes, hNo, hText). Check for WM_COMMAND messages and check the (HWND)lparam to see if it matches the hYes or hNo button.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    18

    jbravo99

    What would I assign these HWND's to?

  4. #4
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    In your WindowProc under case WM_CREATE you'd assign them when you create the radio buttons. ie:
    Code:
    //global declare
    HWND hBtn=NULL;
    //in your WindowProc, case WM_CREATE:
    hBtn=CreateWindowEx(0,"Button","Click Here",WS_VISIBLE, 
     WS_CHILD | BS_DEFPUSHBUTTON,10,10,120,30,hWnd,
     NULL,hInstance,NULL);
    In this example it creates a regular pushbutton. hWnd is the HWND passed to your WindowProc (your main window's HWND) and hInstMain would be the global HINSTANCE for your main window).

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    18
    Hi jdinger,
    I'm creating resources using VC++. So I can't get the HWND for the button the way you specified. Is there a function for returning the HWND of my radio button to hBtn?
    Thanks,
    Donal

  6. #6
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Yes you can. Check out my signature. I use MSVC++ 6. You can get the HWND like that. In your WindowProc under case WM_COMMAND you'd just use:
    Code:
    if((HWND)lParam==hBtn1)
    {
      //do stuff here
    }
    else if((HWND)lParam==hBtn2)
    {
      //do different stuff here
    }

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    18
    But how do you get hBtn1 to be a HWND for IDC_RADIO1 without
    using the CreateWindowEx() function????

    Tks,
    Donal

  8. #8
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Ah! You didn't mention that you were using MFC. I have very little experience with MFC but you can check here. I'll look into it and when I find something I'll post it here for you.

  9. #9
    Registered User
    Join Date
    Mar 2002
    Posts
    18
    Thanks for you help
    Donal

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    GetWindow() and GetDlgItem() will return the HWND of a ctrl.

    Try
    Code:
    case WM_COMMAND:
    idControl	= GET_WM_COMMAND_ID(wParam,lParam) ;
    switch (idControl)
          case IDC_RADIOYES:
          if (BN_CLICKED == HIWORD(wParam))
          {
                 EnableWindow(GetDlgItem(hDialog,IDC_EDIT),TRUE);
          }
          break;
          //disable with a false under the no radio
    break;
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  2. Automatically enter text in a dialog box
    By leojose in forum Windows Programming
    Replies: 6
    Last Post: 12-13-2005, 10:59 AM
  3. edit box affecting displaying of text?
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-04-2005, 03:28 PM
  4. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 06:35 PM
  5. String from a text box
    By Garfield in forum Windows Programming
    Replies: 4
    Last Post: 09-16-2001, 03:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21