MCPcopy Create free account
hub / github.com/MicrosoftEdge/WebView2Samples / AppWindow

Method AppWindow

SampleApps/WebView2APISample/AppWindow.cpp:201–298  ·  view source on GitHub ↗

Creates a new window which is a copy of the entire app, but on the same thread.

Source from the content-addressed store, hash-verified

199
200// Creates a new window which is a copy of the entire app, but on the same thread.
201AppWindow::AppWindow(
202 UINT creationModeId, const WebViewCreateOption& opt, const std::wstring& initialUri,
203 const std::wstring& userDataFolderParam, bool isMainWindow,
204 std::function<void()> webviewCreatedCallback, bool customWindowRect, RECT windowRect,
205 bool shouldHaveToolbar, bool isPopup)
206 : m_creationModeId(creationModeId), m_webviewOption(opt), m_initialUri(initialUri),
207 m_onWebViewFirstInitialized(webviewCreatedCallback), m_isPopupWindow(isPopup)
208{
209 // Initialize COM as STA.
210 CHECK_FAILURE(OleInitialize(NULL));
211
212 ++s_appInstances;
213
214 WCHAR szTitle[s_maxLoadString]; // The title bar text
215 LoadStringW(g_hInstance, IDS_APP_TITLE, szTitle, s_maxLoadString);
216 m_appTitle = szTitle;
217 DWORD windowStyle = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
218 if (m_webviewOption.useWco)
219 {
220 windowStyle &= ~WS_OVERLAPPEDWINDOW;
221 windowStyle |= (WS_POPUP | WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX);
222 }
223
224
225 if (userDataFolderParam.length() > 0)
226 {
227 m_userDataFolder = userDataFolderParam;
228 }
229
230 if (customWindowRect)
231 {
232 m_mainWindow = CreateWindowExW(
233 WS_EX_CONTROLPARENT, GetWindowClass(), szTitle, windowStyle, windowRect.left,
234 windowRect.top, windowRect.right - windowRect.left,
235 windowRect.bottom - windowRect.top, nullptr, nullptr, g_hInstance, nullptr);
236 }
237 else
238 {
239 m_mainWindow = CreateWindowExW(
240 WS_EX_CONTROLPARENT, GetWindowClass(), szTitle, windowStyle, CW_USEDEFAULT, 0,
241 CW_USEDEFAULT, 0, nullptr, nullptr, g_hInstance, nullptr);
242 }
243
244 m_appBackgroundImageHandle = (HBITMAP)LoadImage(
245 g_hInstance, MAKEINTRESOURCE(IDI_WEBVIEW2_BACKGROUND), IMAGE_BITMAP, 0, 0,
246 LR_DEFAULTCOLOR);
247 GetObject(m_appBackgroundImageHandle, sizeof(m_appBackgroundImage), &m_appBackgroundImage);
248 m_memHdc = CreateCompatibleDC(GetDC(m_mainWindow));
249 SelectObject(m_memHdc, m_appBackgroundImageHandle);
250
251 SetWindowLongPtr(m_mainWindow, GWLP_USERDATA, (LONG_PTR)this);
252
253 //! [TextScaleChanged1]
254 if (winrt::try_get_activation_factory<winrt::Windows::UI::ViewManagement::UISettings>())
255 {
256 m_uiSettings = winrt::Windows::UI::ViewManagement::UISettings();
257 m_uiSettings.TextScaleFactorChanged({this, &AppWindow::OnTextScaleChanged});
258 }

Callers

nothing calls this directly

Calls 2

InitializeMethod · 0.45
HideMethod · 0.45

Tested by

no test coverage detected