Subversion Repositories pentevo

Rev

Rev 796 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. #include "std.h"
  2.  
  3. #include "emul.h"
  4. #include "vars.h"
  5. #include "draw.h"
  6. #include "iehelp.h"
  7.  
  8. #include "util.h"
  9.  
  10. static HMODULE hMSHTML = nullptr, hURLMON = nullptr;
  11.  
  12.  
  13. typedef HRESULT (WINAPI *tCreateURLMoniker)(IMoniker*,WCHAR*,IMoniker**);
  14. typedef HRESULT (WINAPI *tShowHTMLDialog)(HWND,IMoniker*,VARIANT*,WCHAR*,VARIANT*);
  15.  
  16. void init_ie_help() { }
  17.  
  18. void done_ie_help()
  19. {
  20.     if(hMSHTML)
  21.     {
  22.         FreeLibrary(hMSHTML);
  23.         hMSHTML = nullptr;
  24.     }
  25.     if(hURLMON)
  26.     {
  27.         FreeLibrary(hURLMON);
  28.         hURLMON = nullptr;
  29.     }
  30. }
  31.  
  32. void showhelppp(const char *anchor) //Alone Coder 0.36.6
  33. {
  34.    if (!hMSHTML) hMSHTML = LoadLibrary("MSHTML.DLL");
  35.    if (!hURLMON) hURLMON = LoadLibrary("URLMON.DLL");
  36.  
  37.    tShowHTMLDialog Show = hMSHTML? (tShowHTMLDialog)GetProcAddress(hMSHTML, "ShowHTMLDialog") : nullptr;
  38.    tCreateURLMoniker CreateMoniker = hURLMON? (tCreateURLMoniker)GetProcAddress(hURLMON, "CreateURLMoniker") : nullptr;
  39.  
  40.    HWND fgwin = GetForegroundWindow();
  41.    if (!Show || !CreateMoniker)
  42.    { MessageBox(fgwin, "Install IE4.0 or higher to view help", nullptr, MB_ICONERROR); return; }
  43.  
  44.    char dst[0x200];
  45.    GetTempPath(sizeof dst, dst); strcat(dst, "us_help.htm");
  46.  
  47.    FILE *ff = fopen(helpname, "rb"), *gg = fopen(dst, "wb");
  48.    if(ff == nullptr)
  49.    {
  50.        return;
  51.    }
  52.    if(gg == nullptr)
  53.    {
  54.        fclose(ff);
  55.        return;
  56.    }
  57.  
  58.    for (;;)
  59.    {
  60.       int x = getc(ff);
  61.       if (x == EOF) break;
  62.       if (x == '{')
  63.       {
  64.          char tag[0x100]; size_t r = 0;
  65.          while (r < sizeof(tag)-1 && !feof(ff) && (x = getc(ff)) != '}')
  66.              tag[r++] = char(x);
  67.          tag[r] = 0;
  68.          if (tag[0] == '?')
  69.          {
  70.             RECT rc;
  71.             GetWindowRect(fgwin, &rc);
  72.             if (tag[1] == 'x')
  73.                 fprintf(gg, "%ld", rc.right-rc.left-20);
  74.             if (tag[1] == 'y')
  75.                 fprintf(gg, "%ld", rc.bottom-rc.top-20);
  76.          }
  77.          else
  78.          {
  79.             char res[0x100]; GetPrivateProfileString("SYSTEM.KEYS", tag, "not defined", res, sizeof res, ininame);
  80.             char *comment = strchr(res, ';'); if (comment) *comment = 0;
  81.             size_t len; //Alone Coder 0.36.7
  82.             for (/*int*/ len = strlen(res); len && res[len-1] == ' '; res[--len] = 0);
  83.             for (len = 0; res[len]; len++) if (res[len] == ' ') res[len] = '-';
  84.             fprintf(gg, "%s", res);
  85.          }
  86.       } else putc(x, gg);
  87.    }
  88.    fclose(ff);
  89.    fclose(gg);
  90.  
  91.    char url[0x200];
  92.    sprintf(url, "file://%s%s%s", dst, anchor?"#":nil, anchor?anchor:nil);
  93.    WCHAR urlw[0x200];
  94.    MultiByteToWideChar(AreFileApisANSI()? CP_ACP : CP_OEMCP, MB_USEGLYPHCHARS, url, -1, urlw, _countof(urlw));
  95.    IMoniker *pmk = nullptr;
  96.    CreateMoniker(nullptr, urlw, &pmk);
  97.  
  98.    if (pmk)
  99.    {
  100.       bool restore_video = false;
  101.       if(!(temp.rflags & (RF_GDI | RF_CLIP | RF_OVR | RF_16 | RF_32)))
  102.       {
  103.           temp.rflags = temp.rflags | RF_GDI;
  104.           set_video();
  105.           restore_video = true;
  106.       }
  107.       Show(fgwin, pmk, nullptr, nullptr, nullptr);
  108.       pmk->Release();
  109.  
  110.       if(dbgbreak)
  111.       {
  112.           temp.rflags = RF_MONITOR;
  113.           set_video();
  114.       }
  115.       else
  116.       {
  117.           if(restore_video)
  118.               apply_video();
  119.       }
  120.    }
  121.  
  122.    DeleteFile(dst);
  123. }
  124.  
  125.