//
// ___ _____ ___ ___ __ __
// / __|_ _/ _ \| _ \ \/ |
// \__ \ | || (_) | / |\/| |
// |___/ |_| \___/|_|_\_| |_|
//
// Storm.TextEditor.dll
// ��������������������
// Storm.TabControl.dll was created under the LGPL
// license. Some of the code was created from scratch,
// some was not. Code not created from scratch was
// based on the DotNetFireball framework and evolved
// from that.
//
// What I mostly did in this library was that I
// cleaned up the code, structured it, documentated
// it and added new features.
//
// Although it might not sound like it, it was very
// hard and took a long (pretty much a shitload)
// time. Why? Well, this was* some of the crappiest,
// most unstructured, undocumentated, ugly code I've
// ever seen. It would actually have taken me less
// time to create it from scratch, but I figured that
// out too late. Figuring out what the code actually
// did and then documentating it was (mostly) a
// day-long process. Well, I hope you enjoy some of
// my hard work. /rant
//
// Of course some/most of it is made from scratch by me.
// *Yes, was. It isn't now. :) Some of the naming
// conventions might still seem a little bit off though.
//
// What is Storm?
// ��������������
// Storm is a set of dynamic link libraries used in
// Theodor "Vestras" Storm Kristensen's application
// "Moonlite".
//
//
// Thanks:
// �������
// - The DotNetFireball team for creating and publishing
// DotNetFireball which I based some of my code on.
//
//
// Copyright (c) Theodor "Vestras" Storm Kristensen 2009
// �����������������������������������������������������
//
namespace Storm.TextEditor.Win32
{
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Storm.TextEditor;
using Storm.TextEditor.Controls;
using Storm.TextEditor.Controls.Core;
using Storm.TextEditor.Controls.Core.Globalization;
using Storm.TextEditor.Controls.Core.Timers;
using Storm.TextEditor.Controls.IntelliMouse;
using Storm.TextEditor.Document;
using Storm.TextEditor.Document.Exporters;
using Storm.TextEditor.Forms;
using Storm.TextEditor.Interacting;
using Storm.TextEditor.Painting;
using Storm.TextEditor.Parsing;
using Storm.TextEditor.Parsing.Base;
using Storm.TextEditor.Parsing.Classes;
using Storm.TextEditor.Parsing.Language;
using Storm.TextEditor.Preset;
using Storm.TextEditor.Preset.Painting;
using Storm.TextEditor.Preset.TextDraw;
using Storm.TextEditor.Printing;
using Storm.TextEditor.Utilities;
using Storm.TextEditor.Win32;
public static class NativeUser32Api
{
#region Members
public const int GWL_STYLE = -16;
public const int WS_CHILD = 0x40000000;
#endregion
#region Natives (DllImport)
[DllImport("user32.dll")]
public static extern Int32 SendMessage(IntPtr pWnd, UInt32 uMsg,
UInt32 wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool AnimateWindow(IntPtr hWnd, uint dwTime, uint dwFlags);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool ClientToScreen(IntPtr hWnd, ref POINTAPI pt);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool DispatchMessage(ref MSG msg);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool DrawFocusRect(IntPtr hWnd, ref RECTAPI rect);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetFocus();
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern ushort GetKeyState(int virtKey);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool GetMessage(ref MSG msg, int hWnd,
uint wFilterMin, uint wFilterMax);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool GetWindowRect(IntPtr hWnd, ref RECTAPI rect);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool HideCaret(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool InvalidateRect(IntPtr hWnd,
ref RECTAPI rect, bool erase);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr LoadCursor(IntPtr hInstance, uint cursor);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool MoveWindow(IntPtr hWnd, int x, int y,
int width, int height, bool repaint);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool PeekMessage(ref MSG msg, int hWnd, uint wFilterMin,
uint wFilterMax, uint wFlag);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool PostMessage(IntPtr hWnd, int Msg,
uint wParam, uint lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool ReleaseCapture();
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool ScreenToClient(IntPtr hWnd, ref POINTAPI pt);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern uint SendMessage(IntPtr hWnd, int Msg,
uint wParam, uint lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SetCursor(IntPtr hCursor);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SetFocus(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int newLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndAfter,
int X, int Y, int Width,
int Height, uint flags);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool ShowCaret(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int ShowWindow(IntPtr hWnd, short cmdShow);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam,
ref int bRetValue, uint fWinINI);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool TrackMouseEvent(ref TRACKMOUSEEVENTS tme);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool TranslateMessage(ref MSG msg);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst,
ref POINTAPI pptDst,
ref SIZE psize, IntPtr hdcSrc,
ref POINTAPI pprSrc, int crKey,
ref BLENDFUNCTION pblend,
int dwFlags);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool UpdateWindow(IntPtr hwnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool WaitMessage();
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int msg,
int wParam, COMPOSITIONFORM lParam);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int msg,
int wParam, LogFont lParam);
[DllImport("user32.dll", SetLastError = false, CharSet =
CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int DrawText(IntPtr hDC, string lpString,
int nCount, ref RECTAPI Rect, int wFormat);
[DllImport("user32.dll")]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWND, int message,
int WParam, int LParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention =
CallingConvention.StdCall)]
public static extern IntPtr GetWindowDC(IntPtr hWND);
[DllImport("user32.dll")]
public static extern IntPtr WindowFromDC(int hdc);
[DllImport("user32.dll", SetLastError = false, CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern int TabbedTextOut(IntPtr hDC, int x, int y,
string lpString, int nCount,
int nTabPositions,
ref int lpnTabStopPositions,
int nTabOrigin);
[DllImport("user32.dll", SetLastError = false, CharSet =
CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int FillRect(IntPtr hDC, ref RECTAPI rect, IntPtr hBrush);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
public static extern uint GetTabbedTextExtent(IntPtr hDC, string lpString,
int nCount, int nTabPositions,
ref int lpnTabStopPositions);
[DllImport("user32.dll", SetLastError = false, CharSet =
CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int InvertRect(IntPtr hDC, ref RECTAPI rect);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention =
CallingConvention.StdCall)]
public static extern UInt16 GetAsyncKeyState(int vKey);
[DllImport("user32.dll")]
public static extern IntPtr CreateWindowEx(
uint dwExStyle,
string lpClassName,
string lpWindowName,
uint dwStyle,
int x,
int y,
int nWidth,
int nHeight,
IntPtr hWndParent,
IntPtr hMenu,
IntPtr hInstance,
IntPtr lpParam);
#endregion
#region Non-native
public static bool IsKeyPressed(Keys k)
{
int s = (int)GetAsyncKeyState((int)k);
s = (s & 0x8000) >> 15;
return (s == 1);
}
public static IntPtr ControlDC(Control control)
{ return GetDC(control.Handle); }
public static int ColorToInt(Color color)
{ return (color.B << 16 | color.G << 8 | color.R); }
public static Color IntToColor(int color)
{
int b = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int r = (color) & 0xFF;
return Color.FromArgb(r, g, b);
}
#endregion
}
}