Print Page | Close Window

CXTPButton::SetChecked / CWnd::UpdateData problems

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=23888
Printed Date: 26 April 2024 at 8:21am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTPButton::SetChecked / CWnd::UpdateData problems
Posted By: liong
Subject: CXTPButton::SetChecked / CWnd::UpdateData problems
Date Posted: 13 August 2019 at 11:21am
I have a button on a dialog which, when pressed, executes the following code to set the checked state of another button.
With V15.0.2 this was working fine but now the same implementation causes problems with V17.0.0.

void MyDialog::OnBnClickedA()
{
  m_BtnB.SetChecked(FALSE);
  UpdateData(FALSE); // will call CWnd::UpdateData
}

I found out that UpdateData which does the data exchange sends a BM_SETCHECK msg which is handled by CXTPButton::OnSetCheck. This handler wasn't there in V15.0.2 but is now in V17.0.0.
Amongst other things, this one calls

  if (IsPushButton())
  {
    SetChecked(!GetChecked());
  }

to toggle the check state again :/

I cannot remove the call to UpdateData since this is needed for other controls.

How can i set the checked state for a CXTPButton in such a constellation?




Replies:
Posted By: BobC
Date Posted: 14 August 2019 at 5:41pm
You have run into the problem of UpdateData() being an all-or-nothing function, and because of that, I prefer to not use it at all except for trivially simple dialogs where all I want is to load values in OnInitDialog and retrieve values in OnOK.

Most dialogs I construct are not that simple, so OnInitDialog initializes them all with specific calls such as SetWindowText, SetCheck, etc., and the OnOK handler uses GetWindowText, GetCheck, etc. to validate the values, and only allows OnOK to succeed if all validation succeeds.

You can see some recent dialogs at https://drive.google.com/drive/folders/1tRI0MIsoCT2sU5oeKFNgpx3cLgzDNw4M" rel="nofollow - https://drive.google.com/drive/folders/1tRI0MIsoCT2sU5oeKFNgpx3cLgzDNw4M . The dialogs are the screens without the button toolbar (but technically, they are all dialogs because the application is form-based).

It sounds like you don't need to, and probably cannot, update all values at once, and if that is the case, you should not be using UpdateData().



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net