Launch app if checkbox is checked or display launch window if not checked

This commit is contained in:
Jyothi Venugopal 2019-03-07 11:26:45 -08:00
Родитель da973b14ab
Коммит 8858dcf877
7 изменённых файлов: 142 добавлений и 9 удалений

Просмотреть файл

@ -0,0 +1,31 @@
#include <windows.h>
#include <shlobj_core.h>
#include <CommCtrl.h>
#include "FilePaths.hpp"
#include "InstallComplete.hpp"
#include "GeneralUtil.hpp"
#include <TraceLoggingProvider.h>
#include "InstallUI.hpp"
const PCWSTR InstallComplete::HandlerName = L"InstallComplete";
HRESULT InstallComplete::ExecuteForAddRequest()
{
SendInstallCompleteMsg();
return S_OK;
}
HRESULT InstallComplete::CreateHandler(MsixRequest * msixRequest, IPackageHandler ** instance)
{
std::unique_ptr<InstallComplete> localInstance(new InstallComplete(msixRequest));
if (localInstance == nullptr)
{
return E_OUTOFMEMORY;
}
*instance = localInstance.release();
return S_OK;
}

Просмотреть файл

@ -0,0 +1,19 @@
#pragma once
#include "GeneralUtil.hpp"
#include "IPackageHandler.hpp"
class InstallComplete : IPackageHandler
{
public:
HRESULT ExecuteForAddRequest();
static const PCWSTR HandlerName;
static HRESULT CreateHandler(_In_ MsixRequest* msixRequest, _Out_ IPackageHandler** instance);
~InstallComplete() {}
private:
MsixRequest * m_msixRequest = nullptr;
InstallComplete() {}
InstallComplete(_In_ MsixRequest* msixRequest) : m_msixRequest(msixRequest) {}
};

Просмотреть файл

@ -12,6 +12,8 @@
#include <iostream>
#include "resource.h"
// MSIXWindows.hpp define NOMINMAX because we want to use std::min/std::max from <algorithm>
// GdiPlus.h requires a definiton for min and max. Use std namespace *BEFORE* including it.
using namespace std;
@ -186,6 +188,23 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
}
break;
case WM_INSTALLCOMPLETE_MSG:
DestroyWindow(g_CancelbuttonHWnd);
CreateLaunchButton(hWnd, windowRect);
UpdateWindow(hWnd);
ShowWindow(g_progressHWnd, SW_HIDE); //hide progress bar
ShowWindow(g_checkboxHWnd, SW_HIDE); //hide launch check box
if (g_launchCheckBoxState) {
ui->LaunchInstalledApp(); // launch app
DestroyWindow(hWnd); // close msix app installer
}
else
{
//wait for user to click launch button or close the window
DWORD waitLaunchButtonResult = WaitForSingleObject(ui->getLaunchButtonEvent(), INFINITE);
}
MessageBox(NULL, L"Launch App window", L"Launch App window", 0);
break;
case WM_SIZE:
case WM_SIZING:
break;
@ -201,6 +220,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0;
}
HRESULT UI::LaunchInstalledApp()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
PackageInfo* packageInfo = m_msixRequest->GetPackageInfo();
std::wstring resolvedExecutableFullPath = m_msixRequest->GetFilePathMappings()->GetExecutablePath(packageInfo->GetExecutableFilePath(), packageInfo->GetPackageFullName().c_str());
ShellExecute(NULL, NULL, resolvedExecutableFullPath.c_str(), NULL, NULL, SW_SHOW);
}
void StartParseFile(HWND hWnd)
{
//auto result = ParseAndRun(hWnd);
@ -258,6 +286,7 @@ void StartUIThread(UI* ui)
MessageBox(NULL, L"Call to RegisterClassEx failed!", title.c_str(), NULL);
return;
}
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
@ -424,6 +453,24 @@ BOOL CreateCancelButton(HWND parentHWnd, RECT parentRect) {
return TRUE;
}
BOOL CreateLaunchButton(HWND parentHWnd, RECT parentRect) {
LPVOID buttonPointer = nullptr;
g_LaunchbuttonHWnd = CreateWindowEx(
WS_EX_LEFT, // extended window style
L"BUTTON",
L"Launch", // text
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_FLAT, // style
parentRect.right - 100 - 50, // x coord
parentRect.bottom - 60, // y coord
120, // width
35, // height
parentHWnd, // parent
(HMENU)IDC_LAUNCHBUTTON, // menu
reinterpret_cast<HINSTANCE>(GetWindowLongPtr(parentHWnd, GWLP_HINSTANCE)),
buttonPointer); // pointer to button
return TRUE;
}
// FUNCTION: ChangeButtonText(LPARAM newMessage)
//
// PURPOSE: Changes the text of the lower right button
@ -488,7 +535,7 @@ BOOL ChangeText(HWND parentHWnd, std::wstring displayName, std::wstring messageT
// windowTitle: the window title
int UI::CreateInitWindow(HINSTANCE hInstance, int nCmdShow, const std::wstring& windowClass, const std::wstring& title)
{
HWND hWnd = CreateWindow(
hWnd = CreateWindow(
const_cast<wchar_t*>(windowClass.c_str()),
const_cast<wchar_t*>(title.c_str()),
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU,
@ -507,6 +554,8 @@ int UI::CreateInitWindow(HINSTANCE hInstance, int nCmdShow, const std::wstring&
return 1;
}
RegisterWindowMessage(L"InstallComplete");
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)this);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
@ -529,3 +578,8 @@ void UpdateProgressBar()
{
SendMessage(g_progressHWnd, PBM_STEPIT, 0, 0);
}
void SendInstallCompleteMsg()
{
SendMessage(hWnd, WM_INSTALLCOMPLETE_MSG, NULL, NULL);
}

Просмотреть файл

@ -10,12 +10,16 @@
#define IDC_LAUNCHCHECKBOX 1
#define IDC_INSTALLBUTTON 2
#define IDC_CANCELBUTTON 3
#define IDC_LAUNCHBUTTON 4
#define WM_INSTALLCOMPLETE_MSG (WM_APP+1)
// Global variables
static HWND hWnd = NULL; // parent window hwnd
static HWND g_buttonHWnd = NULL;
static HWND g_checkboxHWnd = NULL;
static HWND g_progressHWnd = NULL;
static HWND g_CancelbuttonHWnd = NULL;
static HWND g_LaunchbuttonHWnd = NULL;
static bool g_installed = false;
static bool g_displayInfo = false;
static bool g_displayCompleteText = false;
@ -25,6 +29,7 @@ class UI
{
public:
HRESULT ShowUI();
HRESULT LaunchInstalledApp();
static HRESULT Make(_In_ MsixRequest* msixRequest, _Out_ UI** instance);
~UI() {}
@ -32,15 +37,25 @@ private:
MsixRequest* m_msixRequest = nullptr;
HANDLE m_buttonClickedEvent;
HANDLE m_launchAppEvent;
UI() {}
UI(_In_ MsixRequest* msixRequest) : m_msixRequest(msixRequest) { m_buttonClickedEvent = CreateEvent(NULL, FALSE, FALSE, NULL); }
UI(_In_ MsixRequest* msixRequest) : m_msixRequest(msixRequest)
{
m_buttonClickedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
m_launchAppEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
}
public:
HRESULT DisplayPackageInfo(HWND hWnd, RECT windowRect, std::wstring& displayText, std::wstring& messageText);
int CreateInitWindow(HINSTANCE hInstance, int nCmdShow, const std::wstring& windowClass, const std::wstring& title);
void SetButtonClicked() { SetEvent(m_buttonClickedEvent); }
void SetLaunchButtonClicked() { SetEvent(m_launchAppEvent); }
HANDLE getLaunchButtonEvent()
{
return m_launchAppEvent;
}
};
class CreateAndShowUI : IPackageHandler
@ -93,6 +108,8 @@ BOOL CreateCheckbox(HWND parentHWnd, RECT parentRect);
// parentRect: the specs of the parent window
BOOL CreateCancelButton(HWND parentHWnd, RECT parentRect);
BOOL CreateLaunchButton(HWND parentHWnd, RECT parentRect);
// FUNCTION: ChangeButtonText(LPARAM newMessage)
//
// PURPOSE: Changes the text of the lower right button
@ -118,3 +135,5 @@ BOOL ChangeText(HWND parentHWnd, std::wstring displayText, std::wstring message
//
// PURPOSE: Increment the progress bar one tick based on preset tick
void UpdateProgressBar();
void SendInstallCompleteMsg();

Просмотреть файл

@ -25,6 +25,7 @@
#include "PopulatePackageInfo.hpp"
#include "Protocol.hpp"
#include "FileTypeAssociation.hpp"
#include "InstallComplete.hpp"
// MSIXWindows.hpp define NOMINMAX because we want to use std::min/std::max from <algorithm>
@ -47,7 +48,8 @@ std::map<PCWSTR, HandlerInfo> AddHandlers =
{StartMenuLink::HandlerName, {StartMenuLink::CreateHandler, AddRemovePrograms::HandlerName}},
{AddRemovePrograms::HandlerName, {AddRemovePrograms::CreateHandler, Protocol::HandlerName}},
{Protocol::HandlerName, {Protocol::CreateHandler, FileTypeAssociation::HandlerName}},
{FileTypeAssociation::HandlerName, {FileTypeAssociation::CreateHandler, nullptr}},
{FileTypeAssociation::HandlerName, {FileTypeAssociation::CreateHandler, InstallComplete::HandlerName }},
{InstallComplete::HandlerName, {InstallComplete::CreateHandler, nullptr}},
};
std::map<PCWSTR, HandlerInfo> RemoveHandlers =

Просмотреть файл

@ -191,6 +191,7 @@
<ClInclude Include="GeneralUtil.hpp" />
<ClInclude Include="FilePaths.hpp" />
<ClInclude Include="CommandLineInterface.hpp" />
<ClInclude Include="InstallComplete.hpp" />
<ClInclude Include="PopulatePackageInfo.hpp" />
<ClInclude Include="PackageInfo.hpp" />
<ClInclude Include="IPackageHandler.hpp" />
@ -209,6 +210,7 @@
<ClCompile Include="FilePaths.cpp" />
<ClCompile Include="FileTypeAssociation.cpp" />
<ClCompile Include="GeneralUtil.cpp" />
<ClCompile Include="InstallComplete.cpp" />
<ClCompile Include="InstallUI.cpp" />
<ClCompile Include="PackageInfo.cpp" />
<ClCompile Include="Protocol.cpp" />

Просмотреть файл

@ -15,12 +15,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="MSIXPackaging\AppxPackaging.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MSIXPackaging\MSIXWindows.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CommandLineInterface.hpp">
<Filter>Header Files</Filter>
</ClInclude>
@ -75,6 +69,15 @@
<ClInclude Include="Constants.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\.vs\src\msix\AppxPackaging.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\.vs\src\msix\MSIXWindows.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="InstallComplete.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Win7MSIXInstaller.cpp">
@ -122,6 +125,9 @@
<ClCompile Include="PackageInfo.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="InstallComplete.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Win7MSIXInstaller.rc">