mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-11 17:34:58 +00:00
93 lines
2.7 KiB
C#
93 lines
2.7 KiB
C#
/*
|
|
* WelsonJS.Toolkit: WelsonJS native component
|
|
*
|
|
* filename:
|
|
* Window.cs
|
|
*
|
|
* description:
|
|
* WelsonJS - Build a Windows app on the Windows built-in JavaScript engine
|
|
*
|
|
* website:
|
|
* - https://github.com/gnh1201/welsonjs
|
|
* - https://catswords.social/@catswords_oss
|
|
* - https://teams.live.com/l/community/FEACHncAhq8ldnojAI
|
|
*
|
|
* author:
|
|
* Namhyeon Go <abuse@catswords.net>
|
|
*
|
|
* license:
|
|
* GPLv3 or MS-RL(Microsoft Reciprocal License)
|
|
*
|
|
*/
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace WelsonJS
|
|
{
|
|
public class Window
|
|
{
|
|
[DllImport("user32.dll")]
|
|
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string lpsz1, string lpsz2);
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
public static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, IntPtr lParam);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern int SendMessage(IntPtr hWnd, uint msg, int wParam, IntPtr lParam);
|
|
|
|
public enum Message : int
|
|
{
|
|
WM_MOUSEMOVE = 0x200,
|
|
WM_LBUTTONDOWN = 0x201, //Left mousebutton down
|
|
WM_LBUTTONUP = 0x202, //Left mousebutton up
|
|
WM_LBUTTONDBLCLK = 0x203, //Left mousebutton doubleclick
|
|
WM_RBUTTONDOWN = 0x204, //Right mousebutton down
|
|
WM_RBUTTONUP = 0x205, //Right mousebutton up
|
|
WM_RBUTTONDBLCLK = 0x206, //Right mousebutton doubleclick
|
|
WM_KEYDOWN = 0x100, //Key down
|
|
WM_KEYUP = 0x101, //Key up
|
|
WM_SYSKEYDOWN = 0x104,
|
|
WM_SYSKEYUP = 0x105,
|
|
WM_CHAR = 0x102, //char
|
|
WM_COMMAND = 0x111
|
|
}
|
|
|
|
public enum VirtualKey : int
|
|
{
|
|
VK_RETURN = 0x0D,
|
|
VK_F1 = 0x70,
|
|
VK_F2 = 0x71,
|
|
VK_F3 = 0x72,
|
|
VK_F4 = 0x73,
|
|
VK_F5 = 0x74,
|
|
VK_F6 = 0x75,
|
|
VK_F7 = 0x76,
|
|
VK_F8 = 0x77,
|
|
VK_F9 = 0x78,
|
|
VK_F10 = 0x79,
|
|
VK_F11 = 0x7A,
|
|
VK_F12 = 0x7B
|
|
}
|
|
|
|
public static IntPtr GetWindowByTitleContains(string title)
|
|
{
|
|
IntPtr hWnd = IntPtr.Zero;
|
|
|
|
foreach (Process proc in Process.GetProcesses())
|
|
{
|
|
if (proc.MainWindowTitle.Contains(title))
|
|
{
|
|
hWnd = proc.MainWindowHandle;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return hWnd;
|
|
}
|
|
}
|
|
}
|