1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-25 20:53:15 +00:00

Added support for trapping child window events

Added first rev of support for mouse over cursor changes
This commit is contained in:
Bryan Roe
2022-04-19 13:00:11 -07:00
parent c0cff1225f
commit edff560369
4 changed files with 195 additions and 10 deletions

View File

@@ -26,10 +26,15 @@ const DEFAULT_QUALITY = 0;
const DEFAULT_PITCH = 0;
const FF_SWISS = (2 << 4); /* Variable stroke width, sans-serifed. */
const TME_HOVER = 0x00000001;
const TME_LEAVE = 0x00000002;
const TME_NONCLIENT = 0x00000010;
const WM_NCLBUTTONDOWN = 0x00A1;
const HT_CAPTION = 2;
const WM_WINDOWPOSCHANGING = 70;
const IDC_ARROW = 32512;
const IDC_HAND = 32649;
const SW_SHOW = 5;
const SW_HIDE = 0;
@@ -40,10 +45,16 @@ const WM_MOUSEMOVE = 0x0200;
const WM_SETFONT = 0x0030;
const WM_LBUTTONDOWN = 0x0201;
const WM_USER = 0x0400;
const WM_MOUSEHOVER = 0x02A1;
const WM_MOUSELEAVE = 0x02A3;
const WM_NCMOUSEHOVER = 0x02A0;
const WM_NCMOUSELEAVE = 0x02A2;
const WS_CHILD = 0x40000000;
const WS_TABSTOP = 0x00010000;
const WS_VISIBLE = 0x10000000;
const WM_SETCURSOR = 0x0020;
const GCL_HCURSOR = -12;
const GCLP_HCURSOR = -12;
const STM_SETIMAGE = 0x0172;
const STM_GETIMAGE = 0x0173;
@@ -294,6 +305,11 @@ function windows_notifybar_local(title, bar_options)
this.notifybar._pumps.peek().on('hwnd', function (h)
{
this._HANDLE = h;
this._HAND = this._user32.LoadCursorA(0, IDC_HAND);
this._ARROW = this._user32.LoadCursorA(0, IDC_ARROW);
this._addAsyncMethodCall(this._user32.SetClassLongPtrA.async, [h, GCLP_HCURSOR, this._ARROW]).then(function (z) { console.log('SetClassLong: ' + z.Val, z._LastError); });
this._icon = getScaledImage(x_icon, this.height * 0.75, this.height * 0.75, bar_options);
this._addCreateWindowEx(0, GM.CreateVariable('STATIC', { wide: true }), GM.CreateVariable('X', { wide: true }), WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_BITMAP | SS_CENTERIMAGE | SS_NOTIFY,
this.width - (this.height * 0.75) - (this.height * 0.125), // x position
@@ -323,6 +339,17 @@ function windows_notifybar_local(title, bar_options)
this.pump._pushpin = c;
this.pump._pinned = true;
this.pump._addAsyncMethodCall(this.pump._user32.SendMessageW.async, [c, STM_SETIMAGE, IMAGE_BITMAP, this.pump._pin1.Deref()]);
c.x = this.pump.height * 0.125;
c.y = this.pump.height * 0.0625;
c.w = this.pump.height * 0.75;
c.h = this.pump.height * 0.75;
var r = GM.CreateVariable(4);
r.increment(4294967284, true);
this.pump._addAsyncMethodCall(this.pump._user32.SetClassLongPtrA.async, [c, GCLP_HCURSOR, this.pump._HAND]).then(function (z) { console.log('SetClassLong: ' + z.Val, z._LastError); });
//this.pump.hookChild(c);
}).parentPromise.pump = this;
this._addCreateWindowEx(0, GM.CreateVariable('STATIC', { wide: true }), GM.CreateVariable(this._title, { wide: true }), WS_TABSTOP | WS_VISIBLE | WS_CHILD | SS_LEFT | SS_CENTERIMAGE | SS_WORDELLIPSIS,
this.height, // x position
@@ -419,6 +446,26 @@ function windows_notifybar_local(title, bar_options)
}
break;
case WM_MOUSEMOVE:
if (msg.hwnd.Val == this._pushpin.Val)
{
if (this.pushpincursor == null || this.pushpincursor === false)
{
this.pushpincursor = true;
console.log('PUSHPIN!');
var v = GM.CreateVariable(24);
v.toBuffer().writeUInt32LE(24);
v.toBuffer().writeUInt32LE(TME_LEAVE, 4);
this._pushpin.pointerBuffer().copy(v.Deref(8, 8).toBuffer());
this._user32.TrackMouseEvent(v);
//this._addAsyncMethodCall(this._user32.LoadCursorA.async, [0, IDC_HAND]).then(function (cs)
//{
// this.pump._addAsyncMethodCall(this.pump._user32.SetCursor.async, [cs]);
//}).parentPromise.pump = this;
//break;
}
}
if (!this._pinned)
{
if (this._minimized)
@@ -431,6 +478,29 @@ function windows_notifybar_local(title, bar_options)
this._idle = setTimeout(this._idleTimeout.bind(this), 3000);
}
break;
case WM_MOUSELEAVE:
case WM_NCMOUSELEAVE:
console.log('LEAVE!');
this.pushpincursor = false;
this._addAsyncMethodCall(this._user32.LoadCursorA.async, [0, IDC_ARROW]).then(function (cs)
{
this.pump._addAsyncMethodCall(this.pump._user32.SetCursor.async, [cs]);
}).parentPromise.pump = this;
break;
case WM_SETCURSOR:
console.log('SETCURSOR', this._HANDLE.Val == msg.hwnd.Val);
if (this._HANDLE.Val == msg.hwnd.Val)
{
//if(this.pushpincursor === true)
//{
// return (this._HAND);
//}
//else
//{
// return (this._ARROW);
//}
}
break;
}
});
}

View File

@@ -18,6 +18,7 @@ var WH_CALLWNDPROC = 4;
var WM_QUIT = 0x0012;
var WM_CLOSE = 0x0010;
var GM = require('_GenericMarshal');
const GWLP_WNDPROC = -4;
function WindowsMessagePump(options)
{
@@ -55,11 +56,15 @@ function WindowsMessagePump(options)
this._user32.CreateMethod('RegisterClassExW');
this._user32.CreateMethod('ReleaseCapture');
this._user32.CreateMethod('SendMessageW');
this._user32.CreateMethod('SetClassLongA');
this._user32.CreateMethod('SetClassLongPtrA');
this._user32.CreateMethod('SetCursor');
this._user32.CreateMethod('SetWindowLongPtrA');
this._user32.CreateMethod('SetWindowPos');
this._user32.CreateMethod('SetWindowTextW');
this._user32.CreateMethod('ShowWindow');
this._user32.CreateMethod('SystemParametersInfoA');
this._user32.CreateMethod('TrackMouseEvent');
this._user32.CreateMethod('TranslateMessage');
this._user32.CreateMethod('UnregisterClassW');
@@ -101,6 +106,7 @@ function WindowsMessagePump(options)
this.wndclass.wndproc.on('GlobalCallback', function onWndProc(xhwnd, xmsg, wparam, lparam)
{
var processed = false;
if (this.mp._hwnd != null && this.mp._hwnd.Val == xhwnd.Val)
{
// This is for us
@@ -186,6 +192,7 @@ function WindowsMessagePump(options)
if (!this.nativeProxy.mp._options) { this.nativeProxy.mp._options = {}; }
if (!this.nativeProxy.mp._options.window) { this.nativeProxy.mp._options.window = {}; }
if (this.nativeProxy.mp._options.window.exstyles == null) { this.nativeProxy.mp._options.window.exstyles = 0x00000088; } // TopMost Tool Window
//if (this.nativeProxy.mp._options.window.exstyles == null) { this.nativeProxy.mp._options.window.exstyles = 0x00000080; } // Tool Window
if (this.nativeProxy.mp._options.window.winstyles == null) { this.nativeProxy.mp._options.window.winstyles = 0x00800000; } // WS_BORDER
if (this.nativeProxy.mp._options.window.x == null) { this.nativeProxy.mp._options.window.x = 0; }
if (this.nativeProxy.mp._options.window.y == null) { this.nativeProxy.mp._options.window.y = 0; }
@@ -230,7 +237,8 @@ function WindowsMessagePump(options)
this._startPump_continuation = function _startPump_continuation(h)
{
this.finalpromise.resolve(h);
this.nativeProxy.mp._startPump();
//this.nativeProxy.mp._startPump();
this.mp._startPump();
}
this._startPump = function _startPump()
{
@@ -241,6 +249,7 @@ function WindowsMessagePump(options)
args.unshift(this._user32.RegisterClassExW.async);
var p2 = j.func.apply(this._user32, args);
p2.finalpromise = j.p;
p2.mp = this;
p2.then(this._startPump_continuation);
return;
}
@@ -294,6 +303,36 @@ function WindowsMessagePump(options)
{
this.stop();
});
this.hookChild = function hookChild(childHwnd)
{
if (this.wndclass.wndproc.hooks == null) { this.wndclass.wndproc.hooks = []; }
var newval = GM.GetGenericGlobalCallbackEx(4, 55);
newval.childHwnd = childHwnd;
newval.mp = this;
newval.on('GlobalCallback', function hookedWndProc(xhwnd, xmsg, wparam, lparam)
{
if (this.childHwnd.Val == xhwnd.Val)
{
try
{
this.mp.emit('message', { message: xmsg.Val, wparam: wparam.Val, lparam: lparam.Val, lparam_hex: lparam.pointerBuffer().toString('hex'), lparam_raw: lparam, hwnd: xhwnd });
}
catch (zz)
{
console.info1(zz);
}
}
});
var old = this._user32.SetWindowLongPtrA(childHwnd, GWLP_WNDPROC, newval);
if (old.Val != 0)
{
GM.PutData(childHwnd, old, newval);
return (true);
}
return (false);
}
}
module.exports = WindowsMessagePump;