title: Disabling dialog OK button MFC
body: <p>How do I disable MFC dialog OK button?<br>
  This code:<br>
  <code>CWnd* fieldOK = pDlg-&gt;GetDlgItem(IDOK);<br>
   fieldOK-&gt;EnableWindow(FALSE);</code><br>
  causes exception "<em>Access violation reading location...</em>"
   in line <code>ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));</code> of function <code>CWnd::EnableWindow(BOOL bEnable)</code> in <code>winnocc.cpp</code> from <code>mfc90d.dll</code><br>
  In this time focus is on another control.<br>
  What's can be wrong?  </p>
  
  <p>Thanks for help.</p>
  
  <p>[EDITED]</p>
  
  <pre><code>bool CSCalcNormCell::OnSelectionChanged( CWnd* pDlg, int type, int page, UINT ctrl_id ) 
  { 
    DDX_DataBox(pDX.get(), IDC_WORKSHOP_COMBO, ws_code); 
    if (!CInfactoryPriceAdapter::CanEditPricesForWorkshop( ws_code )) 
    { 
      CWnd* fieldOK = pDlg-&gt;GetDlgItem(IDOK); 
      fieldOK-&gt;EnableWindow(FALSE); 
    } 
    else 
    { 
      CWnd* fieldOK = pDlg-&gt;GetDlgItem(IDOK); 
      fieldOK-&gt;EnableWindow(TRUE); 
    } 
  }
  </code></pre>