Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » How do I 'check' a Switch control
How do I 'check' a Switch control [message #36216] Sat, 12 May 2012 17:35 Go to next message
awksed is currently offline  awksed
Messages: 61
Registered: April 2012
Member
Hi,

How do I 'check' a (single) Switch control and how do I determine if it is 'checked'? (I am looking for the equivalent of the MFC CButton::SetCheck() and CButton::GetCheck()).

Thanks,

Jan
Re: How do I 'check' a Switch control [message #36217 is a reply to message #36216] Sat, 12 May 2012 19:17 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

You can check the selected case in the switch by reading its value to an integer.

Switch sw;
int swVal;

swVal = sw;

or select a particular case in code by doing this

swVal = 1; // select item 1 of the switch
sw = swVal;

Re: How do I 'check' a Switch control [message #36218 is a reply to message #36217] Sat, 12 May 2012 20:14 Go to previous messageGo to next message
awksed is currently offline  awksed
Messages: 61
Registered: April 2012
Member
Hi jerson,

Thanks for your reply. It was most helpful in getting to the answer.

I guess I am not using the Switch class in the way the framework authors intended (too many years with MFC I guess and I'm too lazy to learn how to position two 'Radio Buttons' of a Switch group in widely differing places in a tab control, so I'm using two separate Switch controls connected by code).

The control is a single 'Radio Button', i.e. not part of a group therefore assigning 1 doesnt work, however assigning 0 does 'check' it (put the dot in the circle) and mySwitchObject <<= Null; 'unchecks' it.

int s = mySwitchObject; returns 0 if 'checked', i.e. got a dot in the circle, and -2147483648 (0x80000000) if not 'checked', i.e. no dot in the circle. So I have an odd looking but effective way of achieving what I want to do.

Regards,

Jan

Re: How do I 'check' a Switch control [message #36219 is a reply to message #36216] Sat, 12 May 2012 21:18 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
Hello, Jan.
awksed wrote on Sat, 12 May 2012 17:35

How do I 'check' a (single) Switch control and how do I determine if it is 'checked'? (I am looking for the equivalent of the MFC CButton::SetCheck() and CButton::GetCheck()).

There is Switch example inside reference U++ directory, which "demonstrates Switch widget". Also take a look Switch documentation.
Basically, as Jerson said, you assign the value (of type Value) to Switch object to select concrete case. To get selected value, just use GetData() Switch method or ~ operator before Switch object:
Switch sw;
sw.Add("Left").Add("Center").Add("Right");
sw = 1; // Selecting "Center". Equivalent to sw.SetData(1);
PromptOK(Format("Selected '%s' case with '%s' value", sw.GetLabel(), AsString(~sw)));

Based on CButton::SetCheck method, I think, you need ButtonOption or just Option widget:
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class App : public TopWindow {
public:
	typedef App CLASSNAME;
	App();

	ButtonOption btnOption;
	void PromptOption();
};

void App::PromptOption()
{
	static const String cases[2] = { "Off", "On" };
	PromptOK(cases[(int)btnOption.Get()]); // ButtonOption::Get is equivalent to CButton::GetCheck.
}

App::App()
{
	Title("ButtonOption test application");
	Sizeable().Zoomable();
	SetRect(Size(320, 240));

	btnOption.SetLabel("X");
	btnOption.Set(true); // ButtonOption::Set is equivalent to CButton::SetCheck.
	btnOption.WhenAction = THISBACK(PromptOption);
	Add(btnOption.VCenterPosZ(50).HCenterPosZ(50));
}

GUI_APP_MAIN
{
	App app;
	app.Run();
}

[Updated on: Sat, 12 May 2012 21:25]

Report message to a moderator

Re: How do I 'check' a Switch control [message #36221 is a reply to message #36219] Sun, 13 May 2012 17:51 Go to previous message
awksed is currently offline  awksed
Messages: 61
Registered: April 2012
Member
Hi Sender Ghost,

Thanks.

Jan
Previous Topic: time measurement :: RTIMING, TimeStop, GetTickCount
Next Topic: Storing VectorMap
Goto Forum:
  


Current Time: Thu Mar 28 19:25:24 CET 2024

Total time taken to generate the page: 0.01591 seconds