Source code of Windows XP (NT5)
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.

143 lines
3.8 KiB

  1. /* HTMLPREV.CPP
  2. **
  3. ** Copyright (c) 1997-1999 Microsoft Corporation. All Rights Reserved.
  4. **
  5. ** Display a preview of the HTML wallpaper background,
  6. ** complete with rudimentary palette handling and stretching
  7. ** of bitmaps to fit the preview screen.
  8. **
  9. */
  10. #include <windows.h>
  11. #include <mbctype.h>
  12. #include <objbase.h>
  13. #include <initguid.h>
  14. #include "..\inc\thmbguid.h"
  15. #include "..\inc\thmbobj.h"
  16. #define WM_HTML_BITMAP (WM_USER + 275) // IThumbnail::GetBitmap msg
  17. #define HTML_TIMER 777 // Unique timer ID
  18. // WARNING THESE ARE ALSO DEFINED IN FROST.H -- JUST DON'T WANT TO
  19. // INCLUDE ALL OF FROST.H HERE:
  20. #define MAX_MSGLEN 512
  21. // strings ids
  22. #define STR_APPNAME 0 // Application name (for title bar)
  23. #define STR_ERRHTML 26 // Error getting HTML wallpaper preview
  24. // GLOBALS
  25. extern "C" HWND hWndApp;
  26. IThumbnail *g_pthumb = NULL; // Html to Bitmap converter
  27. extern "C" BOOL InitHTMLBM()
  28. {
  29. HRESULT hr = E_FAIL;
  30. // Bring in the library
  31. hr = CoInitialize(NULL);
  32. if (FAILED(hr))
  33. {
  34. return FALSE;
  35. }
  36. hr = CoCreateInstance(CLSID_Thumbnail, NULL, CLSCTX_INPROC_SERVER,
  37. IID_IThumbnail, (void **)&g_pthumb);
  38. if(SUCCEEDED(hr))
  39. {
  40. g_pthumb->Init(hWndApp, WM_HTML_BITMAP);
  41. return TRUE;
  42. }
  43. else
  44. {
  45. // CoUninitialize();
  46. g_pthumb = NULL;
  47. return FALSE;
  48. }
  49. }
  50. extern "C" HBITMAP HtmlToBmp(LPCTSTR szHTML, LONG lWidth, LONG lHeight)
  51. {
  52. HBITMAP hbmWall;
  53. #ifndef UNICODE
  54. WCHAR wszFile[MAX_PATH];
  55. #endif
  56. DWORD dwItem = 13; // Random choice of numbers for dwItem
  57. UINT uCodePage;
  58. MSG msg;
  59. TCHAR szMessage[MAX_MSGLEN];
  60. TCHAR szTitle[MAX_MSGLEN];
  61. UINT_PTR uTimer = 0;
  62. uCodePage = _getmbcp();
  63. // Paranoid check just in case
  64. if (!g_pthumb) {
  65. return NULL;
  66. }
  67. // MessageBox(hWndApp, szHTML, TEXT("Calling GetBitMap"), MB_OK | MB_APPLMODAL);
  68. #ifndef UNICODE
  69. // IThumbnail interfaces expect wide strings. Need to
  70. // convert ANSI szHTML into UNICODE.
  71. MultiByteToWideChar(uCodePage, 0, szHTML, -1,
  72. wszFile, MAX_PATH);
  73. g_pthumb->GetBitmap(wszFile, dwItem, lWidth, lHeight);
  74. #else
  75. g_pthumb->GetBitmap(szHTML, dwItem, lWidth, lHeight);
  76. #endif
  77. // Set a timer so we don't spin forever waiting on a dead GetBitMap call
  78. uTimer = SetTimer(hWndApp, HTML_TIMER, 60000 /*60 sec*/, NULL);
  79. LoadString(NULL, STR_APPNAME, szTitle, MAX_MSGLEN);
  80. LoadString(NULL, STR_ERRHTML, szMessage, MAX_MSGLEN);
  81. ZeroMemory(&msg, sizeof(MSG));
  82. while (TRUE) {
  83. // First check for Bitmap done message
  84. ZeroMemory(&msg, sizeof(MSG));
  85. if (PeekMessage(&msg, hWndApp, WM_HTML_BITMAP,
  86. WM_HTML_BITMAP, PM_REMOVE)) {
  87. if (msg.wParam == dwItem && msg.lParam) {
  88. hbmWall = (HBITMAP)msg.lParam;
  89. if (uTimer) KillTimer(hWndApp, uTimer);
  90. return hbmWall;
  91. }
  92. else {
  93. if (uTimer) KillTimer(hWndApp, uTimer);
  94. MessageBox(hWndApp, szMessage, szTitle,
  95. MB_OK | MB_APPLMODAL | MB_ICONERROR);
  96. return NULL;
  97. }
  98. }
  99. // Now check to see if we've timed-out waiting on Getbitmap
  100. ZeroMemory(&msg, sizeof(MSG));
  101. if (PeekMessage(&msg, hWndApp, WM_TIMER, WM_TIMER, PM_REMOVE)) {
  102. if (msg.wParam == HTML_TIMER) {
  103. // We timed-out
  104. MessageBox(hWndApp, szMessage, szTitle,
  105. MB_OK | MB_APPLMODAL | MB_ICONERROR);
  106. return NULL;
  107. }
  108. }
  109. } // End While true
  110. // SHOULDN'T EVER FALL THROUGH TO THIS BUT JUST IN CASE
  111. return NULL;
  112. }
  113. extern "C" void CleanUp()
  114. {
  115. if (g_pthumb) g_pthumb->Release();
  116. g_pthumb = NULL;
  117. CoUninitialize();
  118. return;
  119. }