Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.2 KiB

  1. // icwtutor.cpp : Defines the entry point for the application.
  2. //
  3. #include <windows.h>
  4. #include <urlmon.h>
  5. #include <mshtmhst.h>
  6. #include <locale.h>
  7. #define STR_BSTR 0
  8. #define STR_OLESTR 1
  9. #define ARRAYSIZE(a) (sizeof(a)/sizeof((a)[0]))
  10. #define A2B(x) (BSTR)A2W((LPSTR)(x), STR_BSTR)
  11. LPWSTR A2W (LPSTR psz, BYTE bType);
  12. BSTR GetHtmFileFromCommandLine (HINSTANCE hInst, LPSTR lpCmdLine);
  13. BOOL bFileFromCmdLine = FALSE;
  14. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  15. {
  16. HINSTANCE hinstMSHTML = NULL;
  17. #ifdef UNICODE
  18. // Initialize the C runtime locale to the system locale.
  19. setlocale(LC_ALL, "");
  20. #endif
  21. hinstMSHTML = LoadLibrary(TEXT("MSHTML.DLL"));
  22. if(hinstMSHTML)
  23. {
  24. SHOWHTMLDIALOGFN *pfnShowHTMLDialog = NULL;
  25. pfnShowHTMLDialog = (SHOWHTMLDIALOGFN*)GetProcAddress(hinstMSHTML, "ShowHTMLDialog");
  26. if(pfnShowHTMLDialog)
  27. {
  28. IMoniker *pmk = NULL;
  29. BSTR bstrHtmFilePath = NULL;
  30. bstrHtmFilePath = GetHtmFileFromCommandLine(hInstance, lpCmdLine);
  31. CreateURLMoniker(NULL, bstrHtmFilePath, &pmk);
  32. SysFreeString(bstrHtmFilePath);
  33. if(pmk)
  34. {
  35. if(bFileFromCmdLine)
  36. (*pfnShowHTMLDialog)(NULL, pmk, NULL, A2B("help: no"), NULL);
  37. else
  38. (*pfnShowHTMLDialog)(NULL, pmk, NULL, A2B("dialogWidth: 36.5em; dialogHeight: 25.5em; help: no"), NULL);
  39. pmk->Release();
  40. }
  41. }
  42. FreeLibrary(hinstMSHTML);
  43. }
  44. return 0;
  45. }
  46. BSTR GetHtmFileFromCommandLine(HINSTANCE hInst, LPSTR lpCmdLine)
  47. {
  48. CHAR szTemp [MAX_PATH*2] = "\0";
  49. if (*lpCmdLine == '\"')
  50. {
  51. lstrcpynA(szTemp,
  52. lpCmdLine + 1,
  53. lstrlenA(lpCmdLine) - 1);
  54. }
  55. else
  56. {
  57. lstrcpyA(szTemp,
  58. lpCmdLine);
  59. }
  60. if (GetFileAttributesA(szTemp) != 0xFFFFFFFF)
  61. {
  62. bFileFromCmdLine = TRUE;
  63. return A2B(szTemp);
  64. }
  65. lstrcpyA(szTemp, "res://");
  66. GetModuleFileNameA(hInst, szTemp + lstrlenA(szTemp), ARRAYSIZE(szTemp) - lstrlenA(szTemp));
  67. lstrcatA(szTemp, "/Default.htm");
  68. return A2B(szTemp);
  69. }
  70. LPWSTR A2W(LPSTR psz, BYTE bType)
  71. {
  72. int i;
  73. LPWSTR pwsz;
  74. if (!psz)
  75. return(NULL);
  76. // compute the length of the required BSTR
  77. if ((i = MultiByteToWideChar(CP_ACP, 0, psz, -1, NULL, 0)) <= 0)
  78. return NULL;
  79. switch (bType)
  80. {
  81. case STR_BSTR:
  82. // SysAllocStringLen adds 1
  83. pwsz = (LPWSTR)SysAllocStringLen(NULL, (i - 1));
  84. break;
  85. case STR_OLESTR:
  86. pwsz = (LPWSTR)CoTaskMemAlloc(i * sizeof(WCHAR));
  87. break;
  88. default:
  89. return(NULL);
  90. }
  91. if (!pwsz)
  92. return(NULL);
  93. MultiByteToWideChar(CP_ACP, 0, psz, -1, pwsz, i);
  94. pwsz[i - 1] = 0;
  95. return(pwsz);
  96. }