Changes to use old Winforms message box popups rather than WPF to simplify code

This commit is contained in:
S T Chan 2014-01-11 12:10:12 -05:00
parent ebfbee526e
commit 5f75ec07da
10 changed files with 60 additions and 160 deletions

BIN
Common/AdobeIcon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

View File

@ -7,7 +7,7 @@
WindowStyle="None" WindowStyle="None"
Background="Transparent" Background="Transparent"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
Topmost="True" ShowInTaskbar="True"> Topmost="True" ShowInTaskbar="False" IsTabStop="False">
<Grid> <Grid>
<Image Name="QuillPenBackground" Source="Adobe_CreatePDF_icon.PNG" HorizontalAlignment="Center" VerticalAlignment="Top" Height="200" Width="200" ></Image> <Image Name="QuillPenBackground" Source="Adobe_CreatePDF_icon.PNG" HorizontalAlignment="Center" VerticalAlignment="Top" Height="200" Width="200" ></Image>
<Label Height="29" HorizontalAlignment="Left" Margin="12,203,0,0" Name="labelProgress" VerticalAlignment="Top" Width="254" Foreground="Red" FontFamily="Arial Rounded MT" FontSize="16" HorizontalContentAlignment="Center" FontWeight="Bold" VerticalContentAlignment="Top" Content="CAPTURING" /> <Label Height="29" HorizontalAlignment="Left" Margin="12,203,0,0" Name="labelProgress" VerticalAlignment="Top" Width="254" Foreground="Red" FontFamily="Arial Rounded MT" FontSize="16" HorizontalContentAlignment="Center" FontWeight="Bold" VerticalContentAlignment="Top" Content="CAPTURING" />

View File

@ -74,12 +74,14 @@
<PropertyGroup> <PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest> <ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\AdobeIcon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.WindowsAPICodePack">
<HintPath>..\Lib\Microsoft.WindowsAPICodePack.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@ -88,18 +90,11 @@
<Reference Include="System.Xaml"> <Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework> <RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\Common\PdfScribeSharedAssemblyInfo.cs"> <Compile Include="..\Common\PdfScribeSharedAssemblyInfo.cs">
<Link>PdfScribeSharedAssemblyInfo.cs</Link> <Link>PdfScribeSharedAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="ActivityNotification.xaml.cs">
<DependentUpon>ActivityNotification.xaml</DependentUpon>
</Compile>
<Compile Include="ActivityNotificationPresenter.cs" />
<Compile Include="GhostScript64.cs" /> <Compile Include="GhostScript64.cs" />
<Compile Include="NativeMethods.cs" /> <Compile Include="NativeMethods.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
@ -129,26 +124,12 @@
<AppDesigner Include="Properties\" /> <AppDesigner Include="Properties\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Resource Include="..\Common\Adobe_CreatePDF_icon.png"> <None Include="Resources\AdobeIcon.ico" />
<Link>Adobe_CreatePDF_icon.png</Link>
</Resource>
<Content Include="..\Lib\gsdll64.dll"> <Content Include="..\Lib\gsdll64.dll">
<Link>gsdll64.dll</Link> <Link>gsdll64.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Page Include="ActivityNotification.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PdfScribeCore\PdfScribeCore.csproj">
<Project>{1EAD8E9A-A123-4C37-B31E-AEE1354DF003}</Project>
<Name>PdfScribeCore</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)PdfScribeInstall\PrimaryOutputHarvest\$(TargetFileName)" <PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)PdfScribeInstall\PrimaryOutputHarvest\$(TargetFileName)"

View File

@ -1,15 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
using System.IO; using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Windows.Forms;
using System.Windows;
using System.Windows.Threading;
using PdfScribeCore;
namespace PdfScribe namespace PdfScribe
{ {
@ -23,7 +20,7 @@ namespace PdfScribe
const string errorDialogInstructionPDFGeneration = "There was a PDF generation error."; const string errorDialogInstructionPDFGeneration = "There was a PDF generation error.";
const string errorDialogInstructionCouldNotWrite = "Could not create the output file."; const string errorDialogInstructionCouldNotWrite = "Could not create the output file.";
const string errorDialogInstructionUnexpectedError = "There was an unhandled error in PDF Scribe. Enable tracing for details."; const string errorDialogInstructionUnexpectedError = "There was an internal error. Enable tracing for details.";
const string errorDialogTextFileInUse = "{0} is being used by another process."; const string errorDialogTextFileInUse = "{0} is being used by another process.";
const string errorDialogTextGhostScriptConversion = "Ghostscript error code {0}."; const string errorDialogTextGhostScriptConversion = "Ghostscript error code {0}.";
@ -39,22 +36,15 @@ namespace PdfScribe
#endregion #endregion
static Application guiApplication = null;
static Dispatcher guiDispatcher = null;
static ActivityNotificationPresenter activityNotification = null;
static TraceSource logEventSource = new TraceSource(traceSourceName); static TraceSource logEventSource = new TraceSource(traceSourceName);
[STAThread] [STAThread]
static void Main(string[] args) static void Main(string[] args)
{ {
// Install the global exception handler // Install the global exception handler
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Application_UnhandledException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Application_UnhandledException);
//Dispatcher.Run();
LaunchApplication();
//LaunchActivityNotification();
//Thread.Sleep(10000);
String standardInputFilename = Path.GetTempFileName(); String standardInputFilename = Path.GetTempFileName();
String outputFilename = Path.Combine(Path.GetTempPath(), defaultOutputFilename); String outputFilename = Path.Combine(Path.GetTempPath(), defaultOutputFilename);
@ -87,19 +77,10 @@ namespace PdfScribe
errorDialogInstructionCouldNotWrite + errorDialogInstructionCouldNotWrite +
Environment.NewLine + Environment.NewLine +
"Exception message: " + ioEx.Message); "Exception message: " + ioEx.Message);
/*ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption, DisplayErrorMessage(errorDialogCaption,
errorDialogInstructionCouldNotWrite, errorDialogInstructionCouldNotWrite + Environment.NewLine +
String.Format("{0} is in use.", outputFilename));*/
DispatchToGUIApp(
(Action)delegate()
{
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption,
errorDialogInstructionCouldNotWrite,
String.Format("{0} is in use.", outputFilename)); String.Format("{0} is in use.", outputFilename));
} }
);
}
catch (UnauthorizedAccessException unauthorizedEx) catch (UnauthorizedAccessException unauthorizedEx)
{ {
// Couldn't delete a file // Couldn't delete a file
@ -111,9 +92,11 @@ namespace PdfScribe
errorDialogInstructionCouldNotWrite + errorDialogInstructionCouldNotWrite +
Environment.NewLine + Environment.NewLine +
"Exception message: " + unauthorizedEx.Message); "Exception message: " + unauthorizedEx.Message);
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption, DisplayErrorMessage(errorDialogCaption,
errorDialogInstructionCouldNotWrite, errorDialogInstructionCouldNotWrite + Environment.NewLine +
String.Format("Insufficient privileges to either create or delete {0}", outputFilename)); String.Format("Insufficient privileges to either create or delete {0}", outputFilename));
} }
catch (ExternalException ghostscriptEx) catch (ExternalException ghostscriptEx)
{ {
@ -123,8 +106,8 @@ namespace PdfScribe
String.Format(errorDialogTextGhostScriptConversion, ghostscriptEx.ErrorCode.ToString()) + String.Format(errorDialogTextGhostScriptConversion, ghostscriptEx.ErrorCode.ToString()) +
Environment.NewLine + Environment.NewLine +
"Exception message: " + ghostscriptEx.Message); "Exception message: " + ghostscriptEx.Message);
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption, DisplayErrorMessage(errorDialogCaption,
errorDialogInstructionPDFGeneration, errorDialogInstructionPDFGeneration + Environment.NewLine +
String.Format(errorDialogTextGhostScriptConversion, ghostscriptEx.ErrorCode.ToString())); String.Format(errorDialogTextGhostScriptConversion, ghostscriptEx.ErrorCode.ToString()));
} }
@ -140,13 +123,10 @@ namespace PdfScribe
(int)TraceEventType.Warning, (int)TraceEventType.Warning,
String.Format(warnFileNotDeleted, standardInputFilename)); String.Format(warnFileNotDeleted, standardInputFilename));
} }
//ShutdownApplication();
} }
} }
/// <summary> /// <summary>
/// http://stackoverflow.com/questions/8047610/re-open-wpf-window-from-a-console-application
///
/// All unhandled exceptions will bubble their way up here - /// All unhandled exceptions will bubble their way up here -
/// a final error dialog will be displayed before the crash and burn /// a final error dialog will be displayed before the crash and burn
/// </summary> /// </summary>
@ -158,93 +138,26 @@ namespace PdfScribe
(int)TraceEventType.Critical, (int)TraceEventType.Critical,
((Exception)e.ExceptionObject).Message + Environment.NewLine + ((Exception)e.ExceptionObject).Message + Environment.NewLine +
((Exception)e.ExceptionObject).StackTrace); ((Exception)e.ExceptionObject).StackTrace);
ErrorDialogPresenter errorDialog = new ErrorDialogPresenter(errorDialogCaption, DisplayErrorMessage(errorDialogCaption,
errorDialogInstructionUnexpectedError, errorDialogInstructionUnexpectedError);
String.Empty);
} }
static void LaunchActivityNotification() /// <summary>
{ /// Pops up a topmost, OK-only message box for the error message
if (guiApplication != null) /// </summary>
{ /// <param name="boxCaption">The message box's caption</param>
DispatchToGUIApp((Action)delegate() /// <param name="boxMessage"></param>
{ static void DisplayErrorMessage(String boxCaption,
ActivityNotificationPresenter notificationPresenter = new ActivityNotificationPresenter(); String boxMessage)
notificationPresenter.ShowActivityNotificationWindow();
System.Windows.Threading.Dispatcher.Run();
}
);
}
}
static void LaunchApplication()
{ {
if (guiApplication == null) MessageBox.Show(boxMessage,
{ boxCaption,
var guiApplicationThread = new Thread(new ThreadStart(() => MessageBoxButtons.OK,
{ MessageBoxIcon.Error,
guiApplication = new Application(); MessageBoxDefaultButton.Button1,
guiApplication.ShutdownMode = ShutdownMode.OnExplicitShutdown; MessageBoxOptions.DefaultDesktopOnly);
activityNotification = new ActivityNotificationPresenter();
activityNotification.ShowActivityNotificationWindow();
guiApplication.Run();
}
));
guiApplicationThread.SetApartmentState(ApartmentState.STA);
guiApplicationThread.IsBackground = true;
guiApplicationThread.Start();
}
}
static void DispatchToGUIApp(Action guiAction)
{
if (guiApplication != null)
{
if (guiApplication.Dispatcher.Thread != System.Windows.Threading.Dispatcher.CurrentDispatcher.Thread)
{
guiApplication.Dispatcher.Invoke(guiAction);
}
else
{
guiAction.Invoke();
}
}
}
static void ShutdownApplication()
{
if (guiApplication != null)
{
if (guiApplication.Windows != null && guiApplication.Windows.Count > 0)
{
foreach (Window appWindow in guiApplication.Windows)
{
appWindow.Close();
}
}
guiApplication.Shutdown();
guiApplication = null;
/*
guiApplication.Dispatcher.Invoke((Action)delegate()
{
if (guiApplication.Windows != null && guiApplication.Windows.Count > 0)
{
foreach (Window appWindow in guiApplication.Windows)
{
appWindow.Close();
}
}
guiApplication.Shutdown();
//guiApplication.Dispatcher.InvokeShutdown();
} }
);
*/
//guiApplication.Dispatcher.BeginInvokeShutdown(System.Windows.Threading.DispatcherPriority.Send);
//guiApplication.Shutdown();
//guiApplication = null;
}
}
} }
} }

View File

@ -25,14 +25,6 @@ using System.Windows;
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:

View File

@ -59,5 +59,12 @@ namespace PdfScribe.Properties {
resourceCulture = value; resourceCulture = value;
} }
} }
internal static System.Drawing.Icon AdobeIcon {
get {
object obj = ResourceManager.GetObject("AdobeIcon", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
} }
} }

View File

@ -46,7 +46,7 @@
mimetype: application/x-microsoft.net.object.binary.base64 mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64 mimetype: application/x-microsoft.net.object.soap.base64
@ -60,6 +60,7 @@
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
--> -->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType> <xsd:complexType>
<xsd:choice maxOccurs="unbounded"> <xsd:choice maxOccurs="unbounded">
@ -68,9 +69,10 @@
<xsd:sequence> <xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" /> <xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence> </xsd:sequence>
<xsd:attribute name="name" type="xsd:string" /> <xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" /> <xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" /> <xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
<xsd:element name="assembly"> <xsd:element name="assembly">
@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence> </xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" /> <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
<xsd:element name="resheader"> <xsd:element name="resheader">
@ -109,9 +112,13 @@
<value>2.0</value> <value>2.0</value>
</resheader> </resheader>
<resheader name="reader"> <resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="AdobeIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\AdobeIcon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root> </root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

View File

@ -53,7 +53,6 @@ namespace PdfScribeCore
simpleTaskDialog.Opened += new EventHandler(simpleTaskDialog_Opened); simpleTaskDialog.Opened += new EventHandler(simpleTaskDialog_Opened);
simpleTaskDialog.StartupLocation = APICodePack.TaskDialogStartupLocation.CenterScreen; simpleTaskDialog.StartupLocation = APICodePack.TaskDialogStartupLocation.CenterScreen;
simpleTaskDialog.Show(); simpleTaskDialog.Show();
//System.Windows.Threading.Dispatcher.Run();
} }
} }

View File

@ -64,12 +64,13 @@
<File Id="PdfScribeExe" Source="PrimaryOutputHarvest\PdfScribe.exe" KeyPath="yes" > <File Id="PdfScribeExe" Source="PrimaryOutputHarvest\PdfScribe.exe" KeyPath="yes" >
<netfx:NativeImage Id="PdfScribe.exe" Platform="64bit" Priority="1" /> <netfx:NativeImage Id="PdfScribe.exe" Platform="64bit" Priority="1" />
</File> </File>
<File Source="PrimaryOutputHarvest\PdfScribeCore.pdb" /> <File Source="PrimaryOutputHarvest\PdfScribe.pdb" />
<File Source="PrimaryOutputHarvest\PdfScribe.exe.config" /> <File Source="PrimaryOutputHarvest\PdfScribe.exe.config" />
<File Id="PdfScribeCoreDll" Source="PrimaryOutputHarvest\PdfScribeCore.dll" > <File Id="PdfScribeCoreDll" Source="PrimaryOutputHarvest\PdfScribeCore.dll" >
<netfx:NativeImage Id="PdfScribeCore.dll" Platform="64bit" Priority="1" /> <netfx:NativeImage Id="PdfScribeCore.dll" Platform="64bit" Priority="1" />
</File> </File>
<File Source="PrimaryOutputHarvest\PdfScribeCore.pdb" />
<!-- Third party components --> <!-- Third party components -->
<File Source="..\Lib\gsdll64.dll" /> <File Source="..\Lib\gsdll64.dll" />