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"
Background="Transparent"
WindowStartupLocation="CenterScreen"
Topmost="True" ShowInTaskbar="True">
Topmost="True" ShowInTaskbar="False" IsTabStop="False">
<Grid>
<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" />

View File

@ -74,12 +74,14 @@
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\AdobeIcon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.WindowsAPICodePack">
<HintPath>..\Lib\Microsoft.WindowsAPICodePack.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
@ -88,18 +90,11 @@
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Common\PdfScribeSharedAssemblyInfo.cs">
<Link>PdfScribeSharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ActivityNotification.xaml.cs">
<DependentUpon>ActivityNotification.xaml</DependentUpon>
</Compile>
<Compile Include="ActivityNotificationPresenter.cs" />
<Compile Include="GhostScript64.cs" />
<Compile Include="NativeMethods.cs" />
<Compile Include="Program.cs" />
@ -129,26 +124,12 @@
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Resource Include="..\Common\Adobe_CreatePDF_icon.png">
<Link>Adobe_CreatePDF_icon.png</Link>
</Resource>
<None Include="Resources\AdobeIcon.ico" />
<Content Include="..\Lib\gsdll64.dll">
<Link>gsdll64.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</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" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)PdfScribeInstall\PrimaryOutputHarvest\$(TargetFileName)"

View File

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

View File

@ -25,14 +25,6 @@ using System.Windows;
//[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:

View File

@ -59,5 +59,12 @@ namespace PdfScribe.Properties {
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
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
@ -60,6 +60,7 @@
: 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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
@ -68,9 +69,10 @@
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</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="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
@ -85,9 +87,10 @@
<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: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="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
@ -109,9 +112,13 @@
<value>2.0</value>
</resheader>
<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 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>
<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>

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.StartupLocation = APICodePack.TaskDialogStartupLocation.CenterScreen;
simpleTaskDialog.Show();
//System.Windows.Threading.Dispatcher.Run();
}
}

View File

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