Which Windows API in C++ will help me in identifying which Dialog Class the Current ComboBox is using? RRS feed

  • Question

  • I am Having a Desktop Windows Application Written in C++. Currently, I am running that application in Windows 10 and I can see few of the COmbo Boxes are not displaying the items properly. I noticed that our application is using a different kind of Dialog Classes for Different Windows. We are using CDialog, CdialogEx, and Dialogxyz(This is an in-house one and it's non-MFC). I have a function related to DropDown and inside this function, one of my tasks will be I need to retrieve information about what Dialog Class the Current DropDown is using. Based on that Info I need to decide how I am going to draw or set certain ComboBox features. So my question is, is there any Windows API which can retrieve which Dialog the ComboBox is using? A code snippet below will give a better understanding. I will really appreciate if you can enlighten me at the earliest. - Thnaks, Yan


    Combo_DoSomeManipulation( HWND hldg , int n )
    /*"hldg" is the handler of the Current ComBobox and this is the only relevant information I have in this function */
    LPTSTR lpClassName;
    int nMaxCount = 256; 
    GetClassName(hldg , lpClassName ,  _count_of(nMaxCount));             
      /*This will assign "CComboBox" as value in lpClassName */ 
    Similarly as above is there any Windows API which I can use where can pass the "hdlg" as parameter and get the Dialog Class Name used by the ComBoBox ? something like
    GetDialogClass(hldg) ?? 

    I want to use the Name of the Dialog Class used by the ComboBox for further programmatic uses, where depending on the DIalog Class I want to do specific things to that ComboBox.

    Friday, August 23, 2019 5:50 PM

All replies

  • Since 'hldg' is the HWND of your combobox, you can get its parent dialog by calling ::GetParent(hldg). Then call GetClassName() on your parent dialog hwnd.

    Friday, August 23, 2019 6:53 PM
  • If you are interested in the window class of parent window, then determine the parent using GetParent or GetAncestor, then call GetClassName.

    Make sure you pass a correct output buffer and its size.

    Friday, August 23, 2019 6:59 PM
  • Well, the Windows API function GetClassName will return #32770 for an HWND that is a dialog.  This would be the case regardless of the C++ class (MFC or otherwise) that is encapsulating the HWND.

    For MFC, you may be able to determine the C++ class name by using the following technique. See Accessing Run-Time Class Information for more information.

    Assuming that you have obtained an HWND for the parent MFC dialog from the ComboBox

    CWnd *w = FromHandle(hwnd);
    CRuntimeClass *prc = w->GetRuntimeClass();
    TRACE("C++ Runtime class is %s\n", prc->m_lpszClassName);

    Friday, August 23, 2019 8:32 PM