Skip to content

Commit

Permalink
Added declarations of WinApi functions working with window text
Browse files Browse the repository at this point in the history
  • Loading branch information
sieukrem committed Jan 2, 2018
1 parent 93b9ffb commit 4ce0291
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions deploy/[Notepad++ Directory]/plugins/jN/lib/User32.dll.js
Expand Up @@ -8,3 +8,7 @@ User32.Define("SetParent", "HWND", "HWND");
User32.Define("GetWindowLongW", "HWND", "int");
User32.Define("SetWindowLongW", "HWND", "int", "LONG_PTR");
User32.Define("SetWindowPos", "HWND", "HWND", "int","int","int","int","UINT");
User32.Define("FindWindowExW", "HWND", "HWND", "LPCTSTR", "LPCTSTR");
User32.Define("GetWindowTextW", "HWND", "LPCTSTR", "int");
User32.Define("SetWindowTextW", "HWND", "LPCTSTR");
User32.Define("GetWindowTextLengthW", "HWND");
27 changes: 27 additions & 0 deletions deploy/[Notepad++ Directory]/plugins/jN/lib/Window.js
@@ -0,0 +1,27 @@
require("User32.dll.js");

function Window(handle){
this.Handle = handle;
}

Window.prototype.GetWindowText = function(){
var bufferLength = User32.GetWindowTextLengthW(this.Handle);
var buffer = User32.NativeLibrary.alloc(bufferLength*2 + 2);
var copiedChars = User32.GetWindowTextW(this.Handle, buffer, buffer.length/2);
return buffer;
}

Window.prototype.SetWindowText = function(text){
User32.SetWindowTextW(this.Handle, text);
}

Window.FindByClass = function(parent, windowClass){
if (parent == null)
return null;

var windowHandle = User32.FindWindowExW(parent, 0, windowClass, "");
if (windowHandle == null)
return null;

return new Window(windowHandle);
}

0 comments on commit 4ce0291

Please sign in to comment.