node-window-manager icon indicating copy to clipboard operation
node-window-manager copied to clipboard

Distinguish between actual window and menubar app

Open nahtnam opened this issue 5 years ago • 5 comments

Hey,

I was wondering if there is any way to distinguish between a menu bar app and also the space? I am trying to capture and modify all of the open windows on a specific workspace/desktop. Right now when I call getWindows, I get about 15 and they all return true for isWindow, however only 1 window is actually open

nahtnam avatar Dec 15 '19 07:12 nahtnam

i want to ask if this function is work please send message or write doc

WingDust avatar Jan 28 '20 12:01 WingDust

it is from Raymond chen example to get altTab window it's worth to reference https://devblogs.microsoft.com/oldnewthing/20071008-00/?p=24863

WingDust avatar Jan 28 '20 12:01 WingDust

base on up example https://stackoverflow.com/questions/7277366/why-does-enumwindows-return-more-windows-than-i-expected

WingDust avatar Jan 28 '20 12:01 WingDust

This is the best i could do using FFI to interact with win32 api:



let voidPtr = ref.refType(ref.types.void);
let stringPtr = ref.refType(ref.types.CString);


const winapi = ffi.Library('User32', {
  GetDesktopWindow: [  'uint32',  [] ],
  ShowWindow: [  'bool',  ['uint32', 'int'] ],
  FindWindowA: [  'uint32',  ['string', 'uint32'] ],
  FindWindowExW: [  'uint32',  ['uint32', 'uint32', 'uint32', 'uint32'] ],
  GetWindowTextW: [ 'int32', ['uint32','string','int32'] ],
  IsWindowVisible: [ 'bool', ['uint32'] ],
  GetParent: [ 'uint32', ['uint32'] ],
  GetWindowLongPtrA: [ 'uint32', ['uint32', 'int'] ],
  EnumWindows: ['bool', [voidPtr, 'int32']],
  GetWindowTextA : ['long', ['long', stringPtr, 'long']],
  GetWindow: [ 'uint32', ['uint32', 'uint'] ],
  GetClassNameA: [ 'int', ['uint32', 'string', 'int'] ],
  IsHungAppWindow: [ 'bool', ['uint32'] ]
});

// WS_EX_NOREDIRECTIONBITMAP style
// GWL_EXSTYLE = 0x00200000

windowProc = ffi.Callback('bool', ['long', 'int32'], function(hwnd, lParam) {
  let buf, name, ret, visible, hasowner, haslong, test;
  buf = new Buffer.alloc(255);
  ret = winapi.GetWindowTextA(hwnd, buf, 255);
  name = ref.readCString(buf, 0);
  visible = winapi.IsWindowVisible(hwnd);
  hasowner = winapi.GetWindow(hwnd, 4); // GW_OWNER

  let ptr = winapi.GetWindowLongPtrA(hwnd, -20)
  // if (ptr == 0x00200000){
  //   console.log(`Window ${name} PTRA = 0x00200000`)
  // }

  if (name.length > 0 && visible && hasowner == 0) {
    if (ptr == 0x00200000) {
      // console.log("\nUWP:")
    }
    else{
        console.log(`N: ${name}`)
    }
    
}
  }

winapi.EnumWindows(windowProc, 0);

nodgear avatar Mar 16 '21 00:03 nodgear