/****************************************************************************
|
**
|
** Copyright (C) 2020 The Qt Company Ltd.
|
** Contact: https://www.qt.io/licensing/
|
**
|
** This file is part of the Qt VS Tools.
|
**
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
** Commercial License Usage
|
** Licensees holding valid commercial Qt licenses may use this file in
|
** accordance with the commercial license agreement provided with the
|
** Software or, alternatively, in accordance with the terms contained in
|
** a written agreement between you and The Qt Company. For licensing terms
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
** information use the contact form at https://www.qt.io/contact-us.
|
**
|
** GNU General Public License Usage
|
** Alternatively, this file may be used under the terms of the GNU
|
** General Public License version 3 as published by the Free Software
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
** included in the packaging of this file. Please review the following
|
** information to ensure the GNU General Public License requirements will
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
**
|
** $QT_END_LICENSE$
|
**
|
****************************************************************************/
|
|
using System;
|
using System.Runtime.InteropServices;
|
using System.Text;
|
|
namespace QtVsTools
|
{
|
public static class NativeAPI
|
{
|
public const int GWL_STYLE = -16;
|
public const int GWL_EXSTYLE = -20;
|
public const int WS_VISIBLE = 0x10000000;
|
public const int WM_CLOSE = 0x10;
|
public const int WM_STYLECHANGED = 0x007D;
|
public const int WM_GETICON = 0x007F;
|
public const int WM_SETICON = 0x0080;
|
public const int ICON_SMALL = 0;
|
public const int GCL_HICON = -14;
|
public const int GCL_HICONSM = -34;
|
public const int SW_HIDE = 0;
|
public const int SW_SHOWMINNOACTIVE = 7;
|
public const int SW_RESTORE = 9;
|
|
[DllImport("user32.dll")]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
public static extern bool EnumThreadWindows(
|
uint dwThreadId,
|
EnumThreadWindowsCallback lpfn,
|
IntPtr lParam);
|
|
public delegate bool EnumThreadWindowsCallback(IntPtr hWnd, IntPtr lParam);
|
|
[DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetWindowTextW")]
|
public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int maxCount);
|
|
public static string GetWindowCaption(IntPtr hwnd)
|
{
|
var caption = new StringBuilder(256);
|
if (GetWindowText(hwnd, caption, caption.Capacity) > 0)
|
return caption.ToString();
|
else
|
return string.Empty;
|
}
|
|
[DllImport("user32.dll")]
|
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
|
|
[DllImport("user32.dll", EntryPoint = "GetWindowLongW", CharSet = CharSet.Unicode)]
|
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
|
[DllImport("user32.dll")]
|
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
|
[DllImport("user32.dll", EntryPoint = "GetClassLongW", CharSet = CharSet.Unicode)]
|
public static extern int GetClassLong(IntPtr hWnd, int nIndex);
|
|
[DllImport("user32.dll")]
|
public static extern bool MoveWindow(
|
IntPtr Handle,
|
int x, int y,
|
int w, int h,
|
bool repaint);
|
|
[DllImport("user32.dll")]
|
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
|
|
[DllImport("user32.dll")]
|
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
|
|
[DllImport("user32.dll")]
|
public static extern IntPtr SetForegroundWindow(IntPtr hWnd);
|
|
[DllImport("user32.dll")]
|
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
|
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
|
public static extern int SHGetFileInfo(
|
string pszPath,
|
int dwFileAttributes,
|
ref SHFILEINFO psfi,
|
int cbfileInfo,
|
SHGFI uFlags);
|
|
[DllImport("user32.dll", SetLastError = true)]
|
public static extern bool DestroyIcon(IntPtr hIcon);
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
public struct SHFILEINFO
|
{
|
/// <summary>Maximal Length of unmanaged Windows-Path-strings</summary>
|
public const int MAX_PATH = 260;
|
/// <summary>Maximal Length of unmanaged Typename</summary>
|
public const int MAX_TYPE = 80;
|
public SHFILEINFO(bool dummy = true)
|
{
|
hIcon = IntPtr.Zero;
|
iIcon = 0;
|
dwAttributes = 0;
|
szDisplayName = "";
|
szTypeName = "";
|
}
|
public IntPtr hIcon;
|
public int iIcon;
|
public uint dwAttributes;
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)]
|
public string szDisplayName;
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_TYPE)]
|
public string szTypeName;
|
};
|
|
[Flags]
|
public enum SHGFI : int
|
{
|
/// <summary>get icon</summary>
|
Icon = 0x000000100,
|
/// <summary>get display name</summary>
|
DisplayName = 0x000000200,
|
/// <summary>get type name</summary>
|
TypeName = 0x000000400,
|
/// <summary>get attributes</summary>
|
Attributes = 0x000000800,
|
/// <summary>get icon location</summary>
|
IconLocation = 0x000001000,
|
/// <summary>return exe type</summary>
|
ExeType = 0x000002000,
|
/// <summary>get system icon index</summary>
|
SysIconIndex = 0x000004000,
|
/// <summary>put a link overlay on icon</summary>
|
LinkOverlay = 0x000008000,
|
/// <summary>show icon in selected state</summary>
|
Selected = 0x000010000,
|
/// <summary>get only specified attributes</summary>
|
Attr_Specified = 0x000020000,
|
/// <summary>get large icon</summary>
|
LargeIcon = 0x000000000,
|
/// <summary>get small icon</summary>
|
SmallIcon = 0x000000001,
|
/// <summary>get open icon</summary>
|
OpenIcon = 0x000000002,
|
/// <summary>get shell size icon</summary>
|
ShellIconSize = 0x000000004,
|
/// <summary>pszPath is a pidl</summary>
|
PIDL = 0x000000008,
|
/// <summary>use passed dwFileAttribute</summary>
|
UseFileAttributes = 0x000000010,
|
/// <summary>apply the appropriate overlays</summary>
|
AddOverlays = 0x000000020,
|
/// <summary>Get the index of the overlay in the upper 8 bits of the iIcon</summary>
|
OverlayIndex = 0x000000040,
|
}
|
}
|
}
|