Skip to content

Commit 6fd143d

Browse files
committed
almost 2.0
1 parent 7824676 commit 6fd143d

22 files changed

+339
-419
lines changed

.vs/QuickLibrary/v16/.suo

-2.5 KB
Binary file not shown.
0 Bytes
Binary file not shown.

QuickLibrary/FileAssociation.cs

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
namespace QuickLibrary
2+
{
3+
using System;
4+
using System.Diagnostics;
5+
using System.IO;
6+
using System.Runtime.InteropServices;
7+
using System.Text;
8+
9+
public static class FileAssociation
10+
{
11+
/// <summary>
12+
///
13+
/// </summary>
14+
/// <param name="ext"></param>
15+
/// <param name="verb"></param>
16+
/// <returns>Return null if not found</returns>
17+
public static string GetExecCommandAssociatedToExtension(string ext, string verb = null)
18+
{
19+
if (ext[0] != '.')
20+
{
21+
ext = "." + ext;
22+
}
23+
24+
string executablePath = FileExtentionInfo(AssocStr.Command, ext, verb);
25+
26+
// Ensure to not return the default OpenWith.exe associated executable in Windows 8 or higher
27+
if (!string.IsNullOrEmpty(executablePath) && File.Exists(executablePath) &&
28+
!executablePath.ToLower().EndsWith(".dll"))
29+
{
30+
if (executablePath.ToLower().EndsWith("openwith.exe"))
31+
{
32+
return null; // 'OpenWith.exe' is th windows 8 or higher default for unknown extensions. I don't want to have it as associted file
33+
}
34+
return executablePath;
35+
}
36+
return executablePath;
37+
}
38+
39+
/// <summary>
40+
///
41+
/// </summary>
42+
/// <param name="ext"></param>
43+
/// <param name="verb"></param>
44+
/// <returns>Return null if not found</returns>
45+
public static string GetExecFileAssociatedToExtension(string ext, string verb = null)
46+
{
47+
if (ext[0] != '.')
48+
{
49+
ext = "." + ext;
50+
}
51+
52+
string executablePath = FileExtentionInfo(AssocStr.Executable, ext, verb); // Will only work for 'open' verb
53+
if (string.IsNullOrEmpty(executablePath))
54+
{
55+
executablePath = FileExtentionInfo(AssocStr.Command, ext, verb); // required to find command of any other verb than 'open'
56+
57+
// Extract only the path
58+
if (!string.IsNullOrEmpty(executablePath) && executablePath.Length > 1)
59+
{
60+
if (executablePath[0] == '"')
61+
{
62+
executablePath = executablePath.Split('\"')[1];
63+
}
64+
else if (executablePath[0] == '\'')
65+
{
66+
executablePath = executablePath.Split('\'')[1];
67+
}
68+
}
69+
}
70+
71+
// Ensure to not return the default OpenWith.exe associated executable in Windows 8 or higher
72+
if (!string.IsNullOrEmpty(executablePath) && File.Exists(executablePath) &&
73+
!executablePath.ToLower().EndsWith(".dll"))
74+
{
75+
if (executablePath.ToLower().EndsWith("openwith.exe"))
76+
{
77+
return null; // 'OpenWith.exe' is th windows 8 or higher default for unknown extensions. I don't want to have it as associted file
78+
}
79+
return executablePath;
80+
}
81+
return executablePath;
82+
}
83+
84+
[DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
85+
static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] StringBuilder pszOut, [In][Out] ref uint pcchOut);
86+
87+
private static string FileExtentionInfo(AssocStr assocStr, string doctype, string verb)
88+
{
89+
uint pcchOut = 0;
90+
AssocQueryString(AssocF.Verify, assocStr, doctype, verb, null, ref pcchOut);
91+
92+
Debug.Assert(pcchOut != 0);
93+
if (pcchOut == 0)
94+
{
95+
return "";
96+
}
97+
98+
StringBuilder pszOut = new StringBuilder((int)pcchOut);
99+
AssocQueryString(AssocF.Verify, assocStr, doctype, verb, pszOut, ref pcchOut);
100+
return pszOut.ToString();
101+
}
102+
103+
[Flags]
104+
public enum AssocF
105+
{
106+
Init_NoRemapCLSID = 0x1,
107+
Init_ByExeName = 0x2,
108+
Open_ByExeName = 0x2,
109+
Init_DefaultToStar = 0x4,
110+
Init_DefaultToFolder = 0x8,
111+
NoUserSettings = 0x10,
112+
NoTruncate = 0x20,
113+
Verify = 0x40,
114+
RemapRunDll = 0x80,
115+
NoFixUps = 0x100,
116+
IgnoreBaseClass = 0x200
117+
}
118+
119+
public enum AssocStr
120+
{
121+
Command = 1,
122+
Executable,
123+
FriendlyDocName,
124+
FriendlyAppName,
125+
NoOpen,
126+
ShellNewValue,
127+
DDECommand,
128+
DDEIfExec,
129+
DDEApplication,
130+
DDETopic
131+
}
132+
}
133+
}

QuickLibrary/NativeMethodsManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public static class NativeMethodsManager
99
public const int WM_NCLBUTTONDOWN = 0xA1;
1010
public const int HT_CAPTION = 0x2;
1111
public const int GWL_HWNDPARENT = -8;
12+
public const int WS_SYSMENU = 0x80000;
13+
public const int CS_DROPSHADOW = 0x20000;
14+
public const int WS_MINIMIZEBOX = 0x20000;
15+
public const int WS_MAXIMIZEBOX = 0x10000;
16+
public const int WM_POPUPSYSTEMMENU = 0x313;
1217

1318
public enum ScrollBarType : uint
1419
{

QuickLibrary/QlibCheckBox.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,29 @@ protected override void OnPaint(PaintEventArgs e)
6666
{
6767
if (darkMode)
6868
{
69+
int top = (this.Height / 2) - 8;
70+
6971
e.Graphics.Clear(this.BackColor);
7072

7173
if (this.pressed)
7274
{
73-
e.Graphics.FillRectangle(new SolidBrush(ThemeManager.PressedColor), new Rectangle(0, 2, 13, 13));
75+
e.Graphics.FillRectangle(new SolidBrush(ThemeManager.PressedColor), new Rectangle(0, top + 2, 13, 13));
7476
}
7577
else
7678
{
7779
if (this.hovered)
7880
{
79-
e.Graphics.FillRectangle(new SolidBrush(ThemeManager.DarkHoverColor), new Rectangle(0, 2, 13, 13));
81+
e.Graphics.FillRectangle(new SolidBrush(ThemeManager.DarkHoverColor), new Rectangle(0, top + 2, 13, 13));
8082
}
8183
else
8284
{
83-
e.Graphics.FillRectangle(new SolidBrush(ThemeManager.DarkSecondColor), new Rectangle(0, 2, 13, 13));
85+
e.Graphics.FillRectangle(new SolidBrush(ThemeManager.DarkSecondColor), new Rectangle(0, top + 2, 13, 13));
8486
}
8587
}
8688

8789
if (this.Focused)
8890
{
89-
e.Graphics.DrawRectangle(new Pen(ThemeManager.BorderColor, 2), new Rectangle(1, 3, 11, 11));
90-
}
91-
else
92-
{
93-
//ControlPaint.DrawBorder(e.Graphics, new Rectangle(0, 2, 13, 13), ThemeManager.BorderColor, ButtonBorderStyle.Solid);
91+
e.Graphics.DrawRectangle(new Pen(ThemeManager.BorderColor, 2), new Rectangle(1, top + 3, 11, 11));
9492
}
9593

9694
if (this.Checked)
@@ -99,24 +97,24 @@ protected override void OnPaint(PaintEventArgs e)
9997

10098
if (this.Enabled)
10199
{
102-
e.Graphics.DrawLine(new Pen(this.ForeColor, 2), 2, 7, 5, 10);
103-
e.Graphics.DrawLine(new Pen(this.ForeColor, 2), 5, 11, 12, 4);
100+
e.Graphics.DrawLine(new Pen(this.ForeColor, 2), 2, top + 7, 5, top + 10);
101+
e.Graphics.DrawLine(new Pen(this.ForeColor, 2), 5, top + 11, 12, top + 4);
104102
}
105103
else
106104
{
107-
e.Graphics.DrawLine(new Pen(ThemeManager.BorderColor, 2), 2, 7, 5, 10);
108-
e.Graphics.DrawLine(new Pen(ThemeManager.BorderColor, 2), 5, 11, 12, 4);
105+
e.Graphics.DrawLine(new Pen(ThemeManager.BorderColor, 2), 2, top + 7, 5, top + 10);
106+
e.Graphics.DrawLine(new Pen(ThemeManager.BorderColor, 2), 5, top + 11, 12, top + 4);
109107
}
110108
}
111109

112110
e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
113111
if (this.Enabled)
114112
{
115-
e.Graphics.DrawString(darkText, this.Font, new SolidBrush(this.ForeColor), 17, 0);
113+
e.Graphics.DrawString(darkText, this.Font, new SolidBrush(this.ForeColor), 17, top);
116114
}
117115
else
118116
{
119-
e.Graphics.DrawString(darkText, this.Font, new SolidBrush(ThemeManager.BorderColor), 17, 0);
117+
e.Graphics.DrawString(darkText, this.Font, new SolidBrush(ThemeManager.BorderColor), 17, top);
120118
}
121119
}
122120
else

QuickLibrary/QlibCloseButton.cs

Lines changed: 0 additions & 54 deletions
This file was deleted.

QuickLibrary/QlibFixedForm.cs

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -39,99 +39,18 @@ public class QlibFixedForm : Form
3939
[Browsable(false), Obsolete("Don't use this! (Font = ThemeManager.DefaultFont)", true), EditorBrowsable(EditorBrowsableState.Never)]
4040
public new enum Font { };
4141

42-
private bool m_aeroEnabled;
4342
public bool draggable = false;
4443

45-
//private const int CS_DROPSHADOW = 0x00020000;
46-
//private const int WM_NCPAINT = 0x0085;
47-
48-
//[System.Runtime.InteropServices.DllImport("dwmapi.dll")]
49-
//public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
50-
//[System.Runtime.InteropServices.DllImport("dwmapi.dll")]
51-
//public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
52-
//[System.Runtime.InteropServices.DllImport("dwmapi.dll")]
53-
54-
//public static extern int DwmIsCompositionEnabled(ref int pfEnabled);
55-
//[System.Runtime.InteropServices.DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
56-
57-
//private static extern IntPtr CreateRoundRectRgn(
58-
// int nLeftRect,
59-
// int nTopRect,
60-
// int nRightRect,
61-
// int nBottomRect,
62-
// int nWidthEllipse,
63-
// int nHeightEllipse
64-
//);
65-
66-
//public struct MARGINS
67-
//{
68-
// public int leftWidth;
69-
// public int rightWidth;
70-
// public int topHeight;
71-
// public int bottomHeight;
72-
//}
73-
74-
//protected override CreateParams CreateParams
75-
//{
76-
// get
77-
// {
78-
// m_aeroEnabled = CheckAeroEnabled();
79-
// CreateParams cp = base.CreateParams;
80-
// if (!m_aeroEnabled)
81-
// cp.ClassStyle |= CS_DROPSHADOW;
82-
// return cp;
83-
// }
84-
//}
85-
86-
public const int WS_SYSMENU = 0x80000;
87-
public const int CS_DROPSHADOW = 0x20000;
88-
8944
protected override CreateParams CreateParams
9045
{
9146
get
9247
{
9348
CreateParams cp = base.CreateParams;
94-
//cp.Style = WS_SYSMENU;
95-
cp.ClassStyle |= CS_DROPSHADOW;
49+
cp.ClassStyle |= NativeMethodsManager.CS_DROPSHADOW;
9650
return cp;
9751
}
9852
}
9953

100-
//private bool CheckAeroEnabled()
101-
//{
102-
// if (Environment.OSVersion.Version.Major >= 6)
103-
// {
104-
// int enabled = 0;
105-
// DwmIsCompositionEnabled(ref enabled);
106-
// return (enabled == 1) ? true : false;
107-
// }
108-
// return false;
109-
//}
110-
111-
//protected override void WndProc(ref Message m)
112-
//{
113-
// switch (m.Msg)
114-
// {
115-
// case WM_NCPAINT:
116-
// if (m_aeroEnabled)
117-
// {
118-
// var v = 2;
119-
// DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
120-
// MARGINS margins = new MARGINS()
121-
// {
122-
// bottomHeight = -1,
123-
// leftWidth = 0,
124-
// rightWidth = 0,
125-
// topHeight = 0
126-
// };
127-
// DwmExtendFrameIntoClientArea(this.Handle, ref margins);
128-
// }
129-
// break;
130-
// default: break;
131-
// }
132-
// base.WndProc(ref m);
133-
//}
134-
13554
public QlibFixedForm()
13655
{
13756
base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
@@ -145,8 +64,6 @@ public QlibFixedForm()
14564
base.BackgroundImage = null;
14665
base.BackgroundImageLayout = ImageLayout.Tile;
14766
base.Font = ThemeManager.DefaultFont;
148-
149-
m_aeroEnabled = !ThemeManager.isWindows10();
15067
}
15168

15269
public void SetDraggableControls(List<Control> controls)

0 commit comments

Comments
 (0)