main.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  17. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  20. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #include "config.h"
  25. #include "WebView.h"
  26. #include <windows.h>
  27. #include <wtf/PassOwnPtr.h>
  28. static const LPCWSTR kMainWindowTitle = L"WebKit for WinCE";
  29. static const LPCWSTR kMainWindowClassName = L"MainWindowClass";
  30. static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  31. {
  32. switch (message) {
  33. case WM_DESTROY:
  34. PostQuitMessage(0);
  35. break;
  36. default:
  37. return DefWindowProc(hWnd, message, wParam, lParam);
  38. }
  39. return 0;
  40. }
  41. int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
  42. {
  43. UNREFERENCED_PARAMETER(hPrevInstance);
  44. CoInitializeEx(0, COINIT_MULTITHREADED);
  45. WebView::initialize(hInstance);
  46. LPCWSTR homeUrl = lpCmdLine;
  47. bool enableDoubleBuffer = true;
  48. bool fullscreen = false;
  49. if (homeUrl[0] == '-') {
  50. for (; *homeUrl && *homeUrl != ' '; ++homeUrl) {
  51. switch (*homeUrl) {
  52. case 'd':
  53. enableDoubleBuffer = false;
  54. break;
  55. case 'f':
  56. fullscreen = true;
  57. break;
  58. default:
  59. break;
  60. }
  61. }
  62. if (*homeUrl)
  63. ++homeUrl;
  64. }
  65. DWORD styles = WS_VISIBLE;
  66. if (!fullscreen) {
  67. styles |= WS_CAPTION
  68. | WS_MAXIMIZEBOX
  69. | WS_MINIMIZEBOX
  70. | WS_OVERLAPPED
  71. | WS_SYSMENU
  72. | WS_THICKFRAME;
  73. }
  74. WNDCLASSW wc;
  75. wc.style = CS_HREDRAW | CS_VREDRAW;
  76. wc.lpfnWndProc = WndProc;
  77. wc.cbClsExtra = 0;
  78. wc.cbWndExtra = 0;
  79. wc.hInstance = hInstance;
  80. wc.hIcon = 0;
  81. wc.hCursor = 0;
  82. wc.hbrBackground = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
  83. wc.lpszMenuName = 0;
  84. wc.lpszClassName = kMainWindowClassName;
  85. RegisterClass(&wc);
  86. HWND hMainWindow = CreateWindowW(kMainWindowClassName, kMainWindowTitle, styles,
  87. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInstance, 0);
  88. if (fullscreen) {
  89. SetWindowPos(hMainWindow, HWND_TOPMOST, 0, 0, GetSystemMetrics(SM_CXSCREEN),
  90. GetSystemMetrics(SM_CYSCREEN), SWP_SHOWWINDOW);
  91. }
  92. ShowWindow(hMainWindow, nCmdShow);
  93. UpdateWindow(hMainWindow);
  94. WTF::OwnPtr<WebView> webView = WTF::adoptPtr(new WebView(hMainWindow, enableDoubleBuffer ? WebView::EnableDoubleBuffering : WebView::NoFeature));
  95. webView->load(homeUrl);
  96. // Main message loop:
  97. MSG msg;
  98. BOOL bRet;
  99. while (bRet = GetMessage(&msg, 0, 0, 0)) {
  100. if (bRet == -1) {
  101. // FIXME: Handle the error and possibly exit.
  102. } else {
  103. TranslateMessage(&msg);
  104. DispatchMessage(&msg);
  105. }
  106. }
  107. webView.clear();
  108. DestroyWindow(hMainWindow);
  109. WebView::cleanup();
  110. CoUninitialize();
  111. return msg.wParam;
  112. }