Firefox 自动化插件开发系列(获取窗口句柄)

来源:互联网 发布:网络机柜安装图 编辑:程序博客网 时间:2024/06/16 21:23
//获取窗口句柄
    try {
        var hWnd;
        Components.utils.import("resource://gre/modules/ctypes.jsm");
        var lib = ctypes.open("user32.dll");
        var afterFx4 = ctypes.jschar ? true : false;
        var winABI = afterFx4 ? (ctypes.size_t.size == 8 ? ctypes.default_abi : ctypes.winapi_abi) : ctypes.stdcall_abi;
        var wstrType = afterFx4 ? ctypes.jschar.ptr : ctypes.ustring;
        var winClass = afterFx4 ? "MozillaWindowClass" : "MozillaUIWindowClass";
    
        var funcFindWindow = lib.declare("FindWindowW", winABI, ctypes.int32_t, wstrType, wstrType);
        hWnd = funcFindWindow(winClass, document.title);
        //alert(hWnd.toString(16));
    } catch (ex) {
        if(lib) {
            alert(ex);
        }
    } finally {
        if(lib) {
            lib.close();
        }
    }