basic structure for GreenshotCore/GreenshotEditor

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@702 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
JKlingen 2010-07-25 14:32:03 +00:00
commit b574f82685
11 changed files with 168 additions and 11 deletions

View file

@ -0,0 +1,56 @@
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{BDC408EE-DEA1-4474-B59D-7F05757B12EC}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<RootNamespace>GreenshotCore</RootNamespace>
<AssemblyName>GreenshotCore</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<SourceAnalysisOverrideSettingsFile>C:\Dokumente und Einstellungen\jens\Anwendungsdaten\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Lib" />
<Folder Include="UnmanagedHelpers" />
<Compile Include="UnmanagedHelpers\GDI32.cs" />
<Compile Include="UnmanagedHelpers\User32.cs" />
<Compile Include="UnmanagedHelpers\Win32Errors.cs" />
<Compile Include="UnmanagedHelpers\WinMM.cs" />
<None Include="Lib\log4net.dll" />
<None Include="Lib\nunit.framework.dll" />
</ItemGroup>
</Project>

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,81 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
namespace Greenshot.UnmanagedHelpers {
/// <summary>
/// GDI32 Helpers
/// </summary>
public class GDI32 {
[DllImport("gdi32.dll", SetLastError=true)]
public static extern bool BitBlt(IntPtr hObject,int nXDest,int nYDest,
int nWidth,int nHeight,IntPtr hObjectSource,
int nXSrc,int nYSrc, CopyPixelOperation dwRop);
[DllImport("gdi32.dll", SetLastError=true)]
public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
[DllImport("gdi32.dll", SetLastError=true)]
public static extern bool DeleteDC(IntPtr hDC);
[DllImport("gdi32.dll", SetLastError=true)]
public static extern bool DeleteObject(IntPtr hObject);
[DllImport("gdi32.dll", SetLastError=true)]
public static extern IntPtr SelectObject(IntPtr hDC,IntPtr hObject);
[DllImport("gdi32.dll", SetLastError=true)]
public static extern IntPtr CreateDIBSection(IntPtr hdc, ref BitmapInfoHeader bmi, uint Usage, out IntPtr bits, IntPtr hSection, uint dwOffset);
}
[StructLayout(LayoutKind.Sequential)]
public struct BitmapInfoHeader {
public uint biSize;
public int biWidth;
public int biHeight;
public short biPlanes;
public short biBitCount;
public uint biCompression;
public uint biSizeImage;
public int biXPelsPerMeter;
public int biYPelsPerMeter;
public uint biClrUsed;
public int biClrImportant;
private const int BI_RGB = 0; //Das Bitmap ist nicht komprimiert
private const int BI_RLE8 = 1; //Das Bitmap ist komprimiert (Für 8-Bit Bitmaps)
private const int BI_RLE4 = 2; //Das Bitmap ist komprimiert (Für 4-Bit Bitmaps)
private const int BI_BITFIELDS = 3; //Das Bitmap ist nicht komprimiert. Die Farbtabelle enthält
public const int DIB_RGB_COLORS = 0;
public BitmapInfoHeader(int width, int height, short bpp) {
biSize = (uint)Marshal.SizeOf(typeof(BitmapInfoHeader)); // BITMAPINFOHEADER is 40 bytes
biPlanes = 1; // Should allways be 1
biCompression = BI_RGB;
biWidth=width;
biHeight=height;
biBitCount=bpp;
biSizeImage = 0;
biXPelsPerMeter = 0;
biYPelsPerMeter = 0;
biClrUsed = 0;
biClrImportant = 0;
}
}
}

View file

@ -0,0 +1,134 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
namespace Greenshot.UnmanagedHelpers {
/// <summary>
/// User32 Wrappers
/// </summary>
public class User32 {
#region Structures and constants
public const Int32 CURSOR_SHOWING = 0x00000001;
[StructLayout(LayoutKind.Sequential)]
public struct POINT {
public Int32 x;
public Int32 y;
}
[StructLayout(LayoutKind.Sequential)]
public struct CursorInfo {
public Int32 cbSize;
public Int32 flags;
public IntPtr hCursor;
public POINT ptScreenPos;
}
[StructLayout(LayoutKind.Sequential)]
public struct IconInfo {
public bool fIcon;
public Int32 xHotspot;
public Int32 yHotspot;
public IntPtr hbmMask;
public IntPtr hbmColor;
}
#endregion
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hDC);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetForegroundWindow();
[DllImport("User32.dll", SetLastError = true)]
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("User32.dll", SetLastError = true)]
public static extern void ReleaseDC(IntPtr dc);
[DllImport("User32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetClipboardOwner();
[DllImport("user32.dll", SetLastError = true)]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool AttachConsole(uint dwProcessId);
public const uint ATTACH_PARENT_PROCESS = 0x0ffffffff; // default value if not specifing a process ID
[DllImport("kernel32")]
public static extern bool AllocConsole();
/// uiFlags: 0 - Count of GDI objects
/// uiFlags: 1 - Count of USER objects
/// - Win32 GDI objects (pens, brushes, fonts, palettes, regions, device contexts, bitmap headers)
/// - Win32 USER objects:
/// - WIN32 resources (accelerator tables, bitmap resources, dialog box templates, font resources, menu resources, raw data resources, string table entries, message table entries, cursors/icons)
/// - Other USER objects (windows, menus)
///
[DllImport("user32.dll", SetLastError = true)]
public static extern uint GetGuiResources(IntPtr hProcess, uint uiFlags);
public static uint GetGuiResourcesGDICount() {
return GetGuiResources(Process.GetCurrentProcess().Handle, 0);
}
public static uint GetGuiResourcesUserCount() {
return GetGuiResources(Process.GetCurrentProcess().Handle, 1);
}
/// <summary>
/// Helper method to create a Win32 exception with the windows message in it
/// </summary>
/// <param name="method">string with current method</param>
/// <returns>Exception</returns>
public static Exception CreateWin32Exception(string method) {
Win32Exception exceptionToThrow = new Win32Exception();
exceptionToThrow.Data.Add("Method", method);
return exceptionToThrow;
}
#region icon
[DllImport("user32.dll")]
public static extern IntPtr CopyIcon(IntPtr hIcon);
[DllImport("user32.dll")]
public static extern bool DestroyIcon(IntPtr hIcon);
[DllImport("user32.dll")]
public static extern bool GetCursorInfo(out CursorInfo cursorInfo);
[DllImport("user32.dll")]
public static extern bool GetIconInfo(IntPtr hIcon, out IconInfo iconInfo);
#endregion
}
}

View file

@ -0,0 +1,141 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
/// <summary>
/// Win32 error codes
/// </summary>
namespace Greenshot.UnmanagedHelpers {
/// <summary>
/// A Win32 error code.
/// </summary>
public enum Win32Error : uint {
Success = 0x0,
InvalidFunction = 0x1,
FileNotFound = 0x2,
PathNotFound = 0x3,
TooManyOpenFiles = 0x4,
AccessDenied = 0x5,
InvalidHandle = 0x6,
ArenaTrashed = 0x7,
NotEnoughMemory = 0x8,
InvalidBlock = 0x9,
BadEnvironment = 0xa,
BadFormat = 0xb,
InvalidAccess = 0xc,
InvalidData = 0xd,
OutOfMemory = 0xe,
InvalidDrive = 0xf,
CurrentDirectory = 0x10,
NotSameDevice = 0x11,
NoMoreFiles = 0x12,
WriteProtect = 0x13,
BadUnit = 0x14,
NotReady = 0x15,
BadCommand = 0x16,
Crc = 0x17,
BadLength = 0x18,
Seek = 0x19,
NotDosDisk = 0x1a,
SectorNotFound = 0x1b,
OutOfPaper = 0x1c,
WriteFault = 0x1d,
ReadFault = 0x1e,
GenFailure = 0x1f,
SharingViolation = 0x20,
LockViolation = 0x21,
WrongDisk = 0x22,
SharingBufferExceeded = 0x24,
HandleEof = 0x26,
HandleDiskFull = 0x27,
NotSupported = 0x32,
RemNotList = 0x33,
DupName = 0x34,
BadNetPath = 0x35,
NetworkBusy = 0x36,
DevNotExist = 0x37,
TooManyCmds = 0x38,
FileExists = 0x50,
CannotMake = 0x52,
AlreadyAssigned = 0x55,
InvalidPassword = 0x56,
InvalidParameter = 0x57,
NetWriteFault = 0x58,
NoProcSlots = 0x59,
TooManySemaphores = 0x64,
ExclSemAlreadyOwned = 0x65,
SemIsSet = 0x66,
TooManySemRequests = 0x67,
InvalidAtInterruptTime = 0x68,
SemOwnerDied = 0x69,
SemUserLimit = 0x6a
}
public static class Win32 {
[DllImport("kernel32.dll")]
static extern uint FormatMessage(uint dwFlags, IntPtr lpSource, uint dwMessageId, uint dwLanguageId, [Out] StringBuilder lpBuffer, int nSize, IntPtr Arguments);
[DllImport("kernel32.dll")]
public static extern void SetLastError(uint dwErrCode);
public static Win32Error GetLastErrorCode() {
return (Win32Error)Marshal.GetLastWin32Error();
}
public static long GetHResult(Win32Error errorCode) {
int error = (int)errorCode;
if ((error & 0x80000000) == 0x80000000) {
return (long)error;
}
return (long)(0x80070000 | (uint)(error & 0xffff));
}
public static string GetMessage(Win32Error errorCode) {
StringBuilder buffer = new StringBuilder(0x100);
if (FormatMessage(0x3200, IntPtr.Zero, (uint)errorCode, 0, buffer, buffer.Capacity, IntPtr.Zero) == 0) {
return "Unknown error (0x" + ((int)errorCode).ToString("x") + ")";
}
StringBuilder result = new StringBuilder();
int i = 0;
while (i < buffer.Length) {
if (!char.IsLetterOrDigit(buffer[i]) &&
!char.IsPunctuation(buffer[i]) &&
!char.IsSymbol(buffer[i]) &&
!char.IsWhiteSpace(buffer[i]))
break;
result.Append(buffer[i]);
i++;
}
return result.ToString().Replace("\r\n", "");
}
}
}

View file

@ -0,0 +1,35 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Runtime.InteropServices;
namespace Greenshot.UnmanagedHelpers {
/// <summary>
/// Windows Media
/// </summary>
public class WinMM {
[DllImport("winmm.dll", SetLastError = true)]
public static extern bool PlaySound(byte[] ptrToSound, System.UIntPtr hmod, uint fdwSound);
[DllImport("winmm.dll", SetLastError = true)]
public static extern bool PlaySound(IntPtr ptrToSound, System.UIntPtr hmod, uint fdwSound);
}
}