/// <summary> /// Calculates window border width from style. /// </summary> public static int BorderWidth(WS style, WS2 exStyle) { RECT r = default; Api.AdjustWindowRectEx(ref r, style, false, exStyle); return(r.right); }
private void encryptToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); DialogResult dr = ofd.ShowDialog(); if (dr == DialogResult.OK) { byte[] file = System.IO.File.ReadAllBytes(ofd.FileName); WS2 ws = new WS2(file, true); file = ws.Encrypt(file); System.IO.File.WriteAllBytes(ofd.FileName, file); MessageBox.Show("encrypted"); } }
public InactiveWindow(WS style = WS.POPUP | WS.THICKFRAME, WS2 exStyle = WS2.TOOLWINDOW | WS2.NOACTIVATE, bool shadow = false) { _style = style; _exStyle = exStyle; _shadow = shadow; this.SuspendLayout(); this.AutoScaleMode = AutoScaleMode.None; this.StartPosition = FormStartPosition.Manual; this.FormBorderStyle = FormBorderStyle.None; this.ShowInTaskbar = false; this.ResumeLayout(); _wasCtor = true; }
/// <summary> /// Calculates window rectangle from client area rectangle and style. /// Calls API <msdn>AdjustWindowRectEx</msdn>. /// </summary> /// <param name="r">Input - client area rectangle in screen. Output - window rectangle in screen.</param> /// <param name="style"></param> /// <param name="exStyle"></param> /// <param name="hasMenu"></param> /// <remarks> /// Ignores styles WS_VSCROLL, WS_HSCROLL and wrapped menu bar. /// </remarks> public static bool WindowRectFromClientRect(ref RECT r, WS style, WS2 exStyle, bool hasMenu = false) { return(Api.AdjustWindowRectEx(ref r, style, hasMenu, exStyle)); }
/// <summary> /// Creates native/unmanaged window. /// </summary> /// <exception cref="AuException">Failed to create window. Unlikely.</exception> /// <remarks> /// Calls API <msdn>CreateWindowEx</msdn>. /// Later call <see cref="DestroyWindow"/> or <see cref="Close"/>. /// </remarks> /// <seealso cref="RegisterWindowClass"/> public static AWnd CreateWindow(string className, string name = null, WS style = 0, WS2 exStyle = 0, int x = 0, int y = 0, int width = 0, int height = 0, AWnd parent = default, LPARAM controlId = default, IntPtr hInstance = default, LPARAM param = default) { var w = Api.CreateWindowEx(exStyle, className, name, style, x, y, width, height, parent, controlId, hInstance, param); if (w.Is0) { throw new AuException(0); } return(w); }
/// <summary> /// Creates native/unmanaged window of a class registered with <see cref="RegisterWindowClass"/> with null <i>wndProc</i>, and sets its window procedure. /// </summary> /// <exception cref="ArgumentException">The class is not registered with <see cref="RegisterWindowClass"/>, or registered with non-null <i>wndProc</i>.</exception> /// <exception cref="AuException">Failed to create window. Unlikely.</exception> /// <remarks> /// Calls API <msdn>CreateWindowEx</msdn>. /// Protects the <i>wndProc</i> delegate from GC. /// Later call <see cref="DestroyWindow"/> or <see cref="Close"/>. /// </remarks> public static AWnd CreateWindow(Native.WNDPROC wndProc, string className, string name = null, WS style = 0, WS2 exStyle = 0, int x = 0, int y = 0, int width = 0, int height = 0, AWnd parent = default, LPARAM controlId = default, IntPtr hInstance = default, LPARAM param = default) { var a = t_windows ??= new List <(AWnd w, Native.WNDPROC p)>(); for (int i = a.Count; --i >= 0;) { if (!a[i].w.IsAlive) { a.RemoveAt(i); } } lock (s_classes) { if (!s_classes.TryGetValue(className, out var wp) || wp != null) { throw new ArgumentException("Window class must be registered with RegisterWindowClass with null wndProc"); } } AWnd w; //need to cubclass the new window. But not after CreateWindowEx, because wndProc must receive all messages. #if CW_CBT //slightly slower and dirtier. Invented before Core, to support multiple appdomains. using (AHookWin.ThreadCbt(c => { //let CBT hook subclass before any messages if (c.code == HookData.CbtEvent.CREATEWND) { //note: unhook as soon as possible. Else possible exception etc. // If eg hook proc uses 'lock' and that 'lock' must wait, // our hook proc is called again and again while waiting, until 'lock' throws exception. // In STA thread 'lock' dispatches messages, but I don't know why hook proc is called multiple times for same event. c.hook.Unhook(); var ww = (AWnd)c.wParam; Debug.Assert(ww.ClassNameIs(className)); ww.SetWindowLong(Native.GWL.WNDPROC, Marshal.GetFunctionPointerForDelegate(wndProc)); } else { Debug.Assert(false); } return(false); })) { w = Api.CreateWindowEx(exStyle, className, name, style, x, y, width, height, parent, controlId, hInstance, param); } #else t_cwProc = wndProc; //let _DefWndProc subclass on first message try { w = Api.CreateWindowEx(exStyle, className, name, style, x, y, width, height, parent, controlId, hInstance, param); } finally { t_cwProc = null; } //if CreateWindowEx failed and _CWProc not called #endif if (w.Is0) { throw new AuException(0); } a.Add((w, wndProc)); return(w); }