Created
December 6, 2024 16:14
-
-
Save Jiiks/bcbc38c090dff2a258d519451edce8ad to your computer and use it in GitHub Desktop.
PoE2 Window manipulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
using System.Runtime.InteropServices; | |
namespace PoE2WindowManip; | |
public struct Conf { | |
public int X; | |
public int Y; | |
public int W; | |
public int H; | |
public bool B; | |
} | |
public partial class Form1 : Form { | |
[DllImport("User32.dll", SetLastError = true)] | |
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); | |
[DllImport("User32.dll", SetLastError = true)] | |
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); [DllImport("User32.dll", SetLastError = true)] | |
private static extern int GetWindowLong(IntPtr hWnd, int nIndex); | |
private int _defaultStyle = -1, _defaultExStyle = -1; | |
const int GWL_STYLE = -16; | |
const int GWL_EXSTYLE = -20; | |
const int WS_BORDER = 0x00800000; | |
const int WS_DLGFRAME = 0x00400000; | |
const int WS_CAPTION = WS_BORDER | WS_DLGFRAME; | |
const int WS_SYSMENU = 0x00080000; | |
const int WS_MINIMIZEBOX = 0x00020000; | |
const int WS_MAXIMIZEBOX = 0x00010000; | |
const int WS_THICKFRAME = 0x00040000; | |
const int WS_EX_DLGMODALFRAME = 0x00000001; | |
const int WS_EX_CLIENTEDGE = 0x00000200; | |
const int WS_EX_STATICEDGE = 0x00020000; | |
private Conf _config; | |
public Form1() { | |
InitializeComponent(); | |
if(File.Exists("config")) { | |
var cfg = File.ReadAllText("config"); | |
var cfgp = cfg.Split(','); | |
_config = new Conf() { | |
X = int.Parse(cfgp[0]), | |
Y = int.Parse(cfgp[1]), | |
W = int.Parse(cfgp[2]), | |
H = int.Parse(cfgp[3]), | |
B = bool.Parse(cfgp[4]) | |
}; | |
numX.Value = _config.X; | |
numY.Value = _config.Y; | |
numW.Value = _config.W; | |
numH.Value = _config.H; | |
cbBorderless.Checked = _config.B; | |
} | |
} | |
private void btnApply_Click(object sender, EventArgs e) { | |
_config.X = (int)numX.Value; | |
_config.Y = (int)numY.Value; | |
_config.W = (int)numW.Value; | |
_config.H = (int)numH.Value; | |
_config.B = cbBorderless.Checked; | |
File.WriteAllText("config", $"{_config.X},{_config.Y},{_config.W},{_config.H},{_config.B}"); | |
Process? poeProc = null; | |
foreach(var p in Process.GetProcesses()) { | |
if (p.ProcessName.Contains("path", StringComparison.CurrentCultureIgnoreCase)) { | |
poeProc = p; | |
break; | |
} | |
} | |
if (poeProc == null) { | |
MessageBox.Show("Failed to locate poe process", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
return; | |
} | |
var poeHwnd = poeProc.MainWindowHandle; | |
if(poeHwnd == IntPtr.Zero) { | |
MessageBox.Show("Failed to locate poe window", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
return; | |
} | |
if (_defaultStyle == -1) { | |
_defaultStyle = GetWindowLong(poeHwnd, GWL_STYLE); | |
_defaultExStyle = GetWindowLong(poeHwnd, GWL_EXSTYLE); | |
} | |
if(cbBorderless.Checked) { | |
var style = GetWindowLong(poeHwnd, GWL_STYLE); | |
var exStyle = GetWindowLong(poeHwnd, GWL_STYLE); | |
style &= ~(WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME); | |
exStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE); | |
SetWindowLong(poeHwnd, GWL_STYLE, style); | |
SetWindowLong(poeHwnd, GWL_EXSTYLE, exStyle); | |
} else { | |
SetWindowLong(poeHwnd, GWL_STYLE, _defaultStyle); | |
SetWindowLong(poeHwnd, GWL_EXSTYLE, _defaultExStyle); | |
} | |
SetWindowPos(poeHwnd, IntPtr.Zero, (int)numX.Value, (int)numY.Value, (int)numW.Value, (int)numH.Value, 0x0027); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace PoE2WindowManip; | |
partial class Form1 { | |
/// <summary> | |
/// Required designer variable. | |
/// </summary> | |
private System.ComponentModel.IContainer components = null; | |
/// <summary> | |
/// Clean up any resources being used. | |
/// </summary> | |
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> | |
protected override void Dispose(bool disposing) { | |
if (disposing && (components != null)) { | |
components.Dispose(); | |
} | |
base.Dispose(disposing); | |
} | |
#region Windows Form Designer generated code | |
/// <summary> | |
/// Required method for Designer support - do not modify | |
/// the contents of this method with the code editor. | |
/// </summary> | |
private void InitializeComponent() { | |
numW = new NumericUpDown(); | |
label1 = new Label(); | |
label2 = new Label(); | |
numH = new NumericUpDown(); | |
label3 = new Label(); | |
numY = new NumericUpDown(); | |
label4 = new Label(); | |
numX = new NumericUpDown(); | |
cbBorderless = new CheckBox(); | |
btnApply = new Button(); | |
((System.ComponentModel.ISupportInitialize)numW).BeginInit(); | |
((System.ComponentModel.ISupportInitialize)numH).BeginInit(); | |
((System.ComponentModel.ISupportInitialize)numY).BeginInit(); | |
((System.ComponentModel.ISupportInitialize)numX).BeginInit(); | |
SuspendLayout(); | |
// | |
// numW | |
// | |
numW.Location = new Point(109, 102); | |
numW.Maximum = new decimal(new int[] { 10000, 0, 0, 0 }); | |
numW.Name = "numW"; | |
numW.Size = new Size(240, 39); | |
numW.TabIndex = 0; | |
// | |
// label1 | |
// | |
label1.AutoSize = true; | |
label1.Location = new Point(11, 104); | |
label1.Name = "label1"; | |
label1.Size = new Size(78, 32); | |
label1.TabIndex = 1; | |
label1.Text = "Width"; | |
// | |
// label2 | |
// | |
label2.AutoSize = true; | |
label2.Location = new Point(11, 149); | |
label2.Name = "label2"; | |
label2.Size = new Size(86, 32); | |
label2.TabIndex = 3; | |
label2.Text = "Height"; | |
// | |
// numH | |
// | |
numH.Location = new Point(109, 147); | |
numH.Maximum = new decimal(new int[] { 10000, 0, 0, 0 }); | |
numH.Name = "numH"; | |
numH.Size = new Size(240, 39); | |
numH.TabIndex = 2; | |
// | |
// label3 | |
// | |
label3.AutoSize = true; | |
label3.Location = new Point(11, 59); | |
label3.Name = "label3"; | |
label3.Size = new Size(27, 32); | |
label3.TabIndex = 7; | |
label3.Text = "Y"; | |
// | |
// numY | |
// | |
numY.Location = new Point(109, 57); | |
numY.Name = "numY"; | |
numY.Size = new Size(240, 39); | |
numY.TabIndex = 6; | |
// | |
// label4 | |
// | |
label4.AutoSize = true; | |
label4.Location = new Point(11, 14); | |
label4.Name = "label4"; | |
label4.Size = new Size(28, 32); | |
label4.TabIndex = 5; | |
label4.Text = "X"; | |
// | |
// numX | |
// | |
numX.Location = new Point(109, 12); | |
numX.Name = "numX"; | |
numX.Size = new Size(240, 39); | |
numX.TabIndex = 4; | |
// | |
// cbBorderless | |
// | |
cbBorderless.AutoSize = true; | |
cbBorderless.CheckAlign = ContentAlignment.MiddleRight; | |
cbBorderless.Location = new Point(11, 198); | |
cbBorderless.Name = "cbBorderless"; | |
cbBorderless.Size = new Size(156, 36); | |
cbBorderless.TabIndex = 8; | |
cbBorderless.Text = "Borderless"; | |
cbBorderless.UseVisualStyleBackColor = true; | |
// | |
// btnApply | |
// | |
btnApply.Location = new Point(199, 192); | |
btnApply.Name = "btnApply"; | |
btnApply.Size = new Size(150, 46); | |
btnApply.TabIndex = 9; | |
btnApply.Text = "Apply"; | |
btnApply.UseVisualStyleBackColor = true; | |
btnApply.Click += btnApply_Click; | |
// | |
// Form1 | |
// | |
AutoScaleDimensions = new SizeF(13F, 32F); | |
AutoScaleMode = AutoScaleMode.Font; | |
ClientSize = new Size(361, 255); | |
Controls.Add(btnApply); | |
Controls.Add(cbBorderless); | |
Controls.Add(label3); | |
Controls.Add(numY); | |
Controls.Add(label4); | |
Controls.Add(numX); | |
Controls.Add(label2); | |
Controls.Add(numH); | |
Controls.Add(label1); | |
Controls.Add(numW); | |
Name = "Form1"; | |
Text = "Form1"; | |
((System.ComponentModel.ISupportInitialize)numW).EndInit(); | |
((System.ComponentModel.ISupportInitialize)numH).EndInit(); | |
((System.ComponentModel.ISupportInitialize)numY).EndInit(); | |
((System.ComponentModel.ISupportInitialize)numX).EndInit(); | |
ResumeLayout(false); | |
PerformLayout(); | |
} | |
#endregion | |
private NumericUpDown numW; | |
private Label label1; | |
private Label label2; | |
private NumericUpDown numH; | |
private Label label3; | |
private NumericUpDown numY; | |
private Label label4; | |
private NumericUpDown numX; | |
private CheckBox cbBorderless; | |
private Button btnApply; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment