Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <Windows.h>
- #include <ShObjIdl.h>
- #include <atlbase.h>
- #include <string>
- LPCWSTR g_szClassName = L"myWindowClass";
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch(msg)
- {
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- HRESULT LaunchApp(const std::wstring strAppUserModelId, PDWORD pdwProcessId)
- {
- IApplicationActivationManager *spAppActivationManager;
- HRESULT hrResult = E_INVALIDARG;
- if (!strAppUserModelId.empty())
- {
- // Instantiate IApplicationActivationManager
- hrResult = CoCreateInstance(CLSID_ApplicationActivationManager,
- NULL,
- CLSCTX_LOCAL_SERVER,
- IID_IApplicationActivationManager,
- (LPVOID*)&spAppActivationManager);
- if (SUCCEEDED(hrResult))
- {
- // This call ensures that the app is launched as the foreground window
- hrResult = CoAllowSetForegroundWindow(spAppActivationManager, NULL);
- // Launch the app
- if (SUCCEEDED(hrResult))
- {
- hrResult = spAppActivationManager->ActivateApplication(strAppUserModelId.c_str(),
- NULL,
- AO_DESIGNMODE,
- pdwProcessId);
- }
- }
- }
- return hrResult;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- WNDCLASSEX wc;
- HWND hwnd;
- MSG Msg;
- // Window Class
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_GLOBALCLASS;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = g_szClassName;
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- if(!RegisterClassEx(&wc))
- {
- MessageBox(NULL, L"Window Class Registration Failed!", L"Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- //Create the Window
- hwnd = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- g_szClassName,
- L"Modern",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 1366, 768,
- NULL, NULL, hInstance, NULL);
- if(hwnd == NULL)
- {
- MessageBox(NULL, L"Window Creation Failed!", L"Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- //initialize the designmodesettings
- IApplicationDesignModeSettings *pDesignModeSettings;
- //CoInitializeEx(NULL,COINIT_MULTITHREADED);
- // CoCreate the design mode settings object
- HRESULT hr = CoCreateInstance(CLSID_ApplicationDesignModeSettings, nullptr, CLSCTX_INPROC, IID_PPV_ARGS(&pDesignModeSettings));
- if (SUCCEEDED(hr))
- {
- IInitializeWithWindow *pInitializeWithWindow;
- //hr = pDesignModeSettings->QueryInterface(IID_PPV_ARGS(&pInitializeWithWindow));
- hr = pDesignModeSettings->QueryInterface(&pInitializeWithWindow); // Retreive the implementation for IInitializeWithWindow
- if (SUCCEEDED(hr))
- {
- // Before we spoof any state, we must first initialize the design
- // mode settings object with a proxy core window. Since apps
- // running in design mode don't have an actual core window, we must
- // supply an HWND that can be used as a proxy.
- hr = pInitializeWithWindow->Initialize(hwnd); //E_ACCESSDENIED. Dunno why.
- pInitializeWithWindow->Release();
- }
- BOOL fSupported=false;
- SIZE sizeNativeDisplay = {1366, 768};
- if (SUCCEEDED(hr))
- {
- // Verify that our desired spoofed settings are supported.
- //SCALE_FACTOR scaleFactor = SCALE_100_PERCENT;
- APPLICATION_VIEW_STATE viewState = AVS_FULLSCREEN_LANDSCAPE;
- fSupported=true;
- hr = pDesignModeSettings->IsApplicationViewStateSupported(viewState,
- sizeNativeDisplay,
- SCALE_100_PERCENT,
- &fSupported);
- }
- if (SUCCEEDED(hr) && fSupported)
- {
- // Set the spoofed native display size.
- hr = pDesignModeSettings->SetNativeDisplaySize(sizeNativeDisplay);
- if (SUCCEEDED(hr))
- {
- // Set the spoofed scale factor to 100%.
- hr = pDesignModeSettings->SetScaleFactor(SCALE_100_PERCENT);
- }
- if (SUCCEEDED(hr))
- {
- // Set the spoofed application view state to full-screen landscape.
- hr = pDesignModeSettings->SetApplicationViewState(AVS_FULLSCREEN_LANDSCAPE);
- }
- if (SUCCEEDED(hr))
- {
- // Now that all the necessary state has been spoofed, calculate
- // the size that the app should occupy.
- SIZE sizeApplication;
- hr = pDesignModeSettings->ComputeApplicationSize(&sizeApplication);
- }
- }
- pDesignModeSettings->Release();
- }
- //launch the desired app
- HRESULT hrResult = S_OK;
- if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
- {
- std::wstring tes;
- tes=L"microsoft.windowscommunicationsapps_8wekyb3d8bbwe!Microsoft.WindowsLive.Mail"; //fixed const
- DWORD dwProcessId = 0;
- hrResult = LaunchApp(tes, &dwProcessId);
- }
- //Window Message Loop
- while(GetMessage(&Msg, NULL, 0, 0) > 0)
- {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- return Msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment