Note that there are some explanatory texts on larger screens.

plurals
  1. POMFC radio buttons - DDX_Radio and DDX_Control behavior
    text
    copied!<p>I have an MFC dialog in which there are two radio buttons. I have put them in a nice group, their IDCs are one after each other (<code>RB_LEFT, RB_RIGHT</code>).</p> <p>I want to use <code>DDX_Radio</code> so I can access the buttons using an integer value so in the function DoDataExchange I call : </p> <pre><code> DDX_Radio(pDX, RB_LEFT, mRBLeftRight); </code></pre> <p>where mRBLeftRight is a member variable of integer type. I also need to edit the buttons properties so I wanted to use a <code>DDX_Control</code> to map them on member variables mRBLeft and mRBRight (CButton):</p> <pre><code> DDX_Control(pDX, RB_LEFT, mRBLeft); DDX_Control(pDX, RB_RIGHT, mRBRight); </code></pre> <p>now if I do the call to <code>DDX_Control</code>, whenever DoDataExchange is called, the application crashes because <code>DDX_Control</code> forces <code>RB_LEFT</code> to handle a message that <code>DDX_Radio</code> cannot handle. This part I understand.</p> <p>I decided to not use <code>DDX_Control</code> (removed the calls in DoDataExchange) and just keep a pointer to my radio buttons (CButton*) in my classes. So in my OnInitDialog function, I do the following calls :</p> <pre><code> mRBLeft= ((CButton*)GetDlgItem(RB_LEFT)); mRBRight = ((CButton*)GetDlgItem(RB_RIGHT)); </code></pre> <p>Now as long as I don't use mRBLeft it's going to be fine, but if I do, bam, crash on DoDataExchange. The thing that really puzzles me is if I change my left radio button using <code>((CButton*)GetDlgItem(RB_LEFT)-&gt;SetCheck(true)</code> it's going to work. Sooo what's the difference ?</p> <p>(I know it's a lot of hassle for little, but I just wanna understand the mechanics)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload