Created
August 24, 2015 09:08
-
-
Save Noitidart/ebe9a064b768ecfd2d97 to your computer and use it in GitHub Desktop.
_ff-addon-snippet-WinApi_removeMinMaxBtns - On Windows this removes the minimize and maximize button of the targeted window. [jsctypes] [winapi]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cu.import('resource://gre/modules/ctypes.jsm'); | |
var is64bit = ctypes.voidptr_t.size == 4 ? false : true; | |
var ifdef_UNICODE = true; | |
var TYPES = { | |
ABI: is64bit ? ctypes.default_abi : ctypes.winapi_abi, | |
CALLBACK_ABI: is64bit ? ctypes.default_abi : ctypes.stdcall_cabi, | |
BOOL: ctypes.bool, | |
CHAR: ctypes.char, | |
DWORD: ctypes.uint32_t, | |
LONG: ctypes.long, | |
LPCVOID: ctypes.voidptr_t, | |
ULONG_PTR: is64bit ? ctypes.uint64_t : ctypes.unsigned_long, | |
WCHAR: ctypes.jschar, | |
PVOID: ctypes.voidptr_t, | |
INT: ctypes.int, | |
UINT: ctypes.unsigned_int | |
}; | |
// advanced types - based on simple types | |
TYPES.LPSTR = TYPES.CHAR.ptr; | |
TYPES.LPCSTR = TYPES.CHAR.ptr; | |
TYPES.LPDWORD = TYPES.DWORD.ptr; | |
TYPES.LPCWSTR = TYPES.WCHAR.ptr; | |
TYPES.LPWSTR = TYPES.WCHAR.ptr; | |
TYPES.HANDLE = TYPES.PVOID; | |
// advanced advanced types - based on advanced types | |
TYPES.HWND = TYPES.HANDLE; | |
TYPES.HMENU = TYPES.HANDLE | |
TYPES.LPCTSTR = ifdef_UNICODE ? TYPES.LPCWSTR : TYPES.LPCSTR; | |
TYPES.LPTSTR = ifdef_UNICODE ? TYPES.LPWSTR : TYPES.LPSTR; | |
var CONST = { | |
GWL_STYLE: -16, | |
WS_MINIMIZEBOX: 131072, | |
WS_MAXIMIZEBOX: 65536 | |
}; | |
var user32 = ctypes.open('user32'); | |
var GetSystemMenu = user32.declare('GetSystemMenu', TYPES.ABI, TYPES.HMENU, TYPES.HWND, TYPES.BOOL); | |
var SetWindowPos = user32.declare('SetWindowPos', TYPES.ABI, TYPES.BOOL, TYPES.HWND, TYPES.HWND, TYPES.INT, TYPES.INT, TYPES.INT, TYPES.INT, TYPES.UINT); | |
var SetWindowLongPtr = user32.declare(is64bit ? (ifdef_UNICODE ? 'SetWindowLongPtrW' : 'SetWindowLongPtrA') : (ifdef_UNICODE ? 'SetWindowLongW' : 'SetWindowLongA'), TYPES.ABI, is64bit ? TYPES.LONG_PTR : TYPES.LONG, TYPES.HWND, TYPES.INT, is64bit ? TYPES.LONG_PTR : TYPES.LONG); | |
var GetWindowLongPtr = user32.declare(is64bit ? (ifdef_UNICODE ? 'GetWindowLongPtrW' : 'GetWindowLongPtrA') : (ifdef_UNICODE ? 'GetWindowLongW' : 'GetWindowLongA'), TYPES.ABI, is64bit ? TYPES.LONG_PTR : TYPES.LONG, TYPES.HWND, TYPES.INT); | |
// types, consts, and functions declarations complete, now lets use it | |
try { | |
var hToDOMWindow = Services.wm.getMostRecentWindow('navigator:browser'); | |
if (!hToDOMWindow) { | |
throw new Error('No browser window found'); | |
} | |
var hToBaseWindow = hToDOMWindow.QueryInterface(Ci.nsIInterfaceRequestor) | |
.getInterface(Ci.nsIWebNavigation) | |
.QueryInterface(Ci.nsIDocShellTreeItem) | |
.treeOwner | |
.QueryInterface(Ci.nsIInterfaceRequestor) | |
.getInterface(Ci.nsIBaseWindow); | |
var hToString = hToBaseWindow.nativeHandle; | |
var hTo = ctypes.voidptr_t(ctypes.UInt64(hToString)); | |
var style = GetWindowLongPtr(hTo, CONST.GWL_STYLE); | |
console.log('style:', style, style.toString()); | |
style = parseInt(style.toString()); | |
style &= ~CONST.WS_MAXIMIZEBOX; | |
style &= ~CONST.WS_MINIMIZEBOX; | |
var rez_set = SetWindowLongPtr(hTo, CONST.GWL_STYLE, style); | |
console.log('rez_set:', rez_set, rez_set.toString()); | |
} finally { | |
user32.close(); | |
console.log('user32 closed'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
README
Rev1