home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / msj / v10n04 / olecont.exe / INCTLDLG.CPP < prev    next >
C/C++ Source or Header  |  1995-04-01  |  4KB  |  176 lines

  1. // inctldlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "contain.h"
  6. #include "inctldlg.h"
  7. #include <olectl.h>
  8.  
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char BASED_CODE THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // COleInsertCtlDlg dialog
  16.  
  17. COleInsertCtlDlg::COleInsertCtlDlg(CWnd* pParent /*=NULL*/)
  18.     : COleInsertDialog(IOF_SELECTCREATENEW, pParent)
  19. {
  20.     //{{AFX_DATA_INIT(COleInsertCtlDlg)
  21.         // NOTE: the ClassWizard will add member initialization here
  22.     //}}AFX_DATA_INIT
  23. }
  24.  
  25.  
  26. void COleInsertCtlDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28.     CDialog::DoDataExchange(pDX);
  29.     //{{AFX_DATA_MAP(COleInsertCtlDlg)
  30.         // NOTE: the ClassWizard will add DDX and DDV calls here
  31.     //}}AFX_DATA_MAP
  32. }
  33.  
  34.  
  35. BEGIN_MESSAGE_MAP(COleInsertCtlDlg, CDialog)
  36.     //{{AFX_MSG_MAP(COleInsertCtlDlg)
  37.     //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39.  
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // COleInsertCtlDlg message handlers
  43.  
  44. BOOL COleInsertCtlDlg::OnInitDialog() 
  45. {
  46.     COleInsertDialog::OnInitDialog();
  47.  
  48.     CListBox*    pBox;
  49.     pBox = (CListBox*) GetDlgItem(IDC_CONTROLS);
  50.     ASSERT(pBox != NULL);
  51.  
  52.     UINT        cStrings=0;
  53.     int            cch;
  54.     HKEY        hKey;
  55.     LONG        lRet;
  56.     LPTSTR      pszClass;
  57.     LPTSTR      pszClsid;
  58.     LPTSTR        pszKey;
  59.     HKEY        hKeyTemp;
  60.     TCHAR        szID[50];
  61.  
  62.     pszClass=(LPTSTR) new TCHAR[_MAX_PATH*3];
  63.     if (NULL==pszClass)
  64.         return FALSE;
  65.     pszClsid=pszClass+_MAX_PATH;
  66.     pszKey=pszClsid+_MAX_PATH;
  67.  
  68.     //Open up the root key.
  69.     lRet=RegOpenKey(HKEY_CLASSES_ROOT, NULL, &hKey);
  70.  
  71.     if ((LONG)ERROR_SUCCESS!=lRet)
  72.     {
  73.         delete pszClass;
  74.         return FALSE;
  75.     }
  76.  
  77.     //Clean out the existing strings.
  78.     pBox->ResetContent();
  79.  
  80.     while (TRUE)
  81.     {
  82.         lRet=RegEnumKey(hKey, cStrings++, pszClass, _MAX_PATH);
  83.  
  84.         if ((LONG)ERROR_SUCCESS!=lRet)
  85.             break;
  86.  
  87.         // Get full user type name
  88.         DWORD dw=_MAX_PATH;
  89.         lRet=RegQueryValue(hKey, pszClass, pszKey, (LONG*)&dw);
  90.  
  91.         // Get class ID
  92.         lstrcat(pszClass, TEXT("\\CLSID"));
  93.         dw=50 * sizeof(TCHAR);
  94.         lRet = RegQueryValue(hKey, pszClass, szID, (LONG*)&dw);
  95.  
  96.         if ((LONG)ERROR_SUCCESS!=lRet)
  97.             continue;   // CLSID subkey not found
  98.  
  99.         lstrcpy(pszClsid, TEXT("CLSID\\"));
  100.         lstrcat(pszClsid, szID);
  101.         lstrcat(pszClsid, TEXT("\\"));
  102.         cch = lstrlen(pszClsid);
  103.         lstrcpy(pszClsid+cch, TEXT("Control"));
  104.  
  105.         hKeyTemp = NULL;
  106.         lRet=RegOpenKey(hKey, pszClsid, &hKeyTemp);
  107.         if (hKeyTemp != NULL)
  108.             RegCloseKey(hKeyTemp);
  109.  
  110.         if ((LONG)ERROR_SUCCESS!=lRet)
  111.             continue;   // Control NOT found--skip this class
  112.  
  113.         // Look for InprocServer[32] or LocalServer[32] key
  114.         lstrcpy(pszClsid+cch, _T("InprocServer32"));
  115.  
  116.         hKeyTemp = NULL;
  117.         lRet=RegOpenKey(hKey, pszClsid, &hKeyTemp);
  118.         if (hKeyTemp != NULL)
  119.             RegCloseKey(hKeyTemp);
  120.  
  121.         if ((LONG)ERROR_SUCCESS!=lRet)    // InprocServer[32] not found
  122.         {
  123.             lstrcpy(pszClsid+cch, _T("LocalServer32"));
  124.  
  125.             hKeyTemp = NULL;
  126.             lRet=RegOpenKey(hKey, pszClsid, &hKeyTemp);
  127.             if (hKeyTemp != NULL)
  128.                 RegCloseKey(hKeyTemp);
  129.  
  130.             if ((LONG)ERROR_SUCCESS!=lRet)    // LocalServer[32] not found
  131.                 continue;
  132.         }
  133.  
  134.         //We got through all the conditions, add the string.
  135.         lstrcat(pszKey, _T("\t"));
  136.  
  137.         // only add to listbox if not a duplicate
  138.         if (LB_ERR == pBox->FindString(-1, pszKey)) 
  139.         {
  140.             lstrcat(pszKey, szID);
  141.             pBox->AddString(pszKey);
  142.         }
  143.     }
  144.  
  145.     //set the tab stop to be about 1/3 of the box
  146.  
  147.     CRect rectBox;
  148.     int    nThird;
  149.     pBox->GetWindowRect(rectBox);
  150.     nThird = rectBox.Width()/12;        // dialog units
  151.     pBox->SetTabStops(nThird);
  152.  
  153.     //Select the first item by default
  154.     pBox->SetCurSel(0);
  155.     RegCloseKey(hKey);
  156.     delete pszClass;
  157.  
  158.     return TRUE;  // return TRUE unless you set the focus to a control
  159.                   // EXCEPTION: OCX Property Pages should return FALSE
  160. }
  161.  
  162. void COleInsertCtlDlg::OnOK() 
  163. {
  164.     // TODO: Add extra validation here
  165.     
  166.     COleInsertDialog::OnOK();
  167. }
  168.  
  169. int COleInsertCtlDlg::DoModal()
  170. {
  171.         m_io.hInstance = AfxGetResourceHandle();
  172.         m_io.lpszTemplate = MAKEINTRESOURCE(IDD_INSERTCTL);
  173.  
  174.         return COleInsertDialog::DoModal();
  175. }
  176.