CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2008
    Posts
    5

    Trying to check if radiobutton checked in loop

    I have 2 radiobuttons. Each of them has a loop, When radiobutton1 is selected I want the loop in it to run until radiobutton2 is selected, then radiobutton2 will run in a loop until radiobutton1 is selected. So far everything I have tried just ends up with me stuck in a loop that I can't get out of. I can't figure out how to check if the other radiobutton has been selected.
    Any help would be great, Thanks.

  2. #2
    Join Date
    Dec 2008
    Posts
    144

    Re: Trying to check if radiobutton checked in loop

    The check to see if a radio button has been checked is:
    Code:
    if(RadioButtonName->Checked ==true)...
    replace RadioButtonName with the object's actual name, and the elipses are just placeholders.

    So far everything I have tried just ends up with me stuck in a loop that I can't get out of.
    Probably because you wrote an infinite loop. Having a correct check for the 2nd radio button should help with this, but the operation you are describing doesn't make any sense at all because you didn't provide much information. Frankly it sounds like a bad idea- why do you need an infinite loop like this?

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Trying to check if radiobutton checked in loop

    The problem more than likely is that as long as your loop continues to execute, you won't be processing messages so you'll never know the other button has been clicked.

    Put this code in your loop and see what happens.

    Code:
    	MSG msg;
    	while(PeekMessage(&msg, GetSafeHwnd(), 0, 0, PM_REMOVE))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}

  4. #4
    Join Date
    Dec 2008
    Posts
    5

    Re: Trying to check if radiobutton checked in loop

    Thanks for the replies,
    The code is reading either an analog or a digital signal from a USB IO device. So radiobutton1 sends the command to switch the device to digital mode then loops reading the input signal and displaying the value in a label box, radiobutton2 sends the command to switch the device to analog then loops displaying the read voltage in a label box. The loop is there to show any changes in input instantly on the screen.

    Putting the code:
    MSG msg;
    while(PeekMessage(&msg, GetSafeHwnd(), 0, 0, PM_REMOVE))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    in the loop gives the error:
    error C3861: 'GetSafeHwnd': identifier not found
    Thanks.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Trying to check if radiobutton checked in loop

    It's looking for the hwnd of the window that's receiving the notification messages. Just use whatever is appropriate in your case.

  6. #6
    Join Date
    Dec 2008
    Posts
    5

    Re: Trying to check if radiobutton checked in loop

    Thanks for your help.
    I am still having problems with the handle. I have been trying to get the following line of code to work, unless I am way off I thought this is what I needed to do? I have edded the following line:
    HWND hwnd = ::FindWindow(NULL,TEXT("LabJack U3"));

    Where LabJack U3 is what I used for the text property of Form1
    But I keep getting the following errors:
    1>U3Interface3.obj : error LNK2028: unresolved token (0A00004E) "extern "C" struct HWND__ * __stdcall FindWindowW(wchar_t const *,wchar_t const *)" (?FindWindowW@@$$J18YGPAUHWND__@@PB_W0@Z) referenced in function "public: __clrcall U3Interface3::Form1::Form1(void)" (??0Form1@U3Interface3@@$$FQ$AAM@XZ)

    1>U3Interface3.obj : error LNK2019: unresolved external symbol "extern "C" struct HWND__ * __stdcall FindWindowW(wchar_t const *,wchar_t const *)" (?FindWindowW@@$$J18YGPAUHWND__@@PB_W0@Z) referenced in function "public: __clrcall U3Interface3::Form1::Form1(void)" (??0Form1@U3Interface3@@$$FQ$AAM@XZ)

    According to MSDN I needed to add the USER32.lib which I did. Any idea what I'm doing wrong?
    Thanks.

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Trying to check if radiobutton checked in loop

    If this is a forms application, you're in the wrong forum.

    You haven't posted enough code to show the right way to get your window's handle. In MFC, GetSafeHwnd() will do it, but we don't know how you have your window set up.

  8. #8
    Join Date
    Dec 2008
    Posts
    5

    Re: Trying to check if radiobutton checked in loop

    This is a form, so will go to the other forum to finish up. Thanks for your help in getting this far.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured