⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 insobjdlg.c

📁 winNT技术操作系统,国外开放的原代码和LIUX一样
💻 C
📖 第 1 页 / 共 2 页
字号:
    ShowWindow(pdlgInfo->hwndDisplayIconCB, SW_SHOW);

  ShowWindow(pdlgInfo->hwndFileLBL, SW_SHOW);
  ShowWindow(pdlgInfo->hwndFileTB, SW_SHOW);
  ShowWindow(pdlgInfo->hwndBrowseBTN, SW_SHOW);

  SendMessageA(pdlgInfo->hwndCreateFromFileCB, BM_SETCHECK, BST_CHECKED, 0);

  if (LoadStringA(OLEDLG_hInstance, IDS_RESULTFILEOBJDESC, resstr, MAX_PATH))
     SendMessageA(pdlgInfo->hwndResultDesc, WM_SETTEXT, 0, (LPARAM)resstr);
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_PopulateObjectTypes
 *
 * Populate Object Type listbox
 */
static BOOL UIINSERTOBJECTDLG_PopulateObjectTypes(InsertObjectDlgInfo* pdlgInfo)
{
  DWORD i;
  LONG len;
  HKEY hkclsids;
  HKEY hkey;
  CLSID clsid;
  HRESULT ret;
  CHAR szclsid[128];
  CHAR keydesc[MAX_PATH];
  CHAR keyname[MAX_PATH];
  WCHAR wszclsid[128];
  DWORD index = 0;

  UIINSERTOBJECTDLG_FreeObjectTypes(pdlgInfo);

  RegOpenKeyExA(HKEY_CLASSES_ROOT, "CLSID", 0, KEY_READ, &hkclsids);

  while (ERROR_SUCCESS == (ret = RegEnumKeyA(hkclsids, index, szclsid, MAX_PATH)))
  {
    index++;

    RegOpenKeyExA(hkclsids, szclsid, 0, KEY_READ, &hkey);

    len = MAX_PATH;
    if (ERROR_SUCCESS != RegQueryValueA(hkey, "Insertable", keyname, &len))
        continue;

    len = MAX_PATH;
    if (ERROR_SUCCESS == RegQueryValueA(hkey, "NotInsertable", keyname, &len))
        continue;

    RtlMultiByteToUnicodeN(wszclsid, MAX_PATH, NULL, szclsid, MAX_PATH); 
    CLSIDFromString(wszclsid, &clsid);

    for (i = 0; i < pdlgInfo->lpOleUIInsertObject->cClsidExclude; i++)
      if (IsEqualGUID(&pdlgInfo->lpOleUIInsertObject->lpClsidExclude[i], &clsid))
        break;

    if (i < pdlgInfo->lpOleUIInsertObject->cClsidExclude)
      continue;

    len = MAX_PATH;
    if (ERROR_SUCCESS == RegQueryValueA(hkey, NULL, keydesc, &len))
    {
       CLSID* lpclsid = HeapAlloc(GetProcessHeap(), 0, sizeof(CLSID));
       memcpy(lpclsid, &clsid, sizeof(CLSID));

       len = SendMessageA(pdlgInfo->hwndObjTypeLB, LB_ADDSTRING, 0, (LPARAM)keydesc);
       SendMessageA(pdlgInfo->hwndObjTypeLB, LB_SETITEMDATA, (WPARAM)len, (LPARAM)lpclsid);
    }
  }

  pdlgInfo->bObjListInit = (ret == ERROR_NO_MORE_ITEMS);

  return pdlgInfo->bObjListInit;
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_FreeObjectTypes
 *
 * Free Object Types listbox
 */
static void UIINSERTOBJECTDLG_FreeObjectTypes(InsertObjectDlgInfo* pdlgInfo)
{
  UINT i, count;

  count = SendMessageA(pdlgInfo->hwndObjTypeLB, LB_GETCOUNT, (WPARAM)0, (LPARAM)0);

  for (i = 0; i < count; i++)
  {
      CLSID* lpclsid = (CLSID*) SendMessageA(pdlgInfo->hwndObjTypeLB, 
         LB_GETITEMDATA, (WPARAM)i, (LPARAM)0);
      HeapFree(GetProcessHeap(), 0, lpclsid);
  }
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_SelChange
 *
 * Handle object type selection change
 */
static void UIINSERTOBJECTDLG_SelChange(InsertObjectDlgInfo* pdlgInfo)
{
  INT index;
  CHAR objname[MAX_PATH];
  CHAR objdesc[MAX_PATH];
  CHAR resstr[MAX_PATH];

  TRACE("\n");

  if (LoadStringA(OLEDLG_hInstance, IDS_RESULTOBJDESC, resstr, MAX_PATH) &&
     ((index = SendMessageA(pdlgInfo->hwndObjTypeLB, LB_GETCURSEL, 0, 0)) >= 0) &&
     SendMessageA(pdlgInfo->hwndObjTypeLB, LB_GETTEXT, (WPARAM)index, (LPARAM)objname))
       sprintf(objdesc, resstr, objname);
  else
    objdesc[0] = 0;

  SendMessageA(pdlgInfo->hwndResultDesc, WM_SETTEXT, 0, (LPARAM)objdesc);
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_SelChange
 *
 * Handle OK Button
 */
static BOOL UIINSERTOBJECTDLG_OnOpen(InsertObjectDlgInfo* pdlgInfo)
{
  BOOL bret = FALSE;

  if (BST_CHECKED == SendMessageA(pdlgInfo->hwndCreateCtrlCB, BM_GETCHECK, 0, 0) ||
      BST_CHECKED == SendMessageA(pdlgInfo->hwndCreateNewCB, BM_GETCHECK, 0, 0))
  {
    INT index = SendMessageA(pdlgInfo->hwndObjTypeLB, LB_GETCURSEL, 0, 0);

    if (index >= 0)
    {
       CLSID* clsid = (CLSID*) SendMessageA(pdlgInfo->hwndObjTypeLB, 
          LB_GETITEMDATA, (WPARAM)index, 0);
       memcpy(&pdlgInfo->lpOleUIInsertObject->clsid, clsid, sizeof(CLSID));

       if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CREATENEWOBJECT)
       {
          pdlgInfo->lpOleUIInsertObject->sc= OleCreate(
             &pdlgInfo->lpOleUIInsertObject->clsid,
             &pdlgInfo->lpOleUIInsertObject->iid,
             pdlgInfo->lpOleUIInsertObject->oleRender,
             pdlgInfo->lpOleUIInsertObject->lpFormatEtc,
             pdlgInfo->lpOleUIInsertObject->lpIOleClientSite,
             pdlgInfo->lpOleUIInsertObject->lpIStorage,
             pdlgInfo->lpOleUIInsertObject->ppvObj);
       }

       bret = TRUE;
    }
  }
  else if (BST_CHECKED == SendMessageA(pdlgInfo->hwndCreateFromFileCB, BM_GETCHECK, 0, 0))
  {
    char fname[MAX_PATH];

    if (pdlgInfo->lpOleUIInsertObject->lpszFile)
    {
      HRESULT hres;
      WCHAR wcsFile[MAX_PATH];

      SendMessageA(pdlgInfo->hwndFileTB, WM_GETTEXT, (WPARAM)MAX_PATH, (LPARAM)fname);
      lstrcpynA(pdlgInfo->lpOleUIInsertObject->lpszFile, fname, pdlgInfo->lpOleUIInsertObject->cchFile);

      RtlMultiByteToUnicodeN(wcsFile, MAX_PATH, NULL, fname, MAX_PATH); 
      if (ERROR_SUCCESS == (hres = GetClassFile(wcsFile, &pdlgInfo->lpOleUIInsertObject->clsid)))
      {
         if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CREATEFILEOBJECT)
         {
           hres = OleCreateFromFile(
             &pdlgInfo->lpOleUIInsertObject->clsid,
             wcsFile,
             &pdlgInfo->lpOleUIInsertObject->iid,
             pdlgInfo->lpOleUIInsertObject->oleRender,
             pdlgInfo->lpOleUIInsertObject->lpFormatEtc,
             pdlgInfo->lpOleUIInsertObject->lpIOleClientSite,
             pdlgInfo->lpOleUIInsertObject->lpIStorage,
             pdlgInfo->lpOleUIInsertObject->ppvObj);
         }

         bret = TRUE;
      }
      pdlgInfo->lpOleUIInsertObject->sc = hres;
    }
  }

  return bret;
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_BrowseFile
 *
 * Browse for the file
 */
static void UIINSERTOBJECTDLG_BrowseFile(InsertObjectDlgInfo* pdlgInfo)
{
   OPENFILENAMEA fn;
   char fname[MAX_PATH];
   char title[32];

   fn.lStructSize = sizeof(OPENFILENAMEA);
   fn.hwndOwner = pdlgInfo->hwndSelf;
   fn.hInstance = 0;
   fn.lpstrFilter = "All Files\0*.*\0\0";
   fn.lpstrCustomFilter = NULL;
   fn.nMaxCustFilter = 0;
   fn.nFilterIndex = 0;

   SendMessageA(pdlgInfo->hwndFileTB, WM_GETTEXT, (WPARAM)MAX_PATH, (LPARAM)fname);
   fn.lpstrFile = fname;
   fn.nMaxFile = MAX_PATH;

   fn.lpstrFileTitle = NULL;
   fn.nMaxFileTitle = 0;
   fn.lpstrInitialDir = NULL;

   LoadStringA(OLEDLG_hInstance, IDS_BROWSE, title, 32);
   fn.lpstrTitle = title;

   fn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST |
      OFN_HIDEREADONLY | OFN_LONGNAMES;
   fn.nFileOffset = 0;
   fn.nFileExtension = 0;
   fn.lpstrDefExt = NULL;
   fn.lCustData = 0;
   fn.lpfnHook = NULL;
   fn.lpTemplateName = NULL;

   if (GetOpenFileNameA(&fn))
      SendMessageA(pdlgInfo->hwndFileTB, WM_SETTEXT, (WPARAM)0, (LPARAM)fn.lpstrFile);
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_AddControl
 *
 * Add control to Object Type
 */
static void UIINSERTOBJECTDLG_AddControl(InsertObjectDlgInfo* pdlgInfo)
{
   OPENFILENAMEA fn;
   char fname[MAX_PATH];
   char title[32];

   fn.lStructSize = sizeof(OPENFILENAMEA);
   fn.hwndOwner = pdlgInfo->hwndSelf;
   fn.hInstance = 0;
   fn.lpstrFilter = "OLE Controls\0*.ocx\0Libraries\0*.dll\0All Files\0*.*\0\0";
   fn.lpstrCustomFilter = NULL;
   fn.nMaxCustFilter = 0;
   fn.nFilterIndex = 0;

   fname[0] = 0;
   fn.lpstrFile = fname;
   fn.nMaxFile = MAX_PATH;

   fn.lpstrFileTitle = NULL;
   fn.nMaxFileTitle = 0;
   fn.lpstrInitialDir = NULL;

   LoadStringA(OLEDLG_hInstance, IDS_BROWSE, title, 32);
   fn.lpstrTitle = title;

   fn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST |
      OFN_HIDEREADONLY | OFN_LONGNAMES;
   fn.nFileOffset = 0;
   fn.nFileExtension = 0;
   fn.lpstrDefExt = NULL;
   fn.lCustData = 0;
   fn.lpfnHook = NULL;
   fn.lpTemplateName = NULL;

   if (GetOpenFileNameA(&fn))
   {
      HMODULE hMod;
      BOOL bValid = FALSE;

      hMod = LoadLibraryA(fn.lpstrFile);

      if (hMod)
      {
          DLLREGISTER regproc;

          regproc = (DLLREGISTER) GetProcAddress(hMod, "DllRegisterServer");
          if (regproc)
          {
             if (S_OK == regproc())
             {
                UIINSERTOBJECTDLG_PopulateObjectTypes(pdlgInfo);
                bValid = TRUE;
             }
          }

          FreeLibrary(hMod);
      }

      if (!bValid)
      {
          char title[32];
          char msg[256];

          LoadStringA(OLEDLG_hInstance, IDS_NOTOLEMODCAPTION, title, 32);
          LoadStringA(OLEDLG_hInstance, IDS_NOTOLEMOD, msg, 256);

          MessageBoxA(pdlgInfo->hwndSelf, msg, title, MB_ICONEXCLAMATION);
      }
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -