Update WelsonJS.Toolkit

This commit is contained in:
Namhyeon Go 2021-10-14 02:54:32 +09:00
parent 27d0521de5
commit 2a465de78f
2 changed files with 62 additions and 0 deletions

View File

@ -14,6 +14,7 @@
* - https://stackoverflow.com/questions/13547639/return-window-handle-by-its-name-title
* - https://blog.naver.com/zlatmgpdjtiq/222016292758
* - https://stackoverflow.com/questions/5427020/prompt-dialog-in-windows-forms
* - https://stackoverflow.com/questions/60203135/set-delta-in-a-wm-mousewheel-message-to-send-with-postmessage
*/
using System;
@ -56,6 +57,32 @@ namespace WelsonJS
WM_CHAR = 0x102, //char
WM_COMMAND = 0x111
}
public enum WinMsgMouseKey : int
{
MK_NONE = 0x0000,
MK_LBUTTON = 0x0001,
MK_RBUTTON = 0x0002,
MK_SHIFT = 0x0004,
MK_CONTROL = 0x0008,
MK_MBUTTON = 0x0010,
MK_XBUTTON1 = 0x0020,
MK_XBUTTON2 = 0x0040
}
public int directionUp = 1;
public int directionDown = -1;
public const uint WM_MOUSEWHEEL = 0x020A;
public IntPtr MAKEWPARAM(int direction, float multiplier, WinMsgMouseKey button)
{
int delta = (int)(SystemInformation.MouseWheelScrollDelta * multiplier);
return (IntPtr)(((delta << 16) * Math.Sign(direction) | (ushort)button));
}
public IntPtr MAKELPARAM(int low, int high)
{
return (IntPtr)((high << 16) | (low & 0xFFFF));
}
public IntPtr QueryHandleWindow(string wName)
{
@ -137,5 +164,39 @@ namespace WelsonJS
string result = WelsonJS.Prompt.ShowDialog(message, ApplicationName);
return (result == "" ? _default : result);
}
[ComVisible(true)]
public bool MouseWheelDown(string wName)
{
bool result = false;
IntPtr hWnd = QueryHandleWindow(wName);
if (hWnd != IntPtr.Zero)
{
// Scrolls [Handle] down by 1/2 wheel rotation with Left Button pressed
IntPtr wParam = MAKEWPARAM(directionDown, .5f, WinMsgMouseKey.MK_LBUTTON);
IntPtr lParam = MAKELPARAM(Cursor.Position.X, Cursor.Position.Y);
result = PostMessage(hWnd, WM_MOUSEWHEEL, (int)wParam, lParam);
}
return result;
}
[ComVisible(true)]
public bool MouseWheelUp(string wName)
{
bool result = false;
IntPtr hWnd = QueryHandleWindow(wName);
if (hWnd != IntPtr.Zero)
{
// Scrolls [Handle] up by 1/2 wheel rotation with Left Button pressed
IntPtr wParam = MAKEWPARAM(directionUp, .5f, WinMsgMouseKey.MK_LBUTTON);
IntPtr lParam = MAKELPARAM(Cursor.Position.X, Cursor.Position.Y);
result = PostMessage(hWnd, WM_MOUSEWHEEL, (int)wParam, lParam);
}
return result;
}
}
}

View File

@ -43,6 +43,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>