Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - CXTPButton::SetChecked / CWnd::UpdateData problems
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPButton::SetChecked / CWnd::UpdateData problems

 Post Reply Post Reply
Author
Message
liong View Drop Down
Newbie
Newbie
Avatar

Joined: 13 August 2019
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote liong Quote  Post ReplyReply Direct Link To This Post Topic: CXTPButton::SetChecked / CWnd::UpdateData problems
    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?

Back to Top
BobC View Drop Down
Groupie
Groupie


Joined: 28 April 2017
Location: Longmont, CO
Status: Offline
Points: 55
Post Options Post Options   Thanks (0) Thanks(0)   Quote BobC Quote  Post ReplyReply Direct Link To This Post 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 . 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().
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.