webinfo_dlg.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. #include "main.h"
  2. #include "api__gen_ml.h"
  3. #include "./resource.h"
  4. #include "./webinfo_obj.h"
  5. #include "../nu/mtbrowser.h"
  6. #include "./ml_ipc_0313.h"
  7. #include "./stockobjects.h"
  8. #include "../nu/CGlobalAtom.h"
  9. #include <strsafe.h>
  10. #define BROWSER_FORCEQUITDELAY 5000
  11. #define BROWSER_TERMINATEDELAY 3000
  12. #define BROWSER_CACHEINTERVAL 3000
  13. #define TIMER_BROWSERFORCEQUIT_ID 1975
  14. #define TIMER_BROWSERCACHE_ID 1976
  15. #define TIMER_BROWSERLOADINGNOTICE_ID 1977
  16. #define TIMER_BROWSERLOADINGNOTICE_DELAY 80
  17. #define WEBINFOWND_CLASSW L"WAWEBINFOWND"
  18. static CGlobalAtom BROWSERWND_PROPW(L"BWPROP");
  19. #define WM_BROWSERNOTIFY (WM_USER + 0xF000)
  20. #define IDC_LBL_INFO 0x100
  21. #define IDC_BROWSER 0x1000
  22. typedef struct _BROWSERVIEW
  23. {
  24. MTBROWSER browser;
  25. BOOL bBrowserReady;
  26. BOOL bDestroying;
  27. UINT uMsgQuery;
  28. LPWSTR pszCachedFileName;
  29. } BROWSERVIEW;
  30. static HWND hwndCached = NULL;
  31. static LRESULT WINAPI WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  32. static void CALLBACK Window_TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
  33. #define GetBrowserView(_hwnd) ((BROWSERVIEW*)GetPropW(_hwnd, BROWSERWND_PROPW))
  34. // public function
  35. HWND CreateWebInfoWindow(HWND hwndParent, UINT uMsgQuery, INT x, INT y, INT cx, INT cy, INT ctrlId)
  36. {
  37. HWND hwnd;
  38. BROWSERVIEW *pbv;
  39. WNDCLASSW wc;
  40. if (hwndCached && IsWindow(hwndCached))
  41. {
  42. pbv = GetBrowserView(hwndCached);
  43. if (pbv)
  44. {
  45. KillTimer(hwndCached, TIMER_BROWSERCACHE_ID);
  46. hwnd = hwndCached;
  47. hwndCached = NULL;
  48. pbv->uMsgQuery = uMsgQuery;
  49. pbv->bDestroying = FALSE;
  50. pbv->pszCachedFileName = NULL;
  51. ShowWindow(hwnd, SW_HIDE);
  52. SetParent(hwnd, hwndParent);
  53. SetWindowPos(hwnd, HWND_TOP, x, y, cx, cy, SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOCOPYBITS);
  54. SetWindowLongPtrW(hwnd, GWLP_ID, ctrlId);
  55. return hwnd;
  56. }
  57. }
  58. if (!GetClassInfoW(plugin.hDllInstance, WEBINFOWND_CLASSW, &wc))
  59. {
  60. ZeroMemory(&wc, sizeof(WNDCLASSW));
  61. wc.hInstance = plugin.hDllInstance;
  62. wc.lpszClassName = WEBINFOWND_CLASSW;
  63. wc.lpfnWndProc = WindowProc;
  64. wc.style = CS_DBLCLKS;
  65. if (!RegisterClassW(&wc)) return NULL;
  66. }
  67. pbv = (BROWSERVIEW*)calloc(1, sizeof(BROWSERVIEW));
  68. if (!pbv) return NULL;
  69. pbv->uMsgQuery = uMsgQuery;
  70. hwnd = CreateWindowExW(WS_EX_CONTROLPARENT, WEBINFOWND_CLASSW, L"",
  71. DS_CONTROL | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
  72. x, y, cx, cy, hwndParent, (HMENU)(INT_PTR)ctrlId, plugin.hDllInstance, (LPVOID)pbv);
  73. if (!hwnd) free(pbv);
  74. else
  75. {
  76. HFONT font;
  77. HWND hwndCtrl;
  78. hwndCtrl = CreateWindowExW(WS_EX_NOPARENTNOTIFY, L"STATIC", L"",
  79. WS_CHILD | SS_OWNERDRAW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  80. 0, 0, 1, 1, hwnd, (HMENU)IDC_LBL_INFO, NULL, 0);
  81. font = (HFONT)MlStockObjects_Get(DEFAULT_FONT);
  82. SendMessageW(hwnd, WM_SETFONT, (WPARAM)font, FALSE);
  83. if (hwndCtrl) SendMessageW(hwndCtrl, WM_SETFONT, (WPARAM)font, FALSE);
  84. }
  85. return hwnd;
  86. }
  87. static void CALLBACK APC_NavigateToPage(HTMLContainer2 *pContainer, VARIANTARG *pArgs, INT cArgs, LPARAM *pResult)
  88. {
  89. WebFileInfo *pWebInfo;
  90. pWebInfo = reinterpret_cast<WebFileInfo*>(pContainer);
  91. pWebInfo->NavigateToPage();
  92. }
  93. static void CALLBACK APC_InvokeFileInfo(HTMLContainer2 *pContainer, VARIANTARG *pArgs, INT cArgs, LPARAM *pResult)
  94. {
  95. WebFileInfo *pWebInfo;
  96. pWebInfo = reinterpret_cast<WebFileInfo*>(pContainer);
  97. *pResult = (pWebInfo && 1 == cArgs) ? pWebInfo->InvokeFileInfo(pArgs[0].bstrVal) : E_INVALIDARG;
  98. }
  99. static void CALLBACK APC_DisplayMessage(HTMLContainer2 *pContainer, VARIANTARG *pArgs, INT cArgs, LPARAM *pResult)
  100. {
  101. WebFileInfo *pWebInfo;
  102. pWebInfo = reinterpret_cast<WebFileInfo*>(pContainer);
  103. *pResult = (pWebInfo && 1 == cArgs) ? pWebInfo->DisplayMessage(pArgs[0].bstrVal, FALSE) : E_INVALIDARG;
  104. }
  105. static void CALLBACK APC_GetHostHWND(HTMLContainer2 *pContainer, VARIANTARG *pArgs, INT cArgs, LPARAM *pResult)
  106. {
  107. if (1 == cArgs)
  108. {
  109. *((HWND*)pArgs[0].byref) = pContainer->GetHostHWND();
  110. *pResult = S_OK;
  111. }
  112. else *pResult = E_INVALIDARG;
  113. }
  114. static void CALLBACK APC_RegisterCursor(HTMLContainer2 *pContainer, VARIANTARG *pArgs, INT cArgs, LPARAM *pResult)
  115. {
  116. if (1 == cArgs)
  117. {
  118. HCURSOR hCur = (pArgs[0].byref) ? CopyCursor((HCURSOR)pArgs[0].byref) : NULL;
  119. *pResult = pContainer->RegisterBrowserCursor(/*OCR_NORMAL*/32512, hCur);
  120. }
  121. else *pResult = E_INVALIDARG;
  122. }
  123. static void CALLBACK APC_UpdateColors(HTMLContainer2 *pContainer, VARIANTARG *pArgs, INT cArgs, LPARAM *pResult)
  124. {
  125. WebFileInfo *pWebInfo;
  126. pWebInfo = reinterpret_cast<WebFileInfo*>(pContainer);
  127. if (pWebInfo) pWebInfo->UpdateColors();
  128. }
  129. static void DisplayInfoText(HWND hwndView, LPCWSTR pszText)
  130. {
  131. HWND hwndCtrl;
  132. hwndCtrl = GetDlgItem(hwndView, IDC_LBL_INFO);
  133. if (!hwndCtrl) return;
  134. if (pszText)
  135. {
  136. SetWindowTextW(hwndCtrl, pszText);
  137. if (!IsWindowVisible(hwndCtrl))
  138. {
  139. RECT rc;
  140. GetClientRect(hwndView, &rc);
  141. SetWindowPos(hwndCtrl, NULL, 8, 8, rc.right - 16, rc.bottom - 16, SWP_NOACTIVATE | SWP_NOZORDER);
  142. ShowWindow(hwndCtrl, SW_SHOWNORMAL);
  143. }
  144. }
  145. else ShowWindow(hwndCtrl, SW_HIDE);
  146. }
  147. static LRESULT Window_OnCreate(HWND hwnd, CREATESTRUCT *pcs)
  148. {
  149. BROWSERVIEW *pbv;
  150. pbv =(BROWSERVIEW*)pcs->lpCreateParams;
  151. if (pbv)
  152. {
  153. SetPropW(hwnd, BROWSERWND_PROPW, (HANDLE)pbv);
  154. pbv->bBrowserReady = FALSE;
  155. MTBrowser_Init(&pbv->browser);
  156. }
  157. return 0;
  158. }
  159. static void Window_OnDestroy(HWND hwnd)
  160. {
  161. BROWSERVIEW *pbv;
  162. pbv = GetBrowserView(hwnd);
  163. RemovePropW(hwnd, BROWSERWND_PROPW);
  164. KillTimer(hwnd, TIMER_BROWSERFORCEQUIT_ID);
  165. if (pbv)
  166. {
  167. pbv->bBrowserReady = FALSE;
  168. MTBrowser_Kill(&pbv->browser, BROWSER_TERMINATEDELAY);
  169. MTBrowser_Clear(&pbv->browser);
  170. }
  171. free(pbv);
  172. CoFreeUnusedLibraries();
  173. }
  174. static BOOL UpdateCursors(BROWSERVIEW *pbv)
  175. {
  176. HCURSOR hCur;
  177. HAPC hAPC;
  178. VARIANTARG *pArgs;
  179. if (!pbv) return FALSE;
  180. hCur = (HCURSOR)SendMessageW(plugin.hwndParent, WM_WA_IPC, WACURSOR_NORMAL, IPC_GETSKINCURSORS);
  181. hAPC = MTBrowser_InitializeAPC(&pbv->browser, 1, 0, APC_RegisterCursor, &pArgs);
  182. if (!hAPC) return FALSE;
  183. pArgs[0].vt = VT_BYREF;
  184. V_BYREF(&pArgs[0]) = hCur;
  185. return MTBrowser_CallAPC(hAPC);
  186. }
  187. static void Window_OnDisplayChange(HWND hwnd, INT dpi, INT resX, INT resY)
  188. {
  189. HWND hwndCtrl;
  190. BROWSERVIEW *pbv;
  191. pbv = GetBrowserView(hwnd);
  192. if (pbv)
  193. {
  194. HAPC hAPC;
  195. UpdateCursors(pbv);
  196. hAPC = MTBrowser_InitializeAPC(&pbv->browser, 0, 0, APC_UpdateColors, NULL);
  197. if (hAPC) MTBrowser_CallAPC(hAPC);
  198. }
  199. InvalidateRect(hwnd, NULL, TRUE);
  200. hwndCtrl = GetDlgItem(hwnd, IDC_LBL_INFO);
  201. if (hwndCtrl) InvalidateRect(hwndCtrl, NULL, TRUE);
  202. }
  203. static void Window_OnShowWindow(HWND hwnd, BOOL bVisible, INT nStatus)
  204. {
  205. BROWSERVIEW *pbv;
  206. pbv = GetBrowserView(hwnd);
  207. if (pbv && !pbv->browser.hThread && bVisible)
  208. {
  209. WebFileInfo *pWebInfo;
  210. IDispatch *pDispWA;
  211. pDispWA = (IDispatch *)SendMessageW(plugin.hwndParent, WM_WA_IPC, 0, IPC_GET_DISPATCH_OBJECT);
  212. if (pDispWA == (IDispatch*)1) pDispWA = NULL;
  213. pWebInfo = CreateWebFileInfo(hwnd, pDispWA);
  214. if (NULL != pWebInfo)
  215. {
  216. SetTimer(hwnd, TIMER_BROWSERLOADINGNOTICE_ID, TIMER_BROWSERLOADINGNOTICE_DELAY, Window_TimerProc);
  217. MTBrowser_Start(&pbv->browser, pWebInfo, WM_BROWSERNOTIFY);
  218. }
  219. else
  220. {
  221. DisplayInfoText(hwnd, WASABI_API_LNGSTRINGW(IDS_WEBINFO_NAVIGATE_ERROR));
  222. }
  223. if (NULL != pDispWA)
  224. pDispWA->Release();
  225. }
  226. if(bVisible && pbv && pbv->uMsgQuery)
  227. {
  228. HWND hwndParent;
  229. hwndParent = GetParent(hwnd);
  230. if (hwndParent) PostMessageW(hwndParent, pbv->uMsgQuery, 0, 0L);
  231. }
  232. }
  233. static LRESULT Window_OnEraseBkGnd(HWND hwnd, HDC hdc)
  234. {
  235. if (hdc)
  236. {
  237. RECT rc;
  238. GetClientRect(hwnd, &rc);
  239. SetBkColor(hdc, WADlg_getColor(WADLG_ITEMBG));
  240. ExtTextOutW(hdc, 0, 0, ETO_OPAQUE, &rc, L"", 0, 0);
  241. }
  242. return 1;
  243. }
  244. static void Window_OnShowInfo(HWND hwnd, WEBINFOSHOW *pShowParam)
  245. {
  246. HAPC hAPC;
  247. VARIANTARG *pArgs;
  248. BROWSERVIEW *pbv = GetBrowserView(hwnd);
  249. if (!IsWindowVisible(hwnd) || !pbv || !pbv->bBrowserReady || !pShowParam)
  250. {
  251. if (pbv && pbv->pszCachedFileName)
  252. {
  253. free(pbv->pszCachedFileName);
  254. pbv->pszCachedFileName = NULL;
  255. }
  256. return;
  257. }
  258. if (pShowParam->pszFileName)
  259. {
  260. if (0 == (WISF_FORCE & pShowParam->fFlags) && pbv->pszCachedFileName &&
  261. 0 == lstrcmpW(pbv->pszCachedFileName, pShowParam->pszFileName)) return;
  262. else
  263. {
  264. if (pbv->pszCachedFileName) free(pbv->pszCachedFileName);
  265. pbv->pszCachedFileName = _wcsdup(pShowParam->pszFileName);
  266. }
  267. }
  268. else
  269. {
  270. if (0 == (WISF_FORCE & pShowParam->fFlags) && !pbv->pszCachedFileName) return;
  271. if (pbv->pszCachedFileName)
  272. {
  273. free(pbv->pszCachedFileName);
  274. pbv->pszCachedFileName = NULL;
  275. }
  276. }
  277. hAPC = MTBrowser_InitializeAPC(&pbv->browser, 1, 0, (WISF_MESSAGE & pShowParam->fFlags) ? APC_DisplayMessage : APC_InvokeFileInfo , &pArgs);
  278. if (hAPC)
  279. {
  280. pArgs[0].vt = VT_BSTR;
  281. pArgs[0].bstrVal = SysAllocString(pShowParam->pszFileName);
  282. MTBrowser_CallAPC(hAPC);
  283. }
  284. }
  285. static void Window_OnWindowPosChanging(HWND hwnd, WINDOWPOS *pwp)
  286. {
  287. if (0 == (SWP_NOSIZE & pwp->flags))
  288. {
  289. BROWSERVIEW *pbv;
  290. pbv = GetBrowserView(hwnd);
  291. if (pbv && pbv->bBrowserReady)
  292. {
  293. RECT rc;
  294. HWND hBrowser = GetDlgItem(hwnd, IDC_BROWSER);
  295. if (NULL != hBrowser && FALSE != GetClientRect(hBrowser, &rc) &&
  296. (rc.right != pwp->cx || rc.bottom != pwp->cy))
  297. {
  298. SetWindowPos(hBrowser, NULL, 0, 0, pwp->cx, pwp->cy,
  299. SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS | ((SWP_NOREDRAW | SWP_NOCOPYBITS) & pwp->flags));
  300. }
  301. }
  302. }
  303. }
  304. static void Window_OnWindowPosChanged(HWND hwnd, WINDOWPOS *pwp)
  305. {
  306. if (0 == (SWP_NOSIZE & pwp->flags))
  307. {
  308. HWND hwndCtrl;
  309. hwndCtrl = GetDlgItem(hwnd, IDC_LBL_INFO);
  310. if (hwndCtrl && WS_VISIBLE == (WS_VISIBLE & GetWindowLongPtrW(hwnd, GWL_STYLE)))
  311. {
  312. SetWindowPos(hwndCtrl, NULL, 0, 0, pwp->cx - 16, pwp->cy - 16,
  313. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOCOPYBITS | SWP_NOREDRAW);
  314. if (0 == (SWP_NOREDRAW & pwp->flags)) InvalidateRect(hwndCtrl, NULL, FALSE);
  315. }
  316. if (0 == (SWP_NOREDRAW & pwp->flags))
  317. {
  318. HWND hBrowser = GetDlgItem(hwnd, IDC_BROWSER);
  319. if (NULL == hBrowser || 0 == (WS_VISIBLE & GetWindowLongPtr(hBrowser, GWL_STYLE)))
  320. InvalidateRect(hwnd, NULL, TRUE);
  321. }
  322. }
  323. }
  324. static void DrawInfoLabel(DRAWITEMSTRUCT *pds)
  325. {
  326. wchar_t szText[128] = {0};
  327. SetBkColor(pds->hDC, WADlg_getColor(WADLG_ITEMBG));
  328. INT len = GetWindowTextW(pds->hwndItem, szText, sizeof(szText)/sizeof(wchar_t));
  329. ExtTextOutW(pds->hDC, 0, 0, ETO_OPAQUE, &pds->rcItem, L"", 0, 0);
  330. if(len)
  331. {
  332. RECT rt;
  333. INT height, x, y;
  334. CopyRect(&rt, &pds->rcItem);
  335. height = DrawTextW(pds->hDC, szText, len, &rt, DT_CALCRECT | DT_CENTER | DT_WORDBREAK);
  336. SetTextColor(pds->hDC, WADlg_getColor(WADLG_ITEMFG));
  337. y = pds->rcItem.top + ((pds->rcItem.bottom - pds->rcItem.top) - height)/2;
  338. if (y < pds->rcItem.top) y = pds->rcItem.top;
  339. x = pds->rcItem.left + ((pds->rcItem.right - pds->rcItem.left) - (rt.right - rt.left))/2;
  340. SetRect(&rt, x, y, x + rt.right- rt.left, y + rt.bottom - rt.top);
  341. DrawTextW(pds->hDC, szText, len, &rt, DT_CENTER | DT_WORDBREAK);
  342. }
  343. }
  344. static LRESULT Window_OnDrawItem(HWND hwnd, INT ctrlID, DRAWITEMSTRUCT *pds)
  345. {
  346. switch(ctrlID)
  347. {
  348. case IDC_LBL_INFO: DrawInfoLabel(pds); return 1;
  349. }
  350. return 0;
  351. }
  352. static void Browser_OnDocumentComplete(HWND hwndView, BROWSERVIEW *pbv, BOOL bDocReady)
  353. {
  354. if (bDocReady)
  355. {
  356. RECT rc;
  357. KillTimer(hwndView, TIMER_BROWSERLOADINGNOTICE_ID);
  358. DisplayInfoText(hwndView, NULL); // hide
  359. GetClientRect(hwndView, &rc);
  360. MTBrowser_SetLocationAPC(&pbv->browser, &rc);
  361. }
  362. }
  363. static void Browser_OnDestroyed(HWND hwndView, BROWSERVIEW *pbv)
  364. {
  365. if (pbv->bDestroying) DestroyWindow(hwndView);
  366. else {} // browser died for some reason
  367. }
  368. static void Browser_OnReady(HWND hwndView, BROWSERVIEW *pbv)
  369. {
  370. if (NULL == pbv) return;
  371. pbv->bBrowserReady = TRUE;
  372. HWND hBrowser = (NULL != pbv->browser.pContainer) ? pbv->browser.pContainer->GetHostHWND() : NULL;
  373. if (NULL != hBrowser)
  374. SetWindowLongPtr(hBrowser, GWLP_ID, IDC_BROWSER);
  375. UpdateCursors(pbv);
  376. HWND hParent = GetParent(hwndView);
  377. if (NULL != hParent && 0 != pbv->uMsgQuery) PostMessageW(hParent, pbv->uMsgQuery, 0, 0L);
  378. }
  379. static void CALLBACK Window_TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
  380. {
  381. BROWSERVIEW *pbv;
  382. switch(idEvent)
  383. {
  384. case TIMER_BROWSERFORCEQUIT_ID:
  385. KillTimer(hwnd, TIMER_BROWSERFORCEQUIT_ID);
  386. DestroyWindow(hwnd);
  387. break;
  388. case TIMER_BROWSERCACHE_ID:
  389. KillTimer(hwnd, TIMER_BROWSERCACHE_ID);
  390. pbv = GetBrowserView(hwnd);
  391. if (hwnd == hwndCached) hwndCached = NULL;
  392. if (pbv && pbv->bDestroying)
  393. {
  394. pbv->bBrowserReady = FALSE;
  395. MTBrowser_QuitAPC(&pbv->browser);
  396. SetTimer(hwnd, TIMER_BROWSERFORCEQUIT_ID, BROWSER_FORCEQUITDELAY, Window_TimerProc);
  397. }
  398. else DestroyWindow(hwnd);
  399. break;
  400. case TIMER_BROWSERLOADINGNOTICE_ID:
  401. KillTimer(hwnd, TIMER_BROWSERLOADINGNOTICE_ID);
  402. DisplayInfoText(hwnd, WASABI_API_LNGSTRINGW(IDS_LOADING_IN_PROGRESS));
  403. break;
  404. }
  405. }
  406. static void Window_OnRelease(HWND hwnd)
  407. {
  408. BROWSERVIEW *pbv;
  409. pbv = GetBrowserView(hwnd);
  410. if (pbv)
  411. {
  412. hwndCached = hwnd;
  413. pbv->bDestroying = TRUE;
  414. if (pbv->pszCachedFileName)
  415. {
  416. free(pbv->pszCachedFileName);
  417. pbv->pszCachedFileName = NULL;
  418. }
  419. SetWindowPos(hwnd, HWND_BOTTOM, -30000, -30000, 1, 1, SWP_ASYNCWINDOWPOS | SWP_HIDEWINDOW | SWP_NOACTIVATE |
  420. SWP_NOREDRAW | SWP_DEFERERASE | SWP_NOCOPYBITS | SWP_NOSENDCHANGING);
  421. SetParent(hwnd, plugin.hwndParent);
  422. SetTimer(hwnd, TIMER_BROWSERCACHE_ID, BROWSER_CACHEINTERVAL, Window_TimerProc);
  423. }
  424. else DestroyWindow(hwnd);
  425. }
  426. static void Window_OnBrowserNotify(HWND hwnd, INT nCode, LPARAM lParam)
  427. {
  428. BROWSERVIEW *pbv;
  429. pbv = GetBrowserView(hwnd);
  430. if (!pbv) return;
  431. switch(nCode)
  432. {
  433. case MTBC_READY: Browser_OnReady(hwnd, pbv); break;
  434. case MTBC_DESTROYED: Browser_OnDestroyed(hwnd, pbv); break;
  435. case MTBC_DOCUMENTCOMPLETE: Browser_OnDocumentComplete(hwnd, pbv, (BOOL)lParam); break;
  436. }
  437. }
  438. static LRESULT Window_OnMediaLibraryIPC(HWND hwndView, INT msg, INT_PTR param)
  439. {
  440. switch(msg)
  441. {
  442. case ML_IPC_WEBINFO_RELEASE: Window_OnRelease(hwndView); return TRUE;
  443. case ML_IPC_WEBINFO_SHOWINFO: Window_OnShowInfo(hwndView, (WEBINFOSHOW*)param); return TRUE;
  444. }
  445. return 0;
  446. }
  447. static LRESULT WINAPI WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  448. {
  449. switch(uMsg)
  450. {
  451. case WM_CREATE: return (LRESULT)Window_OnCreate(hwnd, (CREATESTRUCT*)lParam);
  452. case WM_DESTROY: Window_OnDestroy(hwnd); break;
  453. case WM_DISPLAYCHANGE: Window_OnDisplayChange(hwnd, (INT)wParam, LOWORD(lParam), HIWORD(lParam)); break;
  454. case WM_SHOWWINDOW: Window_OnShowWindow(hwnd, (BOOL)wParam, (INT)lParam); break;
  455. case WM_WINDOWPOSCHANGING: Window_OnWindowPosChanging(hwnd, (WINDOWPOS*)lParam); return 0;
  456. case WM_WINDOWPOSCHANGED: Window_OnWindowPosChanged(hwnd, (WINDOWPOS*)lParam); return 0;
  457. case WM_ERASEBKGND: return (LRESULT)Window_OnEraseBkGnd(hwnd, (HDC)wParam);
  458. case WM_DRAWITEM: return Window_OnDrawItem(hwnd, (INT)wParam, (DRAWITEMSTRUCT*)lParam);
  459. case WM_BROWSERNOTIFY: Window_OnBrowserNotify(hwnd, (INT)wParam, lParam); return 1;
  460. case WM_ML_IPC:
  461. return Window_OnMediaLibraryIPC(hwnd, (INT)lParam, (INT_PTR)wParam);
  462. }
  463. return DefWindowProcW(hwnd, uMsg, wParam, lParam);
  464. }