KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q167170: BUG: GetWindowContextHelpId() returns 0 for ActiveX Controls

Article: Q167170
Product(s): Microsoft C Compiler
Version(s): 4.2,4.2b,5.0,6.0
Operating System(s): 
Keyword(s): kbActiveX kbContainer kbCSHelp kbCtrl kbMFC kbVC420bug kbVC500bug kbVC600bug kbGrpDSMFC
Last Modified: 12-FEB-2002

-------------------------------------------------------------------------------
The information in this article applies to:

- The Microsoft Foundation Classes (MFC), used with:
   - Microsoft Visual C++, 32-bit Enterprise Edition, versions 4.2, 4.2b, 5.0, 6.0 
   - Microsoft Visual C++, 32-bit Professional Edition, versions 4.2, 4.2b, 5.0, 6.0 
   - Microsoft Visual C++, 32-bit Learning Edition, version 6.0 
-------------------------------------------------------------------------------

SYMPTOMS
========

You can specify a control's help context ID by selecting the "Help ID" check box
from the General tab of the control dialog box in resource editor. If the "Help
ID" check box is selected, calling GetWindowContextHelpId() at runtime retrieves
the help context identifier associated with the control. This works for all
standard controls, such as edit controls, button controls, etc. However, for
ActiveX controls, such as TestHelp controls, Circ3 controls, and so forth, 0 is
returned.

CAUSE
=====

MFC fails to associate a help context id for ActiveX controls even though the
"Help ID" check box is selected.

RESOLUTION
==========

When you call SetWindowContextHelpId() on the control with the correct ID, it
sets the Help ID for the control. OnInitDialog is a good place to do this. For
form views, OnInitialUpdate would be the best place to set the help ID. The
sample code below shows a way to set and retrieve the help context ID of an
ActiveX control (TestHelp control) in a CDialog-derived class.

STATUS
======

Microsoft has confirmed this to be a bug in the Microsoft products listed at the
beginning of this article.

REFERENCES
==========

Sample Code
-----------

     ...
     #include "resource.hm" // Make sure you include the .hm file
                            // generated by the resource editor.
                            // It includes the help ID's for the
                            // controls.
     ...

     BOOL CMyDialog::OnInitDialog()
     {
         CDialog::OnInitDialog();

         ...
         // Associate a help context id with the TestHelp control.
         // IDC_TESTHELP_CONTROL is the id of the TestHelp control and
         // HIDC_TESTHELP_CONTROL is its help context id defined in
         // resource.hm file.
         CWnd* control = GetDlgItem(IDC_TESTHELP_CONTROL);
         control->SetWindowContextHelpId(HIDC_TESTHELP_CONTROL);

         return TRUE;  // Return TRUE unless you set the focus to a control.
                       // EXCEPTION: OCX Property Pages should return FALSE.
     }

     void CMyDialog::MyFunction()
     {
         // Retrieve the help context id associated with the TestHelp
         // control.
         CWnd* control = GetDlgItem(IDC_TESTHELP_CONTROL);
         DWORD help_id = control->GetWindowContextHelpId();
         TRACE("Help ID for Control IDC_TESTHELP_CONTROL : %x\n", help_id);
         ...
     }

(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Yeong-Kah
Tam, Microsoft Corporation


Additional query words:

======================================================================
Keywords          : kbActiveX kbContainer kbCSHelp kbCtrl kbMFC kbVC420bug kbVC500bug kbVC600bug kbGrpDSMFCATL kbNoUpdate 
Technology        : kbAudDeveloper kbMFC
Version           : :4.2,4.2b,5.0,6.0
Issue type        : kbbug

=============================================================================

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.