0

I tried many ways and npm packages to achieve this. But no luck. I am able to do this with only Browser Window.

I also checked this answer But I am not able to do build this node-ffi npm package.

Can anyone guide how we can achieve this?

Example:

I am trying to resize the MS PowerPoint Application window with the help of the electron App.

  • So what would you want to do? Resize an arbitrary window, which is not part of your Electron application? If so, "I can" or "I can't" aren't very helpful statements. Please [edit] your question to include a detailed description of your problem, the desired outcome and what you have tried, in accordance with [ask]. Thanks! – Alexander Leithner Nov 23 '22 at 12:14
  • @AlexanderLeithner Thank you for your reply. I am trying to resize the MS PowerPoint Application window with the help of the electron App. – Nikunj Chaklasiya Nov 23 '22 at 12:33

1 Answers1

1

Yes, it's possible.

To change the size of an external app window you should use Win32 APIs: SetWindowPos or MoveWindow. In fact, your question has already been (partially) answered here.

To access those APIs you can use win32-api. Here's a quick example of resizing a window to 600x600 using the window class name:

const Win32 = require('win32-api/promise');
const User32 = Win32.User32.load(['FindWindowExW','SetWindowPos']);

const SWP_NOMOVE = 0x0002, SWP_NOACTIVATE = 0x0010;

module.exports = {
  ResizeWindow: async function ResizeWindow(className)
  {
    const lpszClass = Buffer.from(className + '\0', 'ucs2')
    const hWnd = await User32.FindWindowExW(0, 0, lpszClass, null); // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-findwindowexw
    User32.SetWindowPos(hWnd, 0, 0, 0, 600, 600, SWP_NOMOVE | SWP_NOACTIVATE); // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos
  }
};

For MS PPT 2013, the class name is PPTFrameClass. You can also use the process ID to get the main window handle like this.

And here's a quick demo: enter image description here

EDIT:

These are the versions that worked for me:

C:\Users\abc>node -v
v18.12.1
"devDependencies": {
   "electron": "^19.0.0"
 },
 "dependencies": {
   "ffi-napi": "^4.0.3",
   "ref-union-di": "^1.0.1",
   "win32-api": "^20.1.0"
 }
Osama
  • 324
  • 3
  • 11
  • Thank you for your answer. I have already tried this code like this => https://github.com/waitingsong/node-win32-api/issues/43. and It gives a `Cannot find module 'node: assert' Require stack`. I tried a lot but I didn't know what I was doing wrong – Nikunj Chaklasiya Nov 24 '22 at 11:10
  • @NikunjChaklasiya I've added the versions that worked for me in the answer. – Osama Nov 24 '22 at 13:35
  • This is fine with one window. Is it possible to resize multiple windows? like I open text1.txt and text2.txt and try to resize both windows. like text1.txt => 600x600 and text2.txt => 500x500. Is it possible to resize using the file name? or is any other way available? – Nikunj Chaklasiya Nov 25 '22 at 11:00
  • You can't resize by filename. You have to enumerate the top-level windows using [EnumWindows](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumwindows), then filter by class name ([GetClassName](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclassname)) or process ([GetWindowThreadProcessId](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowthreadprocessid)). Anyway, it's better to post a new question for that. Don't forget to accept the answer. – Osama Nov 25 '22 at 15:21
  • Thank you I changed your version. It's working fine. But, Can you please guide me on How it is Possible to resize the specific external window(When multiple windows open with the same Exe) using an electron? =>https://stackoverflow.com/questions/74575598/is-it-possible-to-resize-the-specific-external-windowwhen-multiple-windows-open?noredirect=1#comment131672334_74575598 I tried but was not able to set top-level windows. – Nikunj Chaklasiya Nov 30 '22 at 16:53